In app purchase pop up won't close

Hi guys,

I’ve been testing my IAP on android, so far so good but I have a problem with closing/cancelling the IAP popup using back button.

I noticed that I don’t get the “cancel” event in my transaction callback.

Is this a bug? Or something that’s well known?

Thanks

I am wondering about this as well, I am not getting any event responses from the trasnaction callback.

I just checked an app of mine that I’m getting ready to release.  I hit the buy button.  It popped up the purchase.  The only way I could see to cancel was to hit the device’s back button and this appeared in my console log:

I/Corona  (18903): table: 0x63542d08 { I/Corona  (18903):   [name] =\> "storeTransaction" I/Corona  (18903):   [transaction] =\> userdata: 0x634916b8 I/Corona  (18903): } I/Corona  (18903): 312 transactionCallback    cancelled     I/Corona  (18903): 318 tstate    cancelled I/Corona  (18903): 388 User cancelled transaction I/Corona  (18903): 389 productIdentifier    android.test.purchased I/Corona  (18903): 391 transactionIdentifier     I/Corona  (18903): 392 date     I/Corona  (18903): 393 originalReceipt     I/Corona  (18903): 394 originalTransactionIdentifier     I/Corona  (18903): 395 originalDate     I/Corona  (18903): done with store business for now

The numbers like 392, 393, etc are line numbers (hard coded) so I could see which print statements were firing, so I got a cancelled.  

Hrrmmm, just realized that I have not been uploading the same APK to the store as the one I have on my device.  Even so, the testing IAP ID’s such as “android.test.purchased” should always fire a “succesful” to the listener shouldn’t it?  I will try getting the correct APK in both places.

I had to upload an alpha build of my app the first time since you can’t even setup products until the right permissions are in the APK.  I’ve not uploaded a version since.  Can you post your purchase code and your init code?

Sure,

this is the majority of what is used:

--Function to handle store transactions function transactionCallback( event ) local transaction = event.transaction if transaction.state == "purchased" then print("Transaction succuessful!") --Save the volume(s) as purchased if global.isBundlePurchase == false then purchaseData:set(tostring(global.volumeToPurchase), true) volumeLocks[global.volumeToPurchase]:removeSelf() volumeLocks[global.volumeToPurchase]=nil global.volumeDownloadQueue[1] = global.volumeToPurchase else for i=1, #iapData:get("offerVolumes"), 1 do purchaseData:set(tostring(i), true) volumeLocks[i]:removeSelf() volumeLocks[i]=nil if i ~= 1 then global.volumeDownloadQueue[#global.volumeDownloadQueue + 1] = i end end --Remove the "deal pane" from the volume scroller require("scripts.logic").dealPane.isVisible = false require("scripts.logic").volumeScroller:scrollToPosition{ x = 300, y = 0, time = 100 } end purchaseData:save() ---[[if global.volumeToPurchase ~= 1 then native.showAlert("Success", "Purchase successful! Your new content will be downloaded automatically.", {"Okay"}) if fileMan.doesFileExist( "volume".. global.volumeToPurchase .."/images/story1/page1/page1.png", system.DocumentsDirectory ) == false then global.volumeToDownload = global.volumeDownloadQueue[1] local downloadEvent = { action="clicked", index = 1 } require("scripts.logic").downloadChoice( downloadEvent ) end else native.showAlert("Success", "Purchase successful, thank you!", {"You're welcome"}) end --]] local closeEvent = { phase="ended" } global.canTouch = true require("scripts.logic").closePurchasePane( closeEvent ) elseif transaction.state == "restored" then print("Transaction restored (from previous session)") print("productIdentifier", transaction.productIdentifier) print("receipt", transaction.receipt) print("transactionIdentifier", transaction.identifier) print("date", transaction.date) print("originalReceipt", transaction.originalReceipt) print("originalTransactionIdentifier", transaction.originalIdentifier) print("originalDate", transaction.originalDate) elseif transaction.state == "cancelled" then print("User cancelled transaction") native.showAlert("Alert", "Purchase was cancelled.", {"Okay"}) global.canTouch = true elseif transaction.state == "failed" then print("Transaction failed, type:", transaction.errorType, transaction.errorString) native.showAlert(transaction.errorType, transaction.errorString, {"Okay"}) native.showAlert("Alert", "Purchase failed, please try again.", {"Okay"}) global.canTouch = true else native.showAlert("Alert", "An unknown error occured, purchase failed.", {"Okay"}) print("unknown event") global.canTouch = true end -- Once we are done with a transaction, call this to tell the store -- we are done with the transaction. -- If you are providing downloadable content, wait to call this until -- after the download completes. store.finishTransaction( transaction ) end --utilize 'store.availableStores' function: if ( store.availableStores.apple ) then --currentProductList = appleProductList store.init( "apple", storeTransaction ) elseif ( store.availableStores.google ) then --currentProductList = googleProductList store.init( "google", storeTransaction ) else print( "In-app purchases are not supported on this system/device." ) end --Restore any purchases the user has made M.restorePurchases = function() store.restore() end --Purchase a volume from the store M.purchaseVolume = function( event ) local target = event.target if event.phase == "ended" and global.canTouch == true then global.canTouch = false --store.purchase( {iapData:get("volumeID"..target.id)} ) store.purchase( {"android.test.purchased"} ) end end

OOOOOOOh maaan, I am soooo dumb, I just noticed posting this that what I set up in my store.init is the wrong function name… “face palm”.

Thats what I get for copying and pasting code from 1 place and not checking function names…

My store.lua file was a bit of a frankenstein, looks like I copied code from the Corona documents for the “store.init” area and forgot to change the function name it was calling.  thanks and sorry Rob =s

I am wondering about this as well, I am not getting any event responses from the trasnaction callback.

I just checked an app of mine that I’m getting ready to release.  I hit the buy button.  It popped up the purchase.  The only way I could see to cancel was to hit the device’s back button and this appeared in my console log:

I/Corona  (18903): table: 0x63542d08 { I/Corona  (18903):   [name] =\> "storeTransaction" I/Corona  (18903):   [transaction] =\> userdata: 0x634916b8 I/Corona  (18903): } I/Corona  (18903): 312 transactionCallback    cancelled     I/Corona  (18903): 318 tstate    cancelled I/Corona  (18903): 388 User cancelled transaction I/Corona  (18903): 389 productIdentifier    android.test.purchased I/Corona  (18903): 391 transactionIdentifier     I/Corona  (18903): 392 date     I/Corona  (18903): 393 originalReceipt     I/Corona  (18903): 394 originalTransactionIdentifier     I/Corona  (18903): 395 originalDate     I/Corona  (18903): done with store business for now

The numbers like 392, 393, etc are line numbers (hard coded) so I could see which print statements were firing, so I got a cancelled.  

Hrrmmm, just realized that I have not been uploading the same APK to the store as the one I have on my device.  Even so, the testing IAP ID’s such as “android.test.purchased” should always fire a “succesful” to the listener shouldn’t it?  I will try getting the correct APK in both places.

I had to upload an alpha build of my app the first time since you can’t even setup products until the right permissions are in the APK.  I’ve not uploaded a version since.  Can you post your purchase code and your init code?

Sure,

this is the majority of what is used:

--Function to handle store transactions function transactionCallback( event ) local transaction = event.transaction if transaction.state == "purchased" then print("Transaction succuessful!") --Save the volume(s) as purchased if global.isBundlePurchase == false then purchaseData:set(tostring(global.volumeToPurchase), true) volumeLocks[global.volumeToPurchase]:removeSelf() volumeLocks[global.volumeToPurchase]=nil global.volumeDownloadQueue[1] = global.volumeToPurchase else for i=1, #iapData:get("offerVolumes"), 1 do purchaseData:set(tostring(i), true) volumeLocks[i]:removeSelf() volumeLocks[i]=nil if i ~= 1 then global.volumeDownloadQueue[#global.volumeDownloadQueue + 1] = i end end --Remove the "deal pane" from the volume scroller require("scripts.logic").dealPane.isVisible = false require("scripts.logic").volumeScroller:scrollToPosition{ x = 300, y = 0, time = 100 } end purchaseData:save() ---[[if global.volumeToPurchase ~= 1 then native.showAlert("Success", "Purchase successful! Your new content will be downloaded automatically.", {"Okay"}) if fileMan.doesFileExist( "volume".. global.volumeToPurchase .."/images/story1/page1/page1.png", system.DocumentsDirectory ) == false then global.volumeToDownload = global.volumeDownloadQueue[1] local downloadEvent = { action="clicked", index = 1 } require("scripts.logic").downloadChoice( downloadEvent ) end else native.showAlert("Success", "Purchase successful, thank you!", {"You're welcome"}) end --]] local closeEvent = { phase="ended" } global.canTouch = true require("scripts.logic").closePurchasePane( closeEvent ) elseif transaction.state == "restored" then print("Transaction restored (from previous session)") print("productIdentifier", transaction.productIdentifier) print("receipt", transaction.receipt) print("transactionIdentifier", transaction.identifier) print("date", transaction.date) print("originalReceipt", transaction.originalReceipt) print("originalTransactionIdentifier", transaction.originalIdentifier) print("originalDate", transaction.originalDate) elseif transaction.state == "cancelled" then print("User cancelled transaction") native.showAlert("Alert", "Purchase was cancelled.", {"Okay"}) global.canTouch = true elseif transaction.state == "failed" then print("Transaction failed, type:", transaction.errorType, transaction.errorString) native.showAlert(transaction.errorType, transaction.errorString, {"Okay"}) native.showAlert("Alert", "Purchase failed, please try again.", {"Okay"}) global.canTouch = true else native.showAlert("Alert", "An unknown error occured, purchase failed.", {"Okay"}) print("unknown event") global.canTouch = true end -- Once we are done with a transaction, call this to tell the store -- we are done with the transaction. -- If you are providing downloadable content, wait to call this until -- after the download completes. store.finishTransaction( transaction ) end --utilize 'store.availableStores' function: if ( store.availableStores.apple ) then --currentProductList = appleProductList store.init( "apple", storeTransaction ) elseif ( store.availableStores.google ) then --currentProductList = googleProductList store.init( "google", storeTransaction ) else print( "In-app purchases are not supported on this system/device." ) end --Restore any purchases the user has made M.restorePurchases = function() store.restore() end --Purchase a volume from the store M.purchaseVolume = function( event ) local target = event.target if event.phase == "ended" and global.canTouch == true then global.canTouch = false --store.purchase( {iapData:get("volumeID"..target.id)} ) store.purchase( {"android.test.purchased"} ) end end

OOOOOOOh maaan, I am soooo dumb, I just noticed posting this that what I set up in my store.init is the wrong function name… “face palm”.

Thats what I get for copying and pasting code from 1 place and not checking function names…

My store.lua file was a bit of a frankenstein, looks like I copied code from the Corona documents for the “store.init” area and forgot to change the function name it was calling.  thanks and sorry Rob =s