j3k0 / cordova-plugin-purchase

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

Problem while working with IOS #1587

Open ananbetak opened 3 months ago

ananbetak commented 3 months ago

2 Problems !

For android , it is working okay on both cases, whenever the user have already subscribed and clicked on "the button" the popup will appear telling you are subscribed. if not, it will also allow him to subscribe again .

  1. for IOS , is that correct that i am trying to validate ios receipt on server by calling calling my server on .receiptUpdated(async receipt => { and not on "finished" ?

but for android i am calling it on .finished(async (transaction) => {}

since APPLE told me I must verify "receipt" and NOT "transaction".

  1. in IOS , the popup appears only if the user "didn't yet subscribe" , but if the user has already subscribed ( even if it is expired and inactive ). and click the purchase button i get undefined. here next in the 3rd line.

this.store?.get(productId, platformToUse)?.getOffer()?.order() .then(error => { // alert(JSON.stringify('here i get undefined')); ( here is the problem ) why i get undefined and not the popup again? if (error) { // console.log('isProcessingOrder error') // alert('isProcessingOrder error') // alert(JSON.stringify(error)) } if (error?.code === CdvPurchase.ErrorCode.PAYMENT_CANCELLED) { // payment cancelled by the user } });

this is the whole code

async setStore() { if (this.ProductType && this.store && this.ProductTypeIos) { if (this.androidPlatform) { this.store?.register([ { id: "goldsubscription", type: this.ProductType, platform: this.androidPlatform, }, { id: "silversubscription", type: this.ProductType, platform: this.androidPlatform, }, { id: "bronzesubscription", type: this.ProductType, platform: this.androidPlatform, }, ]); } if (this.iosPlatform) { this.store?.register([ { id: "goldsubscription", type: this.ProductTypeIos, platform: this.iosPlatform, }, { id: "silversubscription", type: this.ProductTypeIos, platform: this.iosPlatform, }, { id: "bronzesubscriptions", type: this.ProductTypeIos, platform: this.iosPlatform, } ]); }

  await this.setupEventHandlers();
  // Load information about products and purchases
  this.store.initialize([
    CdvPurchase.Platform.GOOGLE_PLAY,
    CdvPurchase.Platform.APPLE_APPSTORE,
  ]).then((value: CdvPurchase.IError[]): void => {
    // alert('error initilization');
    // alert(JSON.stringify(value));
    // console.log(value);
  });
}

}

async setupEventHandlers() { if (this.store) { this.store.when() .productUpdated(() => { }) .receiptsReady(() => { // alert('receipt updated') }) .receiptUpdated(async receipt => { // alert('receipt') // alert(JSON.stringify(receipt)); if (this.iosPlatform && this.counter === 0) { if (receipt?.transactions?.length > 0) { // alert('receipt') // alert(JSON.stringify(receipt)); try { const platform = this.platformIs === 'ios' ? 'ios' : 'android' await this.dataService.addSubscription(this.userEmail, receipt, platform); this.isCallingServer = false; } catch (e: any) { this.isCallingServer = false; // alert(JSON.stringify(e)); } } this.counter++; } }) .approved(async (transaction) => { // alert('transaction') // alert(JSON.stringify(transaction)); // if (this.androidPlatform && this.counter < 2) // transaction.verify(); }) .verified(async receipt => { this.verifiedCallback.forEach(callback => callback()); }) .unverified(unverified => { }) .finished(async (transaction) => { if (this.androidPlatform) { // alert('.finished'); // alert(JSON.stringify(transaction)); try { const platform = this.platformIs === 'ios' ? 'ios' : 'android' await this.dataService.addSubscription(this.userEmail, transaction, platform); this.isCallingServer = false; } catch (e: any) { this.isCallingServer = false; // alert(JSON.stringify(e)); } } });

  // Show errors for 10 seconds.
  this.store.error(error => {
    if (error.code === CdvPurchase.ErrorCode.PAYMENT_CANCELLED) {
      console.log('The user cancelled the purchase flow.');
      return;
    }
    // setTimeout(() => {
    //   console.log('30 seconds');
    // }, 30000);
  });
}

}

teiermobi commented 3 months ago

I can confirm the iOS behavior. If a user has already subscribed, even if the subscription has been canceled or has expired, the store.get function returns undefined.

ananbetak commented 3 months ago

nobody is able to help ?!

metinjakupi commented 2 months ago

Same issue on Test Device