LoginSignup
0
1

More than 5 years have passed since last update.

[iOS] How to validate the receipt of In-App purchase

Posted at

Here is the official guide to validate the receipt with Objective-C.

Receipt Validation Programming Guide

But here just use curl to validate the in-app purchase receipt.

Validate API

There are two url to post the receipt to the apple api server. One is sandbox and another one is production.

https://sandbox.itunes.apple.com/verifyReceipt
https://buy.itunes.apple.com/verifyReceipt

Encode the receipt with base64

This api does not accept the raw receipt, but the base64 encoded value.

Here introduce two ways to encode the receipt.

Command Line

echo "receipt-string" | openssl enc -e -base64

Ruby Script

require 'base64'
str = "receipt-string"
p Base64.encode64(str)

POST encoded receipt

Here we use the curl to post the encoded receipt to the apple api server.

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST \
-d "Encoded-receipt" \
https://sandbox.itunes.apple.com/verifyReceipt

You will get a json result with status code, 0 is valid or error code here.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1