cordova-plugin-purchase
cordova-plugin-purchase copied to clipboard
Android register product is failed, store.product gives blank array[], But Work fine in Ios
Work Fine with ios Platform if (this.platform.is('ios')) { this.platform.ready().then(() => { this.store.verbosity = CdvPurchase.LogLevel.DEBUG;
CdvPurchase.store.register(
[{
type: CdvPurchase.ProductType.CONSUMABLE,
id: "productId1",
platform: CdvPurchase.Platform.APPLE_APPSTORE,
},
{
type: CdvPurchase.ProductType.CONSUMABLE,
id: "productId2",
platform: CdvPurchase.Platform.APPLE_APPSTORE,
}]
);
this.store.initialize().then((err) => {
const product = this.store.get("productId1"); // product
console.log(product);
this.setListeners()
});
})
})
}
NOT WORK IN ANDROID else if (this.platform.is('android')) { this.platform.ready().then(() => {
this.store.verbosity = CdvPurchase.LogLevel.DEBUG;
CdvPurchase.store.register(
[
{
type: CdvPurchase.ProductType.CONSUMABLE,
id: "productId1,
platform: CdvPurchase.Platform.GOOGLE_PLAY,
},
{
type: CdvPurchase.ProductType.CONSUMABLE,
id: "productId2",
platform: CdvPurchase.Platform.GOOGLE_PLAY,
}]
);
this.store.initialize().then((err) => {
const product = this.store.get("productId"); // product
console.log(product);
this.setListeners()
});
})
})
}
setListeners() {
CdvPurchase.store.when().approved((p: any) => {
console.log('PURCHASE SUCCESS');
p.finish();
});
// CdvPurchase.store.when().updated((p: any) => {
// console.log('updated SUCCESS');
// // var myproduct= CdvPurchase.store.get(p);
// // console.log(myproduct);
// });
CdvPurchase.store.when().verified((receipt: any) => {
receipt.finish()
});
CdvPurchase.store.when().productUpdated(() => {
console.log('PURCHASE ERROR');
});
CdvPurchase.store.when().finished((p:any) => {
p.finish();
console.log('FINISH');
});
CdvPurchase.store.when().receiptUpdated((receipt: any) => {
if (CdvPurchase.store.owned(receipt)) {
console.log("my-product is owned");
}
});
CdvPurchase.store.error((err: any) => {
console.error('Store Error ' + JSON.stringify(err));
});
CdvPurchase.store.ready(() => {
console.log('Store is ready');
console.log('Products: ' + JSON.stringify(CdvPurchase.store.products));
});
}
DEBUG OUTPUT
[CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"ready","data":{}} subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: Ready subscription-plans:6567 [CdvPurchase.Adapters] INFO: GooglePlay initialized. subscription-plans:6567 [CdvPurchase.Adapters] INFO: GooglePlay products: [{"type":"consumable","id":"productId1","platform":"android-playstore"},{"type":"consumable","id":"productId2","platform":"android-playstore"}] subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: Load: [{"type":"consumable","id":"productId1","platform":"android-playstore"},{"type":"consumable","id":"productId2","platform":"android-playstore"}] subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: getAvailableProducts: ["productId1","cproductId2"] | [] subscription-plans:6567 [CdvPurchase.GooglePlay.Bridge] INFO: getAvailableProducts() subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: Loaded: [] subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: getPurchases subscription-plans:6567 [CdvPurchase.GooglePlay.Bridge] INFO: getPurchases() subscription-plans:6567 [CdvPurchase.GooglePlay.Bridge] INFO: listener: {"type":"setPurchases","data":{"purchases":[]}} subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: onSetPurchases: [] subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: onPurchaseUpdated: subscription-plans:6567 [CdvPurchase.AdapterListener] DEBUG: receiptsReady: android-playstore (1/0) subscription-plans:6567 [CdvPurchase.GooglePlay] DEBUG: getPurchases success subscription-plans:6567 [CdvPurchase.Adapters] INFO: GooglePlay products loaded: [{"isError":true,"code":6777012,"message":"Product with id productId1 not found.","platform":"android-playstore","productId":"productId1"},{"isError":true,"code":6777012,"message":"Product with id.productId2 not found.","platform":"android-playstore","productId":"productId2"}] subscription-plans:6567 [CdvPurchase.Adapters] INFO: GooglePlay receipts loaded: [] subscription-plans:6567 [CdvPurchase.AdapterListener] DEBUG: setSupportedPlatforms: android-playstore (1 have their receipts ready) subscription-plans:6567 [CdvPurchase.AdapterListener] DEBUG: triggering receiptsReady() subscription-plans:6567 [CdvPurchase] DEBUG: Calling callback: type=ready() name=#b59ce24a9a0dfb9fdcdcaa0604eeaff8 subscription-plans.component.ts:202 Store is ready subscription-plans.component.ts:204 undefined subscription-plans.component.ts:205 Products: [] subscription-plans:6567 [CdvPurchase] DEBUG: Calling callback: type=receiptsReady() name=#15659ee54654cd3de0a0225d90426d46 subscription-plans:6567 [CdvPurchase.ReceiptsMonitor] DEBUG: receiptsReady... subscription-plans:6567 [CdvPurchase.ReceiptsMonitor] DEBUG: check(0/0) subscription-plans:6567 [CdvPurchase.ReceiptsMonitor] INFO: receiptsVerified()
nothing fatched in product
Thank you in advance
I have the exactly opposite situation, but for your case my workable code shows that maybe you're missing CdvPurchase.Platform.GOOGLE_PLAY
inside store.initialize
.
Also, make sure to keep your productId as myID
instead of com.mybrand.myproject.myID
I also don't see getOffer()
in your case, here's my commit which fixed IAP's btw: https://github.com/Doyban/FlyingPlane/commit/b42786fc3895b77a6f4023a835b3d335554124d4
I have the exactly opposite situation, but for your case my workable code shows that maybe you're missing
CdvPurchase.Platform.GOOGLE_PLAY
insidestore.initialize
.
Fixed in https://github.com/Doyban/FlyingPlane/commit/751f22aaad2b5aaa9f32bf54a3cca5242b589bde