Now we grouped the subscription in the way that the user have possibility to downgrade/upgrade or cancel the current subscription from a Subscription Screen (settings/appleId/iTunes&AppStore..).
How to handle this case of user subscription change in app or on the server side ?
In app:
You should get a callback in SKPaymentObserver with the new transaction. It will usually be with the same originalTransactionID.
Server:
Use server to server notification detailed here https://itunespartner.apple.com/en/apps/news/45333106
Related
I have a flutter mobile app with a backend. I need to synchronize subscription with backend to share subscription across platforms.
For that I follow this flow :
I create a new account
I initiate new subscription after account has been created
I listen for purchase update and when I receive a purchase details with purchaseDetails.pendingCompletePurchase I send it to backend and use apple verifyReceipt endpoint to check receipt in purchaseDetails.VerificationData.ServerVerificationData
If receipt is valid I save the OriginalTransactionId from purchaseDetails.PurchaseID to database
My question here is:
After it return validation state from server I wonder if I still need to call completePurchase even if I called verifyReceipt endpoint.
I'm not sure to understand what completePurchase really do...
In the end, later I wait for apple server notification to update subscription status
I generally understand receipt validation on In App Purchases. Most libraries make this as simple as calling a method.
I'm not so clear on how subscriptions work though -- specifically, how can I detect if the subscription is cancelled?
Subscriptions are cancelled on Apple's iTunes interface only. How is my server supposed to know that a subscription was cancelled?
From the Apple docs:
The user can also cancel their subscription by disabling auto-renew and intentionally letting their subscription lapse. This action triggers the App Store to send your server a status update notification of type DID_CHANGE_RENEWAL_STATUS. Your server can parse the auto_renew_status and the auto_renew_status_change_date to determine the current renewal status of the subscription.
https://developer.apple.com/documentation/storekit/in-app_purchase/subscriptions_and_offers/handling_subscriptions_billing#3221914
The answer from Jacob is correct for the case that the user disables the auto-renewal of his subscription. If the user requested a refund from Apple and they cancel the subscription for him. Your server will receive a CANCEL notification and the receipt will contain a cancellation_date field.
You need to handle both of those cases, because when the user cancels (deactives the auto-renewal) his subscription, it is still valid (till it expires). When Apple customer support cancels the subscription, then it is from this point on invalid.
Note: the CANCEL notification is also triggered when a user up- or downgrades to a different subscription of the same subscription group. See this answer for more details on that.
We are implementing server side receipt validation for auto renewable subscription. Now when a user turn off the subscription or when it auto renew there is no notification send from apple server to our server. We want to poll apple server when the subscription is about to expire. So how can we do this?
Is there a way to schedule such polling at specific date ?
First when any in app purchase made you need to store receipt data after validating it. Also you need to store expire date of that particular purchase which you will get by receipt validation.
Now create a crone job in your server to validate auto renew purchase, crone job time interval is up to you as per your project need but let say for example take 1 hours. In the crone job you need to select only those record which expire time with in next 6 hours(You can change this time as per your need). Then again validate this receipt and if purchase get auto renew then you will get list of receipt. You will get always new receipt in the list whenever purchase auto renew. In this you will get new expire time. Suppose you are not getting any new receipt then it means user has cancel subscription
You would need Receipt validation.
If your app offers auto-renewable subscriptions, you can receive server notifications from the App Store about key events by setting up an optional URL that links to your server.
Before sending a notification to your server, the App Store will try to establish a secure network connection with your server by using App Transport Security (ATS) protocols. If a secure connection cannot be established, notifications will not be sent to your server. See Requirements for Connecting Using ATS to learn more about security requirements.
After a secure HTTPS connection has been established, the App Store will deliver JSON objects through an HTTP post to your server for key subscription events. See the In-App Purchase Programming Guide to learn more about the contents of this HTTP post.
Use server notifications together with Receipt Validation to validate a customer's current subscription status and provide them access to content or services from within your app.
For more info : Link
Not get notifications such as cancel as these notifications are only sent when a subscription is canceled by Apple directly.
The renewal notification, "Automatic renewal was successful for an expired subscription. Check Subscription Expiration Date to determine the next renewal date and time." In general, iTunes will attempt to charge the user account a day before an auto-renewing subscription is scheduled to expire. If the renewal is successful, there is no server-to-server notification because the auto-renewing subscription did not enter into an expired state. There is no support at present to simulate this event in the sandbox environment.“
Read more: https://forums.developer.apple.com/message/283579#283579
How can we cancel an auto Renewable subscription from itunes and get a call back in our server?After getting cancelled from itunes I should get notified in my server or in phone so that I can call cancel subscription in my server.
I read something like this somewhere
" When you hit apple server with the last receipt you have saved, it
will return you the code for cancellation of subscription"
My doubt is:
Is there any specific error code returned in case if the subscription is cancelled?
I have a cancel button inside my app to cancel subscription.What I think of doing is to redirect to the setting ->manage subscriptions page for now.After cancellation How can I get notified about this?
OR,shall I set a cron in the backend to check for cancellation?
My iOS app offers auto-renewable subscriptions. Only the users that has non-expired subscriptions are supposed to receive some news alerts through push notifications. Currently I thought of two possible ways to implement this. One is to subscribe and unsubscribe to push notification from the app by checking the subscription state during the application launch and send push notifications to all subscribers from the server-side.The second method is to update the expiration date of the subscription to the server and make the server checking if the subscription is expired before sending push notifications.
I understand that both methods will always require the app to be launched frequently to update the subscription status. Is there any other way to handle this task? Any tips/suggestions would be highly appreciated. Thanks!