问题
So far I'm able to receive my product information for an iOS device but not Android.
Here is my code in the component module:
registerProduct() {
this.inAppPurchase.verbosity = this.inAppPurchase.DEBUG;
this.inAppPurchase.register({
id: 'android.prod',
type: this.inAppPurchase.NON_CONSUMABLE
});
this.registerHandlersForPurchase('android.prod');
this.inAppPurchase.refresh();
}
registerHandlersForPurchase(productId) {
const self = this.inAppPurchase;
this.inAppPurchase.when(productId).updated((product) => {
if (product.loaded && product.valid && product.state === self.APPROVED && product.transaction != null) {
product.finish();
}
});
this.inAppPurchase.when(productId).registered((product: IAPProduct) => {
// alert(` owned ${product.owned}`);
});
this.inAppPurchase.when(productId).owned((product: IAPProduct) => {
// alert(` owned ${product.owned}`);
product.finish();
});
this.inAppPurchase.when(productId).approved((product: IAPProduct) => {
// alert('approved');
product.finish();
});
this.inAppPurchase.when(productId).refunded((product: IAPProduct) => {
// alert('refunded');
});
this.inAppPurchase.when(productId).expired((product: IAPProduct) => {
// alert('expired');
});
}
This is the console log
[store.js] DEBUG: state: android.prod -> registered
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: store.trigger -> triggering action refreshed
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2781 InAppBilling[js]: setup ok
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2781 InAppBilling[js]: load ["android.prod"]
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2781 InAppBilling[js]: listener: {"type":"ready","data":{}}
/pages-profile-profile-module-es2015.js:178 this.currentUser Ice Berg
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: plugin -> ready
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2781 InAppBilling[js]: getAvailableProducts()
unpkg.com/ionicons@4.5.10-0/dist/ionicons/svg/ios-chevron-forward.svg:1 Failed to load resource: the server responded with a status of 404 ()
/pages-profile-profile-module-es2015.js:210 ionViewDidEnter
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: plugin -> loaded - []
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: state: android.prod -> invalid
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: iabGetPurchases()
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2781 InAppBilling[js]: getPurchases()
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2781 InAppBilling[js]: listener: {"type":"setPurchases","data":{"purchases":[]}}
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: iabSetPurchases: []
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: inappbilling.getPurchases() -> Success
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: -> object
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: -> []
/plugins/cc.fovea.cordova.purchase/www/store-android.js:2012 [store.js] DEBUG: iabUpdatePurchases: []
The difference in iOS is that this is valid: [store.js] DEBUG: state: android.prod -> valid
and when I naviage to the page here is the code:
setupProducts() {
this.androidProduct = this.inAppPurchase.get('android.prod');
console.log('product reg', JSON.stringify(this.androidProduct));
}
product reg {"id":"android.prod","alias":"android.prod","type":"non consumable","group":"","state":"invalid","title":null,"description":null,"priceMicros":null,"price":null,"currency":null,"countryCode":null,"loaded":true,"canPurchase":false,"owned":false,"introPrice":null,"introPriceMicros":null,"introPricePeriod":null,"introPriceNumberOfPeriods":null,"introPricePeriodUnit":null,"introPriceSubscriptionPeriod":null,"introPricePaymentMode":null,"ineligibleForIntroPrice":null,"discounts":[],"downloading":false,"downloaded":false,"additionalData":null,"transaction":null,"valid":false}
One thing I've read in the searching for solutions is a BILLING_KEY...but there's no billing_key in the Google Play Console. I've added my product to Google Play and I've uploaded my .apk into the Closed Testing Beta Track.
My InApp product shows Active in Google Play Console.
ionic -v 6.0.1
cordova -v 9.0.0 (cordova-lib@9.0.1)
"cc.fovea.cordova.purchase": "^10.1.1",
So I'm not sure how to register the Android product so that it's active instead of inactive and retrieve the product information.
Any help would be greatly appreciated.
回答1:
You can find the Android Billing Key in Google Play Console (new), under Monetization Setup > Licensing, starting with "MIIBxxxxxxxxxxxxxx".
You also need to run the command ionic cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="MIIBxxxxxxxxxx (your own billing key)" in terminal.
来源:https://stackoverflow.com/questions/65430263/unable-to-display-in-app-purchase-product-data-in-android