Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem while working with IOS #1587

Open
ananbetak opened this issue Aug 5, 2024 · 3 comments
Open

Problem while working with IOS #1587

ananbetak opened this issue Aug 5, 2024 · 3 comments

Comments

@ananbetak
Copy link

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
Copy link

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
Copy link
Author

nobody is able to help ?!

@metinjakupi
Copy link

Same issue on Test Device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants