What the server-to-server responseBody looks like? - ios

What the server-to-server responseBody looks like and how should i know if a user cancelled subscription or refunded?
I have seen this doc: https://developer.apple.com/documentation/appstoreservernotifications/responsebody, but still confused.I have not seen a field like cacellation_date.
Should i parse the latest_receipt_info, and then if user cacel subscription, there will be cacellation_data and cacallataion_intent?

The cancellation fields are only for the case that the Apple Support cancelled the subscription for a customer. In that case you get the cancellation_date_ms field in the server-to-server response.
cancellation_date_ms
The time and date that Apple customer support canceled a transaction or the time and date the user upgraded an auto-renewable subscription.
more details here.
cancellation_date is the corresponding field in the receipt itself.
Note: cancellation_date and cancellation_date_ms both only exist in the production environment.
To check if a user cancelled your subscription, you would use expiration_intent (The reason a subscription expired).
You can use this value to:
Decide whether to survey the subscribers who have opted in to an account on your system or show alternative subscription products within the same group, if the value is “1”.
Decide whether to show the same or alternative subscription products, if the value is “2”, since the user did not actively make the choice to unsubscribe.
Decide whether to present a subscription offer to win back the user if the value is "1".
more details here

Related

How to use fields in ASN Local receipts while evaluating iOS Auto-Renewable iAP?

Our iOS App supports yearly subscriptions with different free trial periods. We are aiming to evaluate the receipts available locally on user's device offline.
**We are planning to do this: **
Check if cancellation_date exists - inactive subscription
If cancellation_date doesn’t exist, check if purchase_date exists:
if yes, check if expires_date exists and is in an active period - active subscription
if not, check if expires_date exists and is in an active period - may be trial period
The thing we cant figure out is, if user turns-off subscription in trial period stopping payment, how can the app know such events?
Does expires_date indicate "trial duration + 1 Year" or only "1 year"?
Does original_purchase_date or purchase_date indicate "start of trial" or "the date user has made payment"?
Note: We also plan to periodically refresh local receipt using
SKReceiptRefreshRequest.
Make sure you are looking at the sub-contents of all the in_app entries, ASN1 type 17. There will be one for each renewal.
Cancellation date is only set if the subscription is cancelled by Apple customer service, you should mostly depend on the expiration date.
The trial is treated as separate in_app field in the in_apps array. So as long as you are looking for the latest expires_date field, you will be computing the correct expiration date.
Also, I'm not sure how up to date the in_apps are when using SKReceiptRefreshRequests. Apple says to use server side validation, and the /verifyReceipt endpoint when using subscriptions.
Shameless plug, but if you are trying to implement subscriptions with less effort you might want to try my service, RevenueCat. We handle all the receipt parsing and tracking for you and do it correctly. You can sign up with my referral code.

How do I associate a user with an auto-renewable subscription involving Apple's status notifications?

How do I associate an auto-renewable subscription in a way that lets me know which notifications are for which users in MY database? Is there some sort of id from the original receipt that I can store as a field for a User?
It is great that I know when a user cancels or renews, etc but it doesn't help that I am not sure which user this is happening for.
When you visit the docs and scroll down to Status Update Notifications, you'll notice that status notifications do have an original_transaction_id field, is this something that persists and can be relied on?
Yes, you can use original_transaction_id. It's property saved for all renews.
If the user cancels their subscription and buys a new subscription, then original_transaction_id will change.
However, if the user upgrades or downgrades their subscription, original_transaction_id will not change.
This is supported on modern versions of iOS, including iOS 10.
Another way to do it is to save an array of transaction_id values and associate these with user accounts. Depending on your needs, this might work better for you.
UPD by Stafox: time-to-time original_transaction_id may changes after renew and may still the same after cancel and resubscribe.

How to identify that a user changed subscription in manage->setting?

We support subscriptions in our apps and now users can change the subscription from the settings->manage subscriptions button on their ios devices.
How can we find out about these kind of changes in the app?
I was expecting to see a transaction on this change in the SKPaymentQueue or see indication for it when validating the receipt but I could not find anything when I changed from one subscription level to another (in the same subscription group).
Apple documentation on the storeKit (https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html#//apple_ref/doc/uid/TP40008267-CH7-SW6) mention cancellation but not subscription change.
How can the application (client side or server side) can be notified when a user changed his subscription?
By Validating Receipts With the App Store on monthly periodically basis just before user plan going to renew, you can check in Product Identifier
The product identifier of the item that was purchased.
ASN.1 Field Type 1702
ASN.1 Field Value UTF8STRING
JSON Field Name product_id
JSON Field Value string
This value corresponds to the productIdentifier property of the
SKPayment object stored in the transaction’s payment property.

iOS - how should i make sure the IAP receipt is valid

I want to offer a renewable subscription in my iOS application. The user subscribed and the receipt is stored. Now i wonder how i need to make sure that the receipt is valid and not cancelled:
If the user cancels the subscription and it is not renewed, how would i know it? If the subscription is renewed, when a new receipt will be created?
If the user cancels the subscription through apple support (because, for example, he bought it my mistake), how can i know it? The receipt on the device will be valid. Should i refresh the receipt every time the user logs in?
EDIT:
I forgot to mention it, but the receipt is checked in the client side.
Generally you need to check the expiration date of the subscription. To do that you need to get the receipt list and find the most recent record. It could be done using several ways (iOS Restore in App purchases with receipts)
If user cancels the subscription, I believe it means that receipt list simply will updated and you can find this by reading the 'cancellation date' field. To get track the expiration date I'd recommend to use UILocalNotification. If user continues to use subscription and you doubt whether he prolonged it or not, you should update the receipt list and send request to Apple [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]
If user cancel the subscription through apple support , you can find the corresponding record (aka "Cancellation Date") in the receipt data. Please read (https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html).
I'd recommend to check the receipt from time to time or use a notification mechanism.

Handle Auto Renew Subscription iOS SDK

I am developing an app which requires auto renew subscription monthly and I want to maintain that on per user basis who logged into my app. is it possible anyhow with in app purchase. Also how can we handle cancelation of subscriptions ?
I want to maintain all this on my own server.
In the StoreKit documentation, it mentioned in Cancellation section:
A subscription is paid for in full when it’s purchased and can be
refunded only by contacting Apple customer service. For example, if
the user accidentally buys the wrong product, customer support can
cancel the subscription and issue a refund. It’s not possible for
customers to change their mind in the middle of a subscription period
and decide they don’t want to pay for the rest of the subscription.
To check whether a purchase has been canceled, look for the
Cancellation Date field in the receipt. If the field has a date in it,
regardless of the subscription’s expiration date, the purchase has
been canceled—treat a canceled receipt the same as if no purchase had
ever been made.
Depending on the type of product, you may be able to check only the
currently active subscription, or you may need to check all past
subscriptions. For example, a magazine app would need to check all
past subscriptions to determine which issues the user had access to.
Bear in mind that users can cancel the subscription anytime without opening your App. Therefore, you have to check the status of subscription every time the user logs into your App.

Resources