MobileChromeApps / mobile-chrome-apps

Chrome apps on Android and iOS
BSD 3-Clause "New" or "Revised" License
2.5k stars 347 forks source link

Problems installing the payments plugin #137

Closed muszek closed 10 years ago

muszek commented 10 years ago

hi,

I'm trying to install google.payments plugin ( https://github.com/MobileChromeApps/mobile-chrome-apps/tree/master/chrome-cordova/plugins/google.payments ) in my Cordova app (it's not a chrome app). The readme.md says:


For Cordova apps, install with the cordova command-line tool:

cordova plugin add com.google.payments

This is what I get:

muszek@dziobak:~/pgpc2$ cordova plugin add com.google.payments
Fetching plugin "com.google.payments" via plugin registry
Error: Failed to fetch package information for com.google.payments
    at /usr/lib/node_modules/cordova/node_modules/plugman/src/registry/registry.js:32:20
    at Request.cb [as _callback] (/usr/lib/node_modules/cordova/node_modules/plugman/src/registry/registry.js:251:9)
    at Request.self.callback (/usr/lib/node_modules/cordova/node_modules/plugman/node_modules/request/index.js:148:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/usr/lib/node_modules/cordova/node_modules/plugman/node_modules/request/index.js:886:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/usr/lib/node_modules/cordova/node_modules/plugman/node_modules/request/index.js:837:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)
muszek@dziobak:~/pgpc2$ cordova --version
3.4.0-0.1.3
mmocny commented 10 years ago

Witam!

This is a fetch error, seemingly because we haven't actually published this plugin to plugins.cordova.io.

Perhaps it was published at some point in the past and was taken down (hence the documentation bug).

@mwoghiren is doing a cca project release today. Max, perhaps he can also tackle a plugins publish to the plugin registry?

mwoghiren commented 10 years ago

Indeed, this plugin is not in the registry. I will talk with Ian about publishing it tomorrow.

Thanks for the issue, Mateusz!

muszek commented 10 years ago

@mwoghiren: this plugin depends on cc.fovea.plugins.inapppurchase and it also appears to be missing from the registry. I added git://github.com/j3k0/PhoneGap-InAppPurchase-iOS.git manually before installing your plugin and it did the trick, but you might want to take a look into it as well.

muszek commented 10 years ago

I'm starting to wonder - is this plugin meant to be used in a plain Cordova (not mobile chrome apps) project? If so, can someone please post a paragraph or two on how to install it? Installing cc.fovea.plugins.inapppurchase and the google.payments plugin itself is not enough. I get a js error about a missing "events" module. I find and include chrome-common/events.js, but it needs some js code that defines a 'module' global variable... I clearly need to have some base js included first.

mmocny commented 10 years ago

You cannot just include events.js as a normal script, since its part of a plugin and is meant to be included as a cordova <js-module> (which would define the missing module you've encountered).

I would install the plugin chrome-common to fix this particular issue.

As for your question about payments will work outside of cca overall.. well payments is a work in progress even within cca, buts not a plugin that depends on the app lifecycle and so should work outside. Max has mentioned earlier that he will discuss and experiment together with Ian, but he was working on a cca release today.

Hopefully after just installing chrome-common plugin you will be able to tell us how it went!

muszek commented 10 years ago

Michał: thank you, it worked. Now I have to figure out why the in-app payment testing doesn't work as expected and my wife's account gets charged :-)

In case someone else faces the same problems, here's a step-by-step instruction:

A. Install the cc.fovea.plugins.inapppurchase plugin (currently it's not in Cordova's registry, and google.payments` plugin.xml references it as if it was in fact registered).

cordova plugin add git://github.com/j3k0/PhoneGap-InAppPurchase-iOS.git

B. Install google.payments plugin. Currently it's not registered and it resides in a subdirectory of a https://github.com/MobileChromeApps/mobile-chrome-apps repo. I didn't know any better solution than to simply clone the whole repo, copy this plugin's directory elsewhere and make it a separate repo. I pushed it to https://github.com/muszek/google.payments . It's 100% the same code as the original, but please do yourself a favor and make sure that's the case. It's payments after all and you shouldn't rely on some random guy's word. Hopefully it will be registered soon and you won't have to do it. This is how you install it:

cordova plugin add https://github.com/muszek/google.payments.git

C. Install org.chromium.common plugin

cordova plugin add org.chromium.common
mmocny commented 10 years ago

Charging your wife's account is a feature not a bug :)

One note about (b) is that we support adding plugins by path, and also support a --searchpath argument to cordova plugin add. You shouldn't need to create a new repo, just clone ours and add the plugin from the subdirectory.

And (c) I would add the "common" plugin that matches up with the payments plugin version. SO: if you add payents directly from git repo, you should add common from there as well.

Let us know if you figure out the wrong-account-being-charged issue, since that sounds important to get right :) I hope its just a configuration issue on your end.

muszek commented 10 years ago

A. It looks like the searchpath feature hasn't been released yet. I see it in the "man page" (cordova help) in their github repo, but it's not when I run 'cordova help' locally. I'm running the latest version from npm:

muszek@dziobak:~/pgpc2$ cordova --version
3.4.0-0.1.3
muszek@dziobak:~/pgpc2$ plugman --version
0.20.2

B. There's no issue with a wrong account being charged (I had to use her account because for some reason Google Play doesn't allow to make a purchase with app's owner account). There's an issue with the actual charges being made, because I've made everything I was asked to in order to set up a test account and the account shouldn't have been charged at all. But it probably doesn't have anything to do with your code, so I'm not bugging you with it... I just mentioned it.

C. Here's something I'd like to bug you with: I played around with the code (Android for now, haven't tested this plugin on iOS at all yet) for a while and I can't get anything but the .buy() method to work.

.getPurchases() fails with an "Invalid action" message:

google.payments.inapp.getPurchases(
    function(resp) {
        console.log('it worked!');
        console.log(resp);
    },
    function(resp) {
        console.log('it failed!');
        console.log(resp);
    }
);
it failed!
Invalid action

.getSKU():

google.payments.inapp.getSkuDetails(
    ['ad_removal_2', 'testowy.za.dwa'],
    function(resp) {
        console.log('it worked!');
        console.log(resp);
    },
    function(resp) {
        console.log('it failed!');
        console.log(resp);
    }
);
undefined
it failed!
Error retrieving SKU details

Is there a reference implementation of this plugin? Or perhaps someone would like to test-drive it on my app? I don't know if it's buggy (you've said it's experimental) or there's a problem with my code or the way things are set up in Google Play.

mmocny commented 10 years ago

@mwoghiren Max, any chance you could take a look?

mwoghiren commented 10 years ago

@clelland C concerns Android. Are those functions intended to be operational?

A heads-up: on iOS, getPurchases is not supported. In iOS 6, receipts were introduced, which makes this implementable, but it hasn't been done yet.

muszek commented 10 years ago

I have installed AndroidInAppBilling plugin from https://github.com/poiuytrez/AndroidInAppBilling/tree/master/v3 and it seems to work fine. I ran a few methods (copy & paste from Google Chrome's console, the formatting could've suffered). The point is "the other plugin works, so there probably are issues in your plugin".

inappbilling.init(
    function(resp) {
        console.log('init successful');
        console.log(resp)
    },
    function(resp) {
        console.log('init failed');
        console.log(resp)
    }
)
InAppBilling[js]: setup ok inappbilling.js:6
undefined
init successful
OK
inappbilling.getPurchases(
    function(resp) {
        console.log('getPurchases() successful');
        console.log(resp)
    },
    function(resp) {
        console.log('getPurchases() failed');
        console.log(resp)
    }
)
InAppBilling[js]: getPurchases called! inappbilling.js:6
getPurchases() successful
[Object, Object]
0: Object
1: Object
length: 2
__proto__: Array[0]
undefined
inappbilling.getProductDetails(
    function(resp) {
        console.log('getProductDetails() successful');
        console.log(resp)
    },
    function(resp) {
        console.log('getProductDetails() failed');
        console.log(resp)
    },
    ['ad_removal_2','testowy_produkt_za_grosik','testowy.za.dwa','testowy_produkt_3']
)
InAppBilling[js]: getProductDetails called! inappbilling.js:6
InAppBilling[js]: load ["ad_removal_2","testowy_produkt_za_grosik","testowy.za.dwa","testowy_produkt_3"] inappbilling.js:6
undefined
getProductDetails() successful
[Object, Object, Object, Object]
0: Object
description: "Ads will be removed from the application."
price: "5,99 zł"
price_amount_micros: 5990000
price_currency_code: "PLN"
productId: "ad_removal_2"
title: "Ad removal (Percentage Calculator)"
type: "inapp"
__proto__: Object
1: Object
description: "asdf"
price: "2,99 zł"
price_amount_micros: 2990000
price_currency_code: "PLN"
productId: "testowy_produkt_za_grosik"
title: "Testowy Produkt Za Grosik (Percentage Calculator)"
type: "inapp"
__proto__: Object
2: Object
description: "opis..."
price: "2,99 zł"
price_amount_micros: 2990000
price_currency_code: "PLN"
productId: "testowy.za.dwa"
title: "testowy za 2 (Percentage Calculator)"
type: "inapp"
__proto__: Object
3: Object
description: "opis trzeciego testowego"
price: "4,50 zł"
price_amount_micros: 4500000
price_currency_code: "PLN"
productId: "testowy_produkt_3"
title: "testowy 3 (Percentage Calculator)"
type: "inapp"
__proto__: Object
length: 4
__proto__: Array[0]
inappbilling.getAvailableProducts(
    function(resp) {
        console.log('getAvailableProducts() successful');
        console.log(resp)
    },
    function(resp) {
        console.log('getAvailableProducts() failed');
        console.log(resp)
    }
)
InAppBilling[js]: getAvailableProducts called! inappbilling.js:6
getAvailableProducts() successful
[Object, Object, Object, Object]
0: Object
description: "Ads will be removed from the application."
price: "5,99 zł"
price_amount_micros: 5990000
price_currency_code: "PLN"
productId: "ad_removal_2"
title: "Ad removal (Percentage Calculator)"
type: "inapp"
__proto__: Object
1: Object
description: "asdf"
price: "2,99 zł"
price_amount_micros: 2990000
price_currency_code: "PLN"
productId: "testowy_produkt_za_grosik"
title: "Testowy Produkt Za Grosik (Percentage Calculator)"
type: "inapp"
__proto__: Object
2: Object
description: "opis..."
price: "2,99 zł"
price_amount_micros: 2990000
price_currency_code: "PLN"
productId: "testowy.za.dwa"
title: "testowy za 2 (Percentage Calculator)"
type: "inapp"
__proto__: Object
3: Object
description: "opis trzeciego testowego"
price: "4,50 zł"
price_amount_micros: 4500000
price_currency_code: "PLN"
productId: "testowy_produkt_3"
title: "testowy 3 (Percentage Calculator)"
type: "inapp"
__proto__: Object
length: 4
__proto__: Array[0]
undefined
muszek commented 10 years ago

Just made a test purchase with the other plugin and it was in fact a test purchase (my wife's account was not charged). Perhaps the case with your plugin was that I waited too little time between setting everything up in Google Play Developer Console and making the purchase. Or perhaps there's an issue with the plugin.

If you'd like, I can surrender another dollar and test it again with your plugin :-)

mikehayesuk commented 10 years ago

Has this plugin disappeared from the registry again (I can't work out how to check)?

I am having the same installation issue today.

cordova plugin add com.google.payments

Fetching plugin "com.google.payments" via plugin registry
Error: Failed to fetch package information for com.google.payments
    at /usr/local/Cellar/node/0.10.5/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/registry/registry.js:32:20
    at Request.cb [as _callback] 
[...]

Is it recommended to use this plugin outside of CCA apps (I'm vanilla Cordova here, considering switching to using the Chrome setup/framework if necessary)?

mikehayesuk commented 10 years ago

Even cloning this repo and installing locally, there are other plugins still missing from the registry (same issue as @muszek had previously).

cordova plugin add ~/mca/chrome-cordova/plugins/google.payments/
Installing "com.google.payments" for android
Fetching plugin "cc.fovea.plugins.inapppurchase" via plugin registry
Failed to install 'com.google.payments':Error: Failed to fetch package information for cc.fovea.plugins.inapppurchase

I'm going to give poiuytrez/AndroidInAppBilling a go instead for now.

Thanks

clelland commented 10 years ago

Hey @BlueHayes, I don't think that com.google.payments has ever been published to the Cordova plugin registry. I haven't tested it outside of CCA, and we don't have any instructions on using it without a manifest, so it's never been made generally available.

There's probably no reason not to do that; I just need to do some basic work to make sure that it is functional. I've added an issue (#207) to make sure I don't forget that.

mikehayesuk commented 10 years ago

Thanks.

The documentation at https://github.com/MobileChromeApps/mobile-chrome-apps/blob/master/chrome-cordova/plugins/google.payments/README.md seems to suggest that it's in the plugin registry.

For Cordova apps, install with the cordova command-line tool:

cordova plugin add com.google.payments

clelland commented 10 years ago

That makes me sad :( Thanks for finding it, though.

Right now, you can install it with the cca tools: cca plugin add com.google.payments, because cca sets your searchpath. You could also manually use

cordova plugin add com.google.payments \
    --searchpath=<path-to-cca/chrome-cordova/plugins> \
    --searchpath=<path-to-cca/cordova>

and that would find it (and its dependencies)

clelland commented 10 years ago

The com.google.payments plugin is now published to the Cordova plugin registry! The dependent plugin is published there as well, so it should install seamlessly