4.4.9
0.61.5
iOS
Sandbox environment
I have the below code snippet to handle subscription purchase
// On button press
requestPurchase(sku);
// Purchase updated listener
this.purchaseUpdateSubscription = purchaseUpdatedListener((purchase) => {
console.log('purchaseUpdatedListener', purchase);
const receipt = purchase.transactionReceipt;
await finishTransaction(purchase);
await Firebase.updateUser({
'subscription.ios': purchase
})
});
So far I was able to perform purchase and store the receipt onto Firebase. But my question is do I need to call getAvailablePurchases on every app launch to store the latest purchase receipt? Or do I only need to store the receipt when the user purchases the subscription for the first time? Also, how do I validate if the subscription has expired?
I'am also wondering this approach. How can I validate if the subscription has expired? Should I check getAvailablePurchases() everytime?
This is usually done using webhooks. For Apple you can enable server-to-server notifications that will communicate with your server. Google has something similar, but setting it up is much more complicated and there is no docs on that. Android Developers has a basic doc here, but what you want is a Pub/Sub system that google has.
Also this StackOverflow question has some good information
UPDATE
I actually found a good source that will help you to set up server-to-server notifications. RevenueCat Docs has a lot of useful information. Here is the link for Apple and Google Pub/Sub
To validate if the subscription I'm doing that
const result = await validateReceiptIos(receiptBody, true);
const lastSubscriptionBasic = result.latest_receipt_info
.filter(item => item.product_id === "subscription_basic") // keep only the "subscription_basic" subscriptions
.sort((a, b) => b.expires_date_ms - a.expires_date_ms)[0]; // sort by expiration date and get the first one
const isSubscriptionBasicValid = lastSubscriptionBasic.expires_date_ms > moment() // check if expiration date is before now
Hi @camel113, can you please explain what is the receiptBody, how can i correctly pass it to validateReceiptIos() ? Because I see it's type is Record<string, unknown>, not just a String
And how to work on Android ?
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.
Most helpful comment
This is usually done using webhooks. For Apple you can enable server-to-server notifications that will communicate with your server. Google has something similar, but setting it up is much more complicated and there is no docs on that. Android Developers has a basic doc here, but what you want is a Pub/Sub system that google has.
Also this StackOverflow question has some good information
UPDATE
I actually found a good source that will help you to set up server-to-server notifications. RevenueCat Docs has a lot of useful information. Here is the link for Apple and Google Pub/Sub