Skip to content

Commit

Permalink
Fix: In-App Purchases (IAP's) for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldanielecki committed Aug 23, 2023
1 parent 50f9260 commit b42786f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/scripts/scenes/shop/ShopItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,12 @@ export class ShopItem extends Phaser.GameObjects.Container {
volume: 1
});

// Purchase In-App Purchase (IAP) item.
const that = this;
const store = CdvPurchase.store;
const { ProductType, Platform } = CdvPurchase;
const { Platform } = CdvPurchase;

// Prepare product.
store.register({
id: `com.doyban.tappyplane.scorex${this.multiplier}`,
type: ProductType.CONSUMABLE,
platform: Platform.GOOGLE_PLAY,
});
store.update();

store.when(`com.doyban.tappyplane.scorex${this.multiplier}`)
store.when()
.approved(() => {
// Add extra score and begin the game.
localStorage.scoreRate = parseInt(that.multiplier);
Expand All @@ -150,8 +143,9 @@ export class ShopItem extends Phaser.GameObjects.Container {

store.initialize([
Platform.GOOGLE_PLAY,
]).then(() => {
console.log('products2', store.products);
});;
]);

const offer: any = store.get(`scorex${this.multiplier}`).getOffer();
store.order(offer);
}
}
12 changes: 12 additions & 0 deletions src/scripts/scenes/shop/ShopItemGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export class ShopItemGroup {
this.startYpos = startY - (offsetY * (rowCount - 1) * 0.5); // Set center position using the total rows and offset.
this.multiplierArray = [2, 4, 6, 8]; // Array to change multiplier count for shop items.

// Prepare products for In App Purchases (IAP's).
const store = CdvPurchase.store;
const { ProductType, Platform } = CdvPurchase;

for (const i in this.multiplierArray) {
store.register({
id: `scorex${this.multiplierArray[i]}`, // Android requires just ID, but iOS full .com.doyban.myApp.scorexA path.
type: ProductType.CONSUMABLE,
platform: Platform.GOOGLE_PLAY,
});
}

this.createLayout();
}

Expand Down

0 comments on commit b42786f

Please sign in to comment.