Notify server with IOS in-app purchase events (renewed,cancelled..etc) - ios

I'm using auto recurring subscriptions in my app in my app,I need to change the subscription status if recurring fails from iOS.
I am following this documentation, but there are a few things that are still not clear to me:
What if my server missed the post data from iOS
How do I know if the subscription got renewed
How do I link my app user memberId (unique id) to the transaction
What is the difference between latest_receipt form iOS post data(server to server notification) and bundle receipt url after purchase.

Here are the steps I take the user to subscribe:
Ask the user to sign in. If they don't sign in they can't subscribe.
Send the app receipt to my server and store it there. If this fails they can't subscribe. This need this to validate get the latest_receipt info from the server at any time.
The user subscribes through iTunes.
Validate their receipt with the app store and check the latest_receipt to make sure they are subscribed. (This is done server side)
Repeat step 4 periodically to make sure they are still subscribed
So to answer your questions:
What if my server missed the post data from iOS?
Since I get the app receipt from the user before they subscribe I can check the with itunes directly from my sever any time and get the status of their subscription.
How do I know if the subscription got renewed?
Since you have the user receipt on your server, you can use it to get the latest receipt from apple and check the current status of the subscription. Here is how you do it Validating Receipts With the App Store
How do I link my app user memberId (unique id) to the transaction?
You could use the "Original Transaction Identifier" from the receipt as a unique id. This value is the same for all receipts that have been generated for a specific subscription
What is the difference between latest_receipt form iOS post
data(server to server notification) and bundle receipt url after
purchase?
When you send a receipt to the app store to be validated, it will return a JSON representation of the receipt that was send, this can be found in the "receipt" field. If your receipt contains subscriptions you will get "latest_receipt" and "latest_receipt_info" fields. These fields are useful when checking whether an auto-renewable subscription is currently active. If the bundle receipt is up to date then the "receipt" and "latest_receipt" will be the same.

Related

TestFlight In-App Purchase returns very old receipt with productID that no longer exists

I am working on auto-renewable subscriptions in my app.
When I purchase a subscription I get the receipt from Apple and send it to my server. My server then sends it to the Apple receipt validation endpoint, and my server retrieves the required information, such as expires_date, product_id, latest_receipt_Base64, original_transaction_id, and stores it in my database for later use.
In addition my app will get a response from my server saying whether the user is subscribed or not.
If I test it locally with Xcode on my device, that works fine, but when I test it with TestFlight, I get a very old receipt from Apple, which still contains a product ID that no longer exists. I deleted this product ID a few months ago.
Why don't I get the current receipt which I normally get when purchasing an IAP?

Update User Auto Renewal Subscription from backend

So our ios app has issue of not updating the expiry date.
Now we want to update all users expiry date from directly our php backend using the verify apple receipt code of node js
But the problem is data base has no purchase id, installion id.. so how do we identify and get the receipt of X user
we are looking at https://www.npmjs.com/package/node-apple-receipt-verify
So User1 emails us he purchased the auto renewal but it did not renew, now we want to update User1's expiry date before he opens the app
You have the send the receipt from the iOS app to your server. Ideally you should do this when the user makes a purchase, but it can be done at anytime. You should store this on the backend with that users info. This is the receipt you need to send when making the validate and verify calls to apple.
I haven't used this library before but the general idea is that you can send this same receipt every time and apple will return you the latest receipt info. You can use the latest receipt info to update/cancel the user subscription.
This is the documentation from apple:
https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1

Auto-Renewable subscription for in-app purchase

After buying a product from in-app purchase (Auto-renewable), I hit API on server to give buying information.
How to know that product is re-new for hitting API ?
When user cancel that subscription, how to known that ?
Swift 3: In order for you to detect when the user has cancelled the subscription you need to do the following;
Download the app receipt
Validate the receipt so you can get the json back containing all the in-app purchases and subscriptions dictionaries
Now inside each receipt there is a field in the dictionary called cancellation_date if this is subscription purchase and otherwise not available for other in-app purchases. If this is nil then there's no cancellation occurred, but if this has a value which contains the cancellation date then a cancellation did occurred and according to apple:
Cancellation Date
For a transaction that was canceled by Apple customer support, the time and date of the cancellation.
Treat a canceled receipt the same as if no purchase had ever been made.
then link below explains all the fields you can use inside the receipts;
https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html
Code Example:
// Create receipt request
let receiptRefreshRequest = SKReceiptRefreshRequest()
// Get the receiptUrl from the main bundle
let receiptUrl = Bundle.main().appStoreReceiptURL
//If the receipt file exist on local device
if (receiptUrl as NSURL?)?.checkResourceIsReachableAndReturnError(nil) == true{
// Get the file as data
let receipt: Data = try! Data(contentsOf: receiptUrl!)
}
now you send the receipt to apple server to validate it using your server as apple recommend. After you get callback from the validation you check the cancellation date.
Apple does not provide anything built into iOS or a REST API that gives you simple subscription details, nor are there any callbacks that you can listen for and respond to in regards to renewal or cancellation. Apple does have an API that, when given a user's local receipt and a “shared secret” generated in iTunes Connect, returns a JSON object of the user's purchase history for your app, including their current subscription information.
More Information check this link

iTunes: Associate transaction_id with an email receipt from a user

From time to time we receive user support requests where the user complains that they did not receive their item in our game.
In our database we are logging the transaction_id returned by the iTunes API whenever we issue a purchase. So in theory we can verify if a user has received their item or not, based on the field transaction_id.
However the transaction_id seems to be pretty useless. Whenever users send us a copy of the email receipt by Apple or send us a screenshot from their iTunes purchase history, they include order number or document number, but none of those matching the format of the transaction ids.
How can we associate any given receipt email from Apple with transaction_ids in our database, so our user support team can verify if a purchase has already been handled or not?

Is there a way to get IAP receipt from iTunes Account?

One of my app is running well on Apple Appstore also generating revenues. In that app user has to pay through Auto-Renewable Subscription for registration. On 13th May (Day before yesterday) a user tried to create his account but after the payment was done, my server could not saved IAP Receipt. It might happen through internet connectivity issue with the device. The App flow is:
Put values for registration like name, surname, email, pwd
Press register button
In app purchase starts
Payment is done
Get receipt from apple.
Save receipt on my server db along with his login details
So in the case that failed, the process could not reach 5th and 6th step and I could not get payment receipt. Also there in no registration details are there on my server db.
After verifying the payment, I gave him access to use the app by creating his account manually. But still I want the payment receipt so that i can further check his subscription is active or not.
Is it possible to get payment receipt now? Even in NSData form? My I tunes account is having anything related to this?

Resources