Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In App Purchase Receipt verification within app

I want to verify the transaction receipt within my app,

Here is my code,

- (void)recordTransaction:(SKPaymentTransaction *)transaction {

    NSData *receiptData = [NSData dataWithData:transaction.transactionReceipt];

    NSString *encodedString = [Base64 encode:receiptData];

     NSURL *url = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];

    [request setPostValue:encodedString forKey:@"receipt-data"];

    [request setRequestMethod:@"POST"];

    [request setDelegate:self];

    [request startAsynchronous];

}

I am getting output:

{"status":21002, "exception":"java.lang.NullPointerException"}

Can someone help me to get proper receipt verification?

like image 821
SST Avatar asked May 08 '11 11:05

SST


People also ask

How do I validate a receipt for an in app purchase?

To test receipt validation, you must run the app on a real device, as it won't work in the simulator. You'll need a Development Certificate and a sandbox account. When testing an app through XCode, the app won't have a receipt by default.

What is receipt validation in app purchase?

The Receipt Verification Service (RVS) enables validation of purchases made by your app's users.

How do I verify In app purchases Apple?

Use the production URL https://buy.itunes.apple.com/verifyReceipt when your app is live in the App Store. For more information on these endpoints, see verifyReceipt. Verify your receipt first with the production URL; then verify with the sandbox URL if you receive a 21007 status code.

What is in app purchase receipt?

The receipt for an application or in-app purchase is a record of the sale of the application and of any in-app purchases made from within the application. You can add receipt validation code to your application to prevent unauthorized copies of your application from running.


1 Answers

Just for those who may find it helpful. I noticed that apple has updated the In App Purchasing Guide with some status code that are for the auto renewable subscription purchases but seem to apply here as well.

  • 21000 The App Store could not read the JSON object you provided.
  • 21002 The data in the receipt-data property was malformed.
  • 21003 The receipt could not be authenticated.
  • 21004 The shared secret you provided does not match the shared secret on file for your account.
  • 21005 The receipt server is not currently available.
  • 21006 This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response.
  • 21007 This receipt is a sandbox receipt, but it was sent to the production service for verification.
  • 21008 This receipt is a production receipt, but it was sent to the sandbox service for verification.

Important: The non-zero status codes here apply only when recovering information about a auto-renewable subscription. Do not use these status codes when testing responses for other kinds of products. (Really?)

I hope this helps as a reference. I got nailed with 21007.

List of status codes on Apple's website: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

like image 144
Chase Avatar answered Sep 30 '22 13:09

Chase