j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 537 forks source link

Successful in-app purchase crashes the app #131

Closed paprikka closed 6 years ago

paprikka commented 9 years ago

After a successful purchase the app crashes (stack trace attached). We're using Cordova 3.6.3 with a Crosswalk template (crosswalk-cordova-10.39.235.15-arm).

It's a single item (non consumable) purchase. I'm using a separate test account, with real products (as opposed to static ones).

D/IabHelper(26210): Expected item type: inapp
D/IabHelper(26210): Purchase signature successfully verified.
D/CordovaPurchase(26210): Purchase finished: IabResult: Success (response: 0:Error), purchase: PurchaseInfo(type:inapp):{"orderId":"12999763169054705758.1366267159098794","packageName":"com.XXXXXX.XXXXXX","productId":"com.getcontentment._test.single3","purchaseTime":1422199082804,"purchaseState":0,"purchaseToken":"nlajeodjdkhbpcogkepedcjb.AO-J1OyO386NU3bBiABs_1EhZOEfbtslUuf9Fjlpz5V_K5-8pI9RDeOUcaAyqoAmh_seqoFzek4ZMrKIpGfO-6R6-2hTOPOALdh9UFACdfen1g-RTuz8S2v4prVt9IKRzRwrlA7NPWc5dc4-jAaDJv2ROg_FN5O4vA"}
D/CordovaPurchase(26210): Purchase successful.
D/AndroidRuntime(26210): Shutting down VM
E/AndroidRuntime(26210): FATAL EXCEPTION: main
E/AndroidRuntime(26210): Process: com.XXXXXX.XXXXXX, PID: 26210
E/AndroidRuntime(26210): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10001, result=-1, data=Intent { (has extras) }} to activity {com.XXXXXX.XXXXXX/com.XXXXXX.XXXXXX.ApplicationName}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.smartmobilesoftware.util.Inventory.addPurchase(com.smartmobilesoftware.util.Purchase)' on a null object reference
E/AndroidRuntime(26210):  at android.app.ActivityThread.deliverResults(ActivityThread.java:3351)
E/AndroidRuntime(26210):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:3394)
E/AndroidRuntime(26210):  at android.app.ActivityThread.access$1300(ActivityThread.java:135)
E/AndroidRuntime(26210):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
E/AndroidRuntime(26210):  at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(26210):  at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(26210):  at android.app.ActivityThread.main(ActivityThread.java:5001)
E/AndroidRuntime(26210):  at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26210):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime(26210):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime(26210): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.smartmobilesoftware.util.Inventory.addPurchase(com.smartmobilesoftware.util.Purchase)' on a null object reference
E/AndroidRuntime(26210):  at com.smartmobilesoftware.inappbilling.InAppBillingPlugin$4.onIabPurchaseFinished(InAppBillingPlugin.java:375)
E/AndroidRuntime(26210):  at com.smartmobilesoftware.util.IabHelper.handleActivityResult(IabHelper.java:514)
E/AndroidRuntime(26210):  at com.smartmobilesoftware.inappbilling.InAppBillingPlugin.onActivityResult(InAppBillingPlugin.java:421)
E/AndroidRuntime(26210):  at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:822)
E/AndroidRuntime(26210):  at android.app.Activity.dispatchActivityResult(Activity.java:5423)
E/AndroidRuntime(26210):  at android.app.ActivityThread.deliverResults(ActivityThread.java:3347)
E/AndroidRuntime(26210):  ... 9 more
westoj commented 9 years ago

Seem to be running into the same issue, did you solve this?

trancee commented 9 years ago

I happen to have the same symptoms. When I try to start the app again, it crashes every time and I am unable to open my app.

02-17 12:27:05.040: D/CordovaPurchase(5484): Num SKUs Found: 1
02-17 12:27:05.040: D/CordovaPurchase(5484): Product SKU Added: andygreen.pro
02-17 12:27:05.040: D/CordovaPurchase(5484): init start
02-17 12:27:05.040: D/CordovaPurchase(5484): Creating IAB helper.
02-17 12:27:05.040: D/CordovaPurchase(5484): Starting setup.
02-17 12:27:05.040: D/IabHelper(5484): Starting in-app billing setup.
02-17 12:27:05.040: D/CordovaLog(5484): file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js: Line 726 : InAppBilling[js]: setup ok
02-17 12:27:05.040: I/chromium(5484): [INFO:CONSOLE(726)] "InAppBilling[js]: setup ok", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (726)
02-17 12:27:05.040: D/CordovaLog(5484): file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js: Line 726 : InAppBilling[js]: load ["andygreen.pro"]
02-17 12:27:05.040: I/chromium(5484): [INFO:CONSOLE(726)] "InAppBilling[js]: load ["andygreen.pro"]", source: file:///android_asset/www/plugins/cc.fovea.cordova.purchase/www/store-android.js (726)
02-17 12:27:05.040: D/IabHelper(5484): Billing service connected.
02-17 12:27:05.050: D/IabHelper(5484): Checking for in-app billing 3 support.
02-17 12:27:05.050: D/IabHelper(5484): In-app billing version 3 supported for com.andygreen.AndyGreen
02-17 12:27:05.050: D/IabHelper(5484): Subscriptions AVAILABLE.
02-17 12:27:05.050: D/CordovaPurchase(5484): Setup finished.
02-17 12:27:05.050: D/CordovaPurchase(5484): Setup successful. Querying inventory w/ SKUs.
02-17 12:27:05.050: D/IabHelper(5484): Starting async operation: refresh inventory
02-17 12:27:05.050: D/IabHelper(5484): Querying owned items, item type: inapp
02-17 12:27:05.050: D/IabHelper(5484): Package name: com.andygreen.AndyGreen
02-17 12:27:05.050: D/IabHelper(5484): Calling getPurchases with continuation token: null
02-17 12:27:05.060: D/IabHelper(5484): Owned items response: 0
02-17 12:27:05.060: E/IABUtil/Security(5484): Base64 decoding failed.
02-17 12:27:05.060: W/dalvikvm(5484): threadid=29: thread exiting with uncaught exception (group=0x41590db8)

And then the crash itself:

02-17 12:27:05.070: E/AndroidRuntime(5484): FATAL EXCEPTION: Thread-24152
02-17 12:27:05.070: E/AndroidRuntime(5484): Process: com.andygreen.AndyGreen, PID: 5484
02-17 12:27:05.070: E/AndroidRuntime(5484): java.lang.IllegalArgumentException: com.smartmobilesoftware.util.Base64DecoderException: Bad Base64 input character at 0: 36(decimal)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.Security.generatePublicKey(Security.java:70)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.Security.verifyPurchase(Security.java:47)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.IabHelper.queryPurchases(IabHelper.java:864)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.IabHelper.queryInventory(IabHelper.java:562)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.IabHelper.queryInventory(IabHelper.java:540)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.IabHelper$2.run(IabHelper.java:635)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at java.lang.Thread.run(Thread.java:841)
02-17 12:27:05.070: E/AndroidRuntime(5484): Caused by: com.smartmobilesoftware.util.Base64DecoderException: Bad Base64 input character at 0: 36(decimal)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.Base64.decode(Base64.java:518)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.Base64.decode(Base64.java:446)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.Base64.decode(Base64.java:392)
02-17 12:27:05.070: E/AndroidRuntime(5484):     at com.smartmobilesoftware.util.Security.generatePublicKey(Security.java:60)
02-17 12:27:05.070: E/AndroidRuntime(5484):     ... 6 more
westoj commented 9 years ago

try some of the fixes in #103 it depends how you're compiling I think, i.e, eclipse, cordova cli, android studio. There seems to be a combination of fixes that works for each environment.

valueerrorx commented 9 years ago

i too encounter the same error.. "Bad Base64 input character at 0: 36 ... " so it seems to be the same $BILLING_KEY problem :( [please fix this]

how can i try those workarounds suggested in this and all the other threads - i'm developing with intel XDK and i can't figure out how to add the downloaded repo as local plugin - do i have to compile it first or something like that? adding the plugin as it is throws an error when i try to build my game.

the only way for me to add the plugin is using the version from the "apache cordova plugin registry" but how would i apply one of those fixes then ?

thx in advance..

valueerrorx commented 9 years ago

oke.. to add the custom (edited plugin) where i hardcoded my billing key i must not use the UI of intel XDK to add it (this will fail) i have to do it manually by creating a file named: intelxdk.config.additions.xml (it will automatically be included) and write the following code into it:

<intelxdk:plugin intelxdk:name="cc.fovea.cordova.purchase" intelxdk:value="cc.fovea.cordova.purchase" intelxdk:type="local">
    <intelxdk:param intelxdk:name="BILLING_KEY" intelxdk:value="MIIBI.......DAQAB" />
</intelxdk:plugin>

now inapp purchases work

Windshifter commented 9 years ago

Have the issue of the app crashed after the a successful buy of a item. I have changed the billing_key are mentioned by valueerrorx.

Has anyone manage to solve this problem ? or is there any plugin that can works ?

Jacse commented 9 years ago

I'm experiencing the same problem. Did anyone figure out a fix?

Windshifter commented 9 years ago

Hi Jacse, I fixed mine by editing the 'intelxdk:value=' to the package name or git repository representing the plugin intelxdk:value="https://github.com/j3k0/cordova-plugin-purchase"

Example: <intelxdk:plugin intelxdk:name="cc.fovea.cordova.purchase" intelxdk:value="https://github.com/j3k0/cordova-plugin-purchase"

/intelxdk:plugin

Hope this helps.

quintonn commented 9 years ago

I found that you have to edit the billing_key_param.xml file inside the plugin folder with your billing key. I am using Visual Studio tools for apache cordova and this fixed a similar issue i had

Jacse commented 9 years ago

I fixed mine by using the quick solution provided by @flexed in #123

sarahsga commented 9 years ago

123 fixed it for me too. @flexed 's answer worked for me perfectly! I have answered it too in hope that it might help.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.