radu florescu
radu florescu

Reputation: 4363

Implement Receipt verification for Apple Store Receipt in C#

I am trying to implement a verify receipt for an In App Apple Store purchase receipt.

According to their website it looks like ?!?.

I need to know the structure, can you please help me with a sample of what to encrypt.

Can you please help me?

To verify the receipt, perform the following steps:

Retrieve the receipt data. On iOS, this is the value of the transaction's transactionReceipt property. On OS X, this is the entire contents of the receipt file inside the application bundle. Encode the receipt data using base64 encoding. Create a JSON object with a single key named receipt-data and the string you created in step 1. Your JSON code should look like this:

{
     "receipt-data" : "(receipt bytes here)" 
} 

Post the JSON object to the App Store using an HTTP POST request. The URL for the store is

https://buy.itunes.apple.com/verifyReceipt. The response received from the App Store is a JSON object with two keys, status and receipt. It should look something like this:

{
     "status" : 0,
     "receipt" : { (receipt here) } 
}

If the value of the status key is 0, this is a valid receipt. If the value is anything other than 0,

this receipt is invalid.

Upvotes: 0

Views: 3825

Answers (1)

justinpeck
justinpeck

Reputation: 141

You can deserialize the store receipt into a class like this:

public class receipt
{
    public string original_purchase_date_pst { get; set; }
    public string original_transaction_id { get; set; }
    public string original_purchase_date_ms { get; set; }
    public string transaction_id { get; set; }
    public string quantity { get; set; }
    public string product_id { get; set; }
    public string bvrs { get; set; }
    public string purchase_date_ms { get; set; }
    public string purchase_date { get; set; }
    public string original_purchase_date { get; set; }
    public string purchase_date_pst { get; set; }
    public string bid { get; set; }
    public string item_id { get; set; }
}

Table 5-1 in the The Store Receipt section of this page of the In-App Purchase Programming Guide has the field-by-field break down. Hope that helps!

Upvotes: 1

Related Questions