Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS + PHP - Extracting sum of money from Apple IAP

Tags:

php

ios

I am developing an iOS app that uses Apple's in-app purchase service. I am also developing a PHP backend service that, upon purchase, receives the encoded receipt string, validates it with Apple's validation servers, and saves the purchase record in the DB.

I would like to know, from the server side, either the product's price, or the sum of money that the user has actually paid for the product.

I prefer to get the result in USD, but any currency would be great as long as I have a way of knowing which currency it is (i.e. currency symbol as part of the string) so I can convert it.

The JSON object that returns from the validation doesn't contain the sum of money that has been paid in the transaction, or the product's price. Is there any way of getting this information from the receipt string only? Or perhaps from the product ID or transaction ID (both can be extracted from the receipt)? Or does this information have to be supplied by the app?

Thanks!!

like image 213
orenk86 Avatar asked Jun 30 '15 10:06

orenk86


1 Answers

Just in case anyone is interested, after some more digging around the internet - it seems impossible...

So I just send the price that was paid by the user (stored in the SKProduct object), in local currency, along with the receipt, to the server. On the server, I convert the sent price to USD and store it.

Another method I have considered was to store a JSON on the server with all of the product IDs as keys, and their prices in USD as values. Then, once the receipt is validated, I can get the product ID from the receipt and the price from the JSON. Please note that this solution may not give you the exact amount of money that the user has actually paid, because product prices and taxes may slightly differ between app stores in different countries. This solution is good for getting an estimated price only.

Hope this helps!

like image 148
orenk86 Avatar answered Nov 09 '22 20:11

orenk86