j3k0 / cordova-plugin-purchase

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

store.refresh breaks after first purchase #123

Closed CodeHunger closed 5 years ago

CodeHunger commented 9 years ago

I've puchased an consumable with my android device. Sadly it the app crashes after the purchase.

When reloading the app and thus calling store.refresh() i get the following error log.

E/IABUtil/Security(28815): Base64 decoding failed.
E/AndroidRuntime(28815): FATAL EXCEPTION: Thread-1914
E/AndroidRuntime(28815): Process: com.CordovaApp, PID: 28815
E/AndroidRuntime(28815): java.lang.IllegalArgumentException: com.smartmobilesoftware.util.on: Bad Base64 input character at 0: 36(decimal)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.Security.generatePublicKey(Security.java:70)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.Security.verifyPurchase(Security.java:47)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.IabHelper.queryPurchases(IabHelper.java:864)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.IabHelper.queryInventory(IabHelper.java:562)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.IabHelper.queryInventory(IabHelper.java:540)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.IabHelper$2.run(IabHelper.java:635)
E/AndroidRuntime(28815):  at java.lang.Thread.run(Thread.java:841)
E/AndroidRuntime(28815): Caused by: com.smartmobilesoftware.util.Base64DecoderException: Bad Base64 input ecimal)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.Base64.decode(Base64.java:518)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.Base64.decode(Base64.java:446)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.Base64.decode(Base64.java:392)
E/AndroidRuntime(28815):  at com.smartmobilesoftware.util.Security.generatePublicKey(Security.java:60)
E/AndroidRuntime(28815):  ... 6 more
E/WindowManager(28815): android.view.WindowLeaked: Activity com.CordovaApp.CordovaApp has leaked window com.icy.impl.PhoneWindow$DecorView{4287f528 V.E..... R....... 0,0-1048,576} that was originally added here
E/WindowManager(28815):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
E/WindowManager(28815):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
E/WindowManager(28815):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
E/WindowManager(28815):   at android.app.Dialog.show(Dialog.java:286)
E/WindowManager(28815):   at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
E/WindowManager(28815):   at org.apache.cordova.CordovaChromeClient.onJsAlert(CordovaChromeClient.java:126)
E/WindowManager(28815):   at com.android.webview.chromium.WebViewContentsClientAdapter.handleJsAlert(tAdapter.java:612)
E/WindowManager(28815):   at com.android.org.chromium.android_webview.AwContentsClientBridge.handleJsAlert(ge.java:72)
E/WindowManager(28815):   at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
E/WindowManager(28815):   at com.android.org.chromium.base.SystemMessageHandler.handleMessage(.java:24)
E/WindowManager(28815):   at android.os.Handler.dispatchMessage(Handler.java:102)
E/WindowManager(28815):   at android.os.Looper.loop(Looper.java:136)
E/WindowManager(28815):   at android.app.ActivityThread.main(ActivityThread.java:5001)
E/WindowManager(28815):   at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(28815):   at java.lang.reflect.Method.invoke(Method.java:515)
E/WindowManager(28815):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/WindowManager(28815):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/WindowManager(28815):   at dalvik.system.NativeStart.main(Native Method)
E/Icing(28195): Unexpected state encountered in RFC822

Does anyone have any idea what i'm doing wrong?

macfam commented 9 years ago

@CodeHunger I believe this is a duplicate of issue #103

CodeHunger commented 9 years ago

@macfam you are right. I did see the bug report earlier but skipped it because (i thought) i've already tried it and didn't work.

updating the billing_key_param.xml did partially solved it.

i've updated

<string name="billing_key_param">$BILLING_KEY</string>

to

<string name="billing_key_param">>MIIBIjANB....</string>

Sadly after rebuilding cordova it updates to:

<resources>
    <string name="billing_key_param">MIIBIjANB...</string>
    <string name="billing_key_param">$BILLING_KEY</string>
</resources>

This sadly breaks it again. Swapping these values fixed it for me. my billing_key_param is now:

<resources>
    <string name="billing_key_param">$BILLING_KEY</string>
    <string name="billing_key_param">MIIBIjANB...</string>
</resources>

This should also solve #103 for people who cant figure it out.

macfam commented 9 years ago

@CodeHunger you are right! That fixed it for me as well. Thanks for sharing your solution.

stegua commented 9 years ago

This is not working for me neither with v3.10.1 nor v3.9.1 (with cordova 4.2.0). The issue appear when calling store.refresh() in the following code (if you need I can send the full adb logs). I did checked my private key, as suggested above, but it does not work for me.

It worked before I did a purchase for "android.test.purchased" (where I did called finish()), but, since then, it always crashes .

      if ( !window.store ) {
         myLog('Store non available');
         return;
      }

      var store = window.store;
      store.verbosity = store.DEBUG;
      store.register({
         id: 'android.test.purchased',
         alias: 'premium',
         type: store.NON_CONSUMABLE
      });

      store.error(function(error) {
         console.log('ERROR '+error.code+': '+error.message);
      });

      store.refresh();
nandeshguru commented 9 years ago

This didnt work for me either. @stegua were you able to resolve this issue?

stegua commented 9 years ago

@nandeshguru Unfortunately, I don't. I have tried with a different plugin [*], but it was even worse. If I will ever find a solution, I will surely post about it here.

[*] https://github.com/MobileChromeApps/mobile-chrome-apps/tree/master/chrome-cordova/plugins/google.payments

nandeshguru commented 9 years ago

Solution proposed by @CodeHunger worked for me after updating /platforms/android/res/values/billing_key_param.xml directly.

Earlier I tried updating /plugins/cc.fovea.cordova.purchase/src/android/billing_key_param.xml but that didnt work even after doing a clean build.

Hoping this resolves your issue too.

stegua commented 9 years ago

I did try to update directly that file, but without success. My file looks like:

% more platforms/android/res/values/billing_key_param.xml
<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="billing_key_param">$BILLING_KEY</string>
    <string name="billing_key_param">MIIB.. {MY_OWN_KEY}</string>
</resources>
svickers commented 9 years ago

This worked for me temporarily but updating to the latest ionic cli now throws this when building:

:mergeReleaseResources
/Users/scottvickers/dev/app/platforms/android/res/values/billing_key_param.xml: Error: Found item String/billing_key_param more than one time
:mergeReleaseResources FAILED
flexed commented 9 years ago

For what it's worth, I had the same problem and it seems to be fixed. I deleted <string name="billing_key_param">$BILLING_KEY</string> from my billing_key_param.xml file and it seems to work. I then went into the android.json file and deleted the relevant line for the plugin so that that line would not be readded when I run cordova prepare Same with the plugin.xml file. So far, so good.

% more platforms/android/res/values/billing_key_param.xml
<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="billing_key_param">MIIB.. {MY_OWN_KEY}</string>
</resources>
valueerrorx commented 9 years ago

unfortunately i'm not able to try this workaround because if i'm downloading this repo and then try to add the "local" plugin to intels XDK it fails to build (unable to install plugin cc.fovea.cordova.purchase)

anything i missed here? thx!

antogerva commented 9 years ago

I have the same problem after buying an "android.test.purchased" item, during a refresh. Here's the relevant logs in adb-logcat when refreshing:

http://pastebin.com/hh3SDcct And yes, I'm pretty sure that $BILLING_KEY is set properly. edit: Well, actually I just realized that I wasn't using the right key from the Google Play Services, yet it doesn't seem to work as expected. I get the same error once I restart my app(thought it seem to work if I reboot my device and I clean any data remaining on the device).

advancedsoftwarecanada commented 9 years ago

I've been able to trigger this from requesting a product 2 or 3 times in a row real quick. If the user held the button down for 0.3 seconds, it requests a purchase. Doing this 2 or 3 times in a row blows it all up.

Solution was to rate limit the request for purchase in my situation. Cheers.

stegua commented 9 years ago

Finally, the plugin is working. After a while, I tried everything from scratch. The first step was to download the plugin directly from github:

cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git ...

Second step was to follow suggestion of @CodeHunger (thanks!) and modify manually the file billing_key_param.xml to move up the line with $BILLING_KEY. Now it works like a charm!

mparpaillon commented 9 years ago

The fix worked for me too... but we shouldn't have to do it manually right ? Is it going to be fixed ?

When installing the plugin like @stegua the billing_key_params.xml in platforms/android/res/values was updated fine with my BILLING_KEY but the billing_key_params.xml in plugins/cc.fovea.cordova.purchase/src/android was not.

Which file does the plugin really use ?

tmarciszewski commented 9 years ago

I was under the impression it was fixed already. I didnt have that problem for quite some time.

mparpaillon commented 9 years ago

Yup I just did the test. It's ok. You don't need to manually change the plugins/cc.fovea.cordova.purchase/src/android/billing_key_params.xml apparently. It seems that it's the one in res/value which is used.

So to conclude, the only thing I've changed is the way I've installed the plugin. By specifying the git url instead of the plugin slug... Is that it ? Should we update the plugin or something ?

eithe commented 9 years ago

I had to follow @flexed solution for it to work. Thanks!

Jacse commented 9 years ago

The solution @flexed provided worked for me as well!

AlexDisler commented 9 years ago

Same issue and worked for me as well.

garyns commented 9 years ago

@flexed, worked for me also, thanks.

rahmadid commented 9 years ago

Hi, for those of you who experience crash after purchase related to billing key, please install the plugin from the git address. Don't install from plugin registry, it seems that the registry hasn't been updated with the latest code. It just works, I don't have to do any manual code changes. Hope that helps.

pacotole commented 9 years ago

Thanks @rahmadid !! That's work and solved me.

browndp08 commented 8 years ago

Did anyone get this to work with phonegap build? @rahmadid I'm not sure how to reference the git address according to the PHB docs at http://docs.build.phonegap.com/en_US/configuring_plugins.md.html

Any suggestions?

rahmadid commented 8 years ago

@browndp08 sorry, i don't have any experience on phonegap build.

On Sat, May 30, 2015, 08:15 browndp08 notifications@github.com wrote:

Did anyone get this to work with phonegap build? @rahmadid https://github.com/rahmadid I'm not sure how to reference the git address according to the PHB docs at http://docs.build.phonegap.com/en_US/configuring_plugins.md.html

Any suggestions?

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/123#issuecomment-106969604 .

browndp08 commented 8 years ago

All good. Thanks for the reply. For those of you using phonegap build, I was able to solve this issue by taking advantage of PGB's new npm sourcing in my config.xml file.

<gap:plugin name="cc.fovea.cordova.purchase" source="npm" version="3.11.0">
    <param name="BILLING_KEY" value="MIIB...."/>
</gap:plugin>

http://docs.build.phonegap.com/en_US/configuring_plugins.md.html

jfbloom22 commented 8 years ago

Thanks @rahmadid! I pulled from git and left the quotation marks off:

worked:

cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git  --variable BILLING_KEY=<BILLING_KEY>

did not work:

 cordova plugin add cc.fovea.cordova.purchase  --variable BILLING_KEY="<BILLING_KEY>"
RouR commented 8 years ago

@jfbloom22 how you install from git?

>cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git  --variable BILLING_KEY="ABC123"
Fetching plugin "https://github.com/j3k0/cordova-plugin-purchase.git" via git clone
Repository "https://github.com/j3k0/cordova-plugin-purchase.git" checked out to git ref "master".
shell.js: internal error
Error: EXDEV, cross-device link not permitted 'C:\Users\user1\AppData\Local\Temp\git\1433941019244\doc'
    at Error (native)
    at Object.fs.renameSync (fs.js:636:18)
    at C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\shelljs\src\mv.js:77:8
    at Array.forEach (native)
    at Object._mv (C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\shelljs\src\mv.js:53:11)
    at Object.mv (C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\shelljs\src\common.js:186:23)
    at C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\plugman\util\plugins.js:53:19
    at _fulfilled (C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:787:54)
    at self.promiseDispatch.done (C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:816:30)
    at Promise.promise.promiseDispatch (C:\Users\user1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)

I have tried:

>cordova plugin add cc.fovea.cordova.purchase  --variable BILLING_KEY=ABC123
Fetching plugin "cc.fovea.cordova.purchase" via cordova plugins registry
Installing "cc.fovea.cordova.purchase" for android

It installed 3.10.1 instead of 3.11

>npm -v
2.10.1

>cordova -v
5.1.1
jfbloom22 commented 8 years ago

Not sure what that error means. Perhaps it is related to your install of GIT or Node. Anyway you can try downloading the .zip by visiting the page in your browser: https://github.com/j3k0/cordova-plugin-purchase.git
Then install from a local directory:

cordova plugin add /path/to/directory
romilmittal commented 8 years ago

Thanks @rahmadid! Moving to git repo worked.

sarahsga commented 8 years ago

@flexed solution worked like a charm! The key was to modify android.json file in the plugins folder Here is what I did:

Step-1: If you already have it added and it doesn't work, cordova plugin remove cc.fovea.cordova.purchase

Step-2: I had been trying to make this plugin work and had failed repeatedly. Meanwhile my android.json file was getting updated too. So the first step to clean install of this plugin was to first remove any traces of previous failures from android.json Open the file plugins/android.json, and check for this code snippet:

"res/values/billing_key_param.xml": {
                "parents": {
                    "/*": [
                        .
                        .
                        .
                    ]

                }
            }

It won't necessarily be there, but if it is, remove this code snippet.

Step-3: add the plugin from github using cordova CLI cordova plugin add https://github.com/j3k0/cordova-plugin-purchase --variable BILLING_KEY="MIIB...AQAB"

and not cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="MIIB...AQAB"

Step-4: If exists, delete $BILLING_KEY from platforms/android/res/values/billing_key_param.xml file

I wrote the above steps from memory. Follow these steps in conjunction with @flexed 's answer and you should be good to go. Hope this helps :)

cloakedninjas commented 8 years ago

Just had this issue myself... Thanks @rahmadid for the solution.

But seriously, could someone please update the NPM repo!

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.