Unclear how/when to call my own API after user purchases non-renewing subscription
Closed this issue · 1 comments
Hi, this might be a dumb question and apologies if this is mentioned in the docs somewhere, but I can't seem to find clear documentation how to do this.
Our app is only accessible when a user has an active non-renewing subscription.
The flow we have atm is:
user registers > user signs in > API check if user has active subscription > If not: go to product/subscription overview > user selects a subscription duration > user pays > send data to our API > go to app
Atm I'm doing an API call in
shop.when().approved((p) => {
// API call
}
as well as in
shop.when().receiptUpdated((receipt) => {
receipt.transactions.forEach(transaction => {
if(transaction.transactionId != 'appstore.application' && transaction.state == 'finished') {
transaction.products.forEach(product => {
// API call
});
}
});
refreshUI()
})
There are a few problems I'm having:
- When a user purchases a subscription the API gets called a dozen or more times in just a few seconds (I can prevent this from creating multiple subscriptions in our API but would like to prevent the API being called that often for a single purchase)
- In production, on iOS, when the user sees the subscription page, it automatically sends an API call for a purchase even when the user hasn't clicked anything yet, allowing them to access the app for free. Even when they've never used/paid for the app ever before
So my question is, when or in which state should I do the actual API call? And what could cause the issue of the API being called when the user hasn't even clicked on a product/subscription yet?
You can view the whole (VueJS) component here: https://codeshare.io/3y1nl6 (might take a minute to show the actual code)
Hi, non-renewing subscriptions are like consumables, they do not remain in the transaction queue.
When a transaction is approved, add it to your database through API call (which you can then use to count how much "subscription time" the user has purchased).
Notice that on iOS a "transaction" exists that describe the "download", you might decide not to make that API call in that case. Also transaction can appear multiple times for some reasons, if your database doesn't allow multiple transactions with the same ID you'll be fine.