what should I do when user upgrade subscribe in apple app purchase - in-app-purchase

Now when user upgrade the auto renew subscribe product in apple app purchase, the apple server will send a DID_CHANGE_RENEWAL_STATUS message to my develop server. Now I am received the message successfully. But I did not know what should I do to handle the DID_CHANGE_RENEWAL_STATUS message properly. I read the doc and search from internet and tell me the apple will take effect the new upgraded subscribtion the next period. what should I do when received the DID_CHANGE_RENEWAL_STATUS message?
I have think one way that save the new upgraded subscribe record and mark the new subscribed record not valid until recieved switch message from apple server. should I do it like this?
now I am get the subscribe product by using product id and expire date, I must add another field to mark the new upgraded product not valid. I just want to know how to handle the DID_CHANGE_RENEWAL_STATUS message the best way. The same as downgrade auto renew product, any suggestion is appriciate.

This event is only telling you that the product_id will change.
As you said, in case of an up-grade/cross-grade, it will change right away. In case of a down-grade it will change at the next expires_date.
To know if you should change the current product associated to your user, look into the last element of the latest_receipt_info (ordered by web_order_line_item_id) and check the product_id. If its value match the upgraded product, you should change, otherwise no.
If it didn't change, you'll get the new product:
in case of an up-grade/cross-grade: an INTERACTIVE_RENEWAL S2S will succeed to the DID_CHANGE_RENEWAL_STATUS (and you'll have to check the latest_receipt_info.product_id property, as described before)
in case of down-grade: since the expires_date will be past, you'll need to check with the /verifyReceipt API if the subscription has been renewed. By looking to the product_id property, you'll detect the down-grade.

Related

IOS auto-renew subscriptions notification handling

Good day! I'm trying to implement notifications for auto-renew subscriptions and some parts of the whole system are not clear for me. Could you please help?
First of all, when user creates a subscription I get a receipt from user's device, verify it and create a record in database with all needed information. Now, the notifications are coming to server.
INITIAL_BUY notification - When does it come and why? I just got a receipt from device, verified it and I'm happy. Why do I need it?
Correct me if I'm wrong, this part is unclear for me, When user UPGRADES subscription level I get CANCEL notification for oldSubscription and a receipt with a new purchase for newSubscription, right?
So theoretical question is - if on my server side content available in oldSubscription and content available in newSubscription are different entities than when I get CANCEL for oldSubscription I just deny user's access to oldSubscription content and when I get receipt from client I create newSubscription with access to new content, right?
DOWNGRADE and CROSSGRADE. As far as I see I get DID_CHANGE_RENEWAL_PREF or DID_CHANGE_RENEWAL_STATUS. So I will get auto_renew_status in notification for this subscription and when payed period will expire I will get a receipt from user device with info about new purchase? Or I have to figure out how to handle DOWNGRADE and CROSSGRADE only by DID_CHANGE_RENEWAL_PREF and DID_CHANGE_RENEWAL_STATUS notifications?
Thank you
The problem with server receipt validation is that there is not only one way. There are endless possibility to implement this and it depends on your use case of the usage of subscriptions and how you want the communication between your app and server to happen.
In your second paragraph is the first example of those possibilities: your server will get the receipt from the device only if you implemented it that way. Also, maybe you update your database solely based on the notifications instead of the send receipt. You see, it is all up to you ;-)
Regarding you questions:
1)
Occurs at the user’s initial purchase of the subscription.
See documentation
Theoretically this is correct, but your described use case isn't an upgrade. Would be odd, if the better subscription wouldn't contain the content of the lower one.
There isn't much to handle with down- or crossgrade. The notifications only tell you that there will be a change with the next auto-renewal. Because, the user is still eligible to access the better content until the next auto-renewal. After the better subscription expired you will receive a normal DID_RENEW with the down- or crsssgrade product id.

ios auto-renewable-subscriptions - simulate cancel operation

I'd like to test CANCEL events...
My understanding is that when users switch between two items within the same group (down/up grades) - the old one is CANCELed and a new one PURCHASEd.
How would I simulate that in a sandbox?
The iTunes SUBSCRIPTION manager doesn't seem to be available on the device when I'm logged into a sandbox account. I'd also like to change subscription status from there also.
You cannot manage subscriptions in the sandbox, but there is nothing special about the upgrade/downgrade process. You just check the in_app field of the receipt as per usual.
For a downgrade, you will receive a purchase event/updated receipt containing the new, lower, subscription product at the end of the current period. If you validate the receipt then you will also see the new product in the auto_renew_product_id that indicates the product that will renew at the end of the current period
For an upgrade, you will receive a purchase event and updated receipt immediately.

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.

Transaction identifier filed in transaction receipt is different from another user

I am doing one application.In that i am using InAppPurchase concept.In that i am implementing auto renewal subscription.Whenever i subscribe for product,I am sending the receipt to apple server from my server.In that i am getting the response from apple.That response contain different fields.In that fields,i want to know about transactionIdentier.Is this fileds is different from every payment.Means whenever i subscribe first time whatever i get is this same as whatever i get at the time of renewal.And if another user subscribe for same item then that person also get the same transactionIdentifier or different one.
I think the answer you are looking for is that all users and all transactions get a unique transactionIdentifier (which unless I've misread is a string of numbers). If you want the transactionIdentifier from when the user first subscribed, I believe you can get that from transaction.originalTransaction during SKPaymentTransactionStateRestored and I believe that is the same as looking for the original_transaction_id field on your server.

in-app purchase for auto-renewal subscriptions notifications

I've been reading the various threads on in-app purchases auto-renewal subscriptions, and I think I've pieced together most of the information I need, but there are a few missing pieces. I'm hoping someone can help me.
The situation:
I have various subscription packages the user can subscribe to (e.g., package A for £1 a month, package B for £2 a month, etc.). I store the user's subscription information in my database. When the user logs in, I check which package he's on and if it's expired or not. My website, android and iOS all use the same database, hence this approach seems to make sense.
Subscribing users via in-app purchase seems straight forward enough. I check paymentQueue and once the payment is cleared, I can update my database.
My questions:
1) My understanding is the user can use iTunes to manage their subscription. Say, they go in to iTunes and cancel their subscription, how can I be notified so I can update my database? Do I need a daemon that checks expired subscriptions to see if the user renewed?
2) If the user wants to upgrade their subscription from Package A to Package B, how do I handle the pricing? Say on Jan 1st, they buy Package A, I charge them £1.00 and set the expiry date to Jan. 31st. On Jan. 15th, they want to upgrade to package B via in-app purchase. Ideally, I would charge them £2 for Package B minus £0.50 of credit they have for Package A and set the new expiry date to feb 14th. However, Apple forces me to associate each package with a tier price. How can I handle this? I don't want the user to wait until the end of the month to put them on a higher tier package...if they upgraded mid-month, it means they want the new content package B will deliver to them immediately.
Any help appreciated!
Thanks!
1) Yes you'll have to reverify your receipt check out the Receipt Validation Programming Guide in the documentation. They mention some important keys:
status - 0 if receipt is valid, or an error code
receipt - JSON response of the receipt
latest_receipt (auto-renewable only) - base 64 encoded receipt for the most recent renewal
latest_receipt_info - JSON version of latest_receipt
With this information, when a purchase is made, send the receipt to your backend for validation, the backend will keep the receipt in the DB and verify with status = 0 that it's a valid receipt. From there, every x days you can validate that receipt with a chron job, daemon, etc. and reverify. The response back each time will have latest_receipt_info that you now need to save to your DB so you have an up-to-date receipt for the next check in x days. This way you will always have the latest receipt. There is no instant notification for telling when a user cancels a subscription, but with this you'll know every x days if they have the subscription still.
2) Pricing like this unfortunately can't be handled. It was not intended for a user to "upgrade" with subscriptions - each subscription is access to it's own exclusive content as of this writing. However, if a customer emails in and complains about it, you could ask for their user name and figure out in your DB if this user has indeed upgraded mid-month and reimburse them appropriately. Very old-school and not feasible for a big user base, but hopefully you won't have that many and can keep them happy.
EDITED
For the second question, Apple's auto-renewable subscription system does not technically offer upgradeable plans between different products.
Every subscription is a stand alone product and it's up to the user to turn on/off subscriptions manually using the Subscription Manager in the iTunes Store.
However if package A and package B offer the exact same content only different duration than what ajay_nasa said is correct, you can create an single auto-subscription product with different duration options. If the user is on 1 month subscription and then the user tries to change to 2-months subscription they will get the following error message asking them go to the App Store's subscriptions manager
So basically the ONLY place the user can actually change the subscription's length is in the App Store. Whether Apple decide to pro-rate the amount left on the old subscription or just append it to the current one is really up to Apple. You need to make sure the user have access to the subscription as long as it's active by reading the Original Purchase Date and Subscription Expiration Date field from each receipt entry and determining the start and end dates of the subscription.
Answering question 1, you can verify subscription receipts in the same way as other IAP, but you'll need to check it periodically to see if the subscription has expired (the verification will tell you if it's expired).
There is more info on the Apple docs here:
http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/RenewableSubscriptions/RenewableSubscriptions.html
Actually, Apple's auto-renewable subscription system does offer upgradeable plans.
To achieve this we simply should add duration in existing Auto-Renewable Subscription. Every Auto-Renewable Subscription could be family of Subscriptions so whenever developer wants to achieve upgradation in subscription he should add duration in existing Auto-Renewable Subscription with different productID.
Whenever, user upgrade his plan in between the month then his upgrade plan will be automatically works from next month.
Answering to your question #1
Recently Apple launched a feature to enable server notification whenever the subscription is renewed. However, the subscription should be in-app.
See the links given below for your reference:
https://help.apple.com/itunes-connect/developer/#/dev0067a330b
&
https://itunespartner.apple.com/en/apps/news/45333106?sc_cid=ITC-AP-ENREC
We Need to Check Cancellation-Date provided in Receipt.

Resources