Hi sorry if this has already been asked . But i just took the iap demo in corona and got it to work in my app but some time after test purchase it has long delay before it show the alert “Thanks for supporting the app” and unlock the item bought and then redirect to different screen. So i tried to upgrade to iap v3 because it say need to do before 2015 . First i tried using http://docs.coronalabs.com/daily/guide/monetization/IAP/index.html but could not get it to work so then i tried http://coronalabs.com/blog/2013/09/03/tutorial-understanding-in-app-purchases/ and the code below and it give no error but when try on device and press the button it dose not do anything , have i put it in the wrong order , any feedback will be appreciated thanks.
1. local store = require("store") 2. if store.target == "google" then 3. store = require( "plugin.google.iap.v3" ) 4. end 5. if store.target == "amazon" then 6. store = require( "plugin.amazon.iap" ) 7. end 8. 9. local store = require( "store" ) 10. local utility = require( "utility" ) 11. 12. local mySettings 13. local restoring 14. 15. mySettings = utility.loadTable("settings.json") 16. 17. if mySettings == nil then 18. mySettings = {} 19. mySettings.isPaid = false 20. utility.saveTable(mySettings, "settings.json") 21. end 22. 23. local function transactionCallback( event ) 24. 25. print("In transactionCallback", event.transaction.state) 26. local transaction = event.transaction 27. local tstate = event.transaction.state 28. 29. if store.availableStores.google and tstate == "purchased" then 30. local timeStamp = utility.makeTimeStamp(transaction.date,"ctime") 31. if timeStamp + 360 \< os.time() then -- if the time stamp is older than 5 minutes, we will assume a restore. 32. print("map this purchase to a restore") 33. tstate = "restored" 34. print("I think tstate is ", tstate) 35. restoring = false 36. end 37. end 38. 39. if tstate == "purchased" then 40. print("Transaction succuessful!") 41. mySettings.isPaid = true 42. utility.saveTable(mySettings, "settings.json") 43. native.showAlert("Thank you!", "Your support is greatly appreciated!", {"Okay"}) 44. store.finishTransaction( transaction ) 45. elseif tstate == "restored" then 46. print("Transaction restored (from previous session)") 47. mySettings.isPaid = true 48. utility.saveTable(mySettings, "settings.json") 49. store.finishTransaction( transaction ) 50. elseif tstate == "refunded" then 51. print("User requested a refund -- locking app back") 52. mySettings.isPaid = false 53. utility.saveTable(mySettings, "settings.json") 54. store.finishTransaction( transaction ) 55. elseif tstate == "revoked" then -- Amazon feature 56. print ("The user who has a revoked purchase is", transaction.userId) 57. --Revoke this SKU here: 58. mySettings.isPaid = false 59. utility.saveTable(mySettings, "settings.json") 60. elseif tstate == "cancelled" then 61. print("User cancelled transaction") 62. store.finishTransaction( transaction ) 63. elseif tstate == "failed" then 64. print("Transaction failed, type:", transaction.errorType, transaction.errorString) 65. store.finishTransaction( transaction ) 66. else 67. print("unknown event") 68. store.finishTransaction( transaction ) 69. end 70. 71. print("done with store business for now") 72. end 73. 74. local function loadProductsListener( event ) 75. print("In loadProductsListener") 76. local products = event.products 77. for i=1, #event.products do 78. print(event.products[i].title) 79. print(event.products[i].description) 80. print(event.products[i].localizedPrice) 81. print(event.products[i].productIdentifier) 82. end 83. for i=1, #event.invalidProducts do 84. print(event.invalidProducts[i]) 85. end 86. end 87. 88. if system.getInfo("targetAppStore") == "amazon" then 89. store = require "plugin.amazon.iap" 90. store.init( transactionCallback ) 91. print("The currently logged in user is: ", store.getUserId()) 92. store.loadProducts({"com.yourcompany.yourapp"}, loadProductsListener) 93. store.restore() 94. else 95. if store.availableStores.apple and not mySettings.isPaid then 96. timer.performWithDelay(1000, function() store.init( "apple", transactionCallback); end) 97. end 98. if store.availableStores.google and not mySettings.isPaid then 99. timer.performWithDelay( 1000, 100. function() 101. store.init( "google", transactionCallback ); 102. restoring = true; 103. store.restore(); 104. end ) 105. end 106. end 107. 108. local buyBtn = display.newImageRect("winbuton.png", 100, 65) 109. localGroup:insert( buyBtn ) 110. buyBtn.x = 160 111. buyBtn.y = 200 112. buyBtn:addEventListener( "touch", removeAds )
2. If i make iap purchase when in alpha testing will it charge the credit card .