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?
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.
The Receipt Verification Service (RVS) enables validation of purchases made by your app's users.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With