Home » Php » iOS + PHP – Extracting sum of money from Apple IAP

iOS + PHP – Extracting sum of money from Apple IAP

Posted by: admin July 12, 2020 Leave a comment


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?


How to&Answers:

As far as I’m aware, the actual amount paid isn’t included in the receipt (keys are listed here).

However, the price is included in the SKProduct object and the product identifier is available in the receipt, so you could send all the prices to your server when you send the receipt, and use the product identifier in the receipt to get the corresponding price.

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

    NSMutableDictionary *prices = [NSMutableDictionary dictionary];
    for (SKProduct *product in [response products]) {

        NSString *productIdentifier = [product productIdentifier];
        NSDecimalNumber *price = [product price];
        NSLocale *priceLocale = [product priceLocale];

        prices[productIdentifier] = @[price, priceLocale];

    // keep these in memory and send them with the receipt


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!