Open ananbetak opened 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
.
nobody is able to help ?!
Same issue on Test Device
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 .
but for android i am calling it on .finished(async (transaction) => {}
since APPLE told me I must verify "receipt" and NOT "transaction".
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, } ]); }
}
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)); } } });
}