Problems with checking receipts when buying AppStore in the application

I know that there have been many reports on this, but not one of them addresses the problems we are facing. So far, I think everything is set up correctly, as indicated in the iOS help library. However, we get 21002 "java.lang.NullPointerException" during our POST request to the AppStore validation URL, so I have to do something wrong.

Some problems that I noticed can cause this:

1) OPPORTUNITY TO RECEIVE

The documentation states that our iPhone application should only transmit a receipt to our server for verification, but it does not indicate exactly what the receipt is. At first, I thought it could be the entire JSON object below, but now I wonder if the receipt is just a buy-information field.

Encoded Receipt ewoJInNpZ25hdHVyZSIgPSAiQWx1SFVsb0dxejZjOVNvSlFVejF0OThhemI2WjJCb2N3WVBhK2ZVYllmdUI5ZE5RQkViV2dTNXVIUUluakdSQ2RScVkxUHhQY2cvMk1kSVlONEN2anc0RkNuc0JqT0d2NGFqNjVBczQ2SERseGd4WjdlTElGUXcrcG9QVlpTZHlEWWF6NHBPaGxxNVBmVXNqdmlZNENYd3VaQzkrSTBHdk55bVZWNkhnR2FCRUFBQURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RRRUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pTQkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIzSmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVEE1TURZeE5USXlNRFUxTmxvWERURTBNRFl4TkRJeU1EVTFObG93WkRFak1DRUdBMVVFQXd3YVVIVnlZMmhoYzJWU1pXTmxhWEIwUTJWeWRHbG1hV05oZEdVeEd6QVpCZ05WQkFzTUVrRndjR3hsSUdsVWRXNWxjeUJUZEc5eVpURVRNQkVHQTFVRUNnd0tRWEJ3YkdVZ1NXNWpMakVMTUFrR0ExVUVCaE1DVlZNd2daOHdEUVl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CgkicHJvZHVjdC1pZCIgPSAiY29tLmNvbXBhbnkuQXBwTmFtZS4xMDAwMDAiOwoJInRyYW5zYWN0aW9uLWlkIiA9ICIxMDAwMDAwMDAxNjI0ODEwIjsKCSJxdWFudGl0eSIgPSAiMSI7Cgkib3JpZ2luYWwtcHVyY2hhc2UtZGF0ZSIgPSAiMjAxMS0wMy0wOCAwMjo0NDozNyBFdGMvR01UIjsKCSJiaWQiID0gImNvbS5jb21wYW55LkFwcE5hbWUiOwoJImJ2cnMiID0gIjEuMC4xIjsKfQ=="; "pod" = "100"; "signing-status" = "0"; } 

2) INVALID JSON

The data is encoded in base64, and as soon as the decoded ones should provide information in a valid JSON object, but from what I see, the objects are definitely invalid JSON. Apple seems to be using "=", where ":" should be ";" where "," should be:

 { "item-id" = "424742510"; "original-transaction-id" = "1000000001624810"; "purchase-date" = "2011-03-08 02:44:37 Etc/GMT"; "product-id" = "com.company.AppName.100000"; "transaction-id" = "1000000001624810"; "quantity" = "1"; "original-purchase-date" = "2011-03-08 02:44:37 Etc/GMT"; "bid" = "com.company.AppName"; "bvrs" = "1.0.1"; } 

I am wondering if one reason we get the error may be because the receipt they provide is invalid JSON, so when we send the data for verification, the server rejects it. Should we decode everything by fixing an object that must be valid JSON, transcode it and then send it to Apple for verification?

I hope that someone else who has this job can point me in the right direction on two issues above or better, but provide the correct CURL call that gets a valid answer that completely solves my problems.

Thanks in advance for your help!

+8
app-store in-app-purchase
source share
3 answers

If I read the documentation correctly, you are mistaken. The receipt you send for verification is a piece of data returned by the transactionReceipt property. You don't care what it decodes, or if it decodes anything at all. You simply base64 encode it, put it in the json object as the value for the receipt-data key, and send that json object to Apple.

When you get a response from Apple, this is what should contain the json receipt information.

+10
source share

For someone else in the future, get error 21002. It took several hours to understand what was going wrong. As a rule, this means that the base encoded string in JSON 64 sent to Apple servers is incorrect. This probably means that you are not encoding Base-64 or that your encoding procedure is not working. These are the steps you should use:

1) Base-64 encodes all NSData obtained from the transactionReceipt property of your SKPaymentTransaction object into an NSString object. You can use the method below.

2) Insert this into the JSON string. In objective-C code, this will be:

 NSString* json = [NSString stringWithFormat:@"{ 'receipt-data' : '%@' }", base64String]; 

3) HTTP POST, which

4) You will get the JSON string back - extract the value for 'status'. If it is 0, your receipt is confirmed - otherwise it is an unverified purchase.

Below is the code that I use to convert NSData to a Base-64 encoded string:

 @interface NSData (Base64Encoding) - (NSString*)base64Encode; @end @implementation NSData (Base64Encoding) - (NSString*)base64Encode { static char table [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; NSInteger length = [self length]; NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; uint8_t* input = (uint8_t*)[self bytes]; uint8_t* output = (uint8_t*)data.mutableBytes; for (NSInteger i = 0; i < length; i += 3) { NSInteger value = 0; for (NSInteger j = i; j < (i + 3); ++j) { value <<= 8; if (j < length) { value |= (0xff & input[j]); } } NSInteger index = (i / 3) * 4; output[index + 0] = table[(value >> 18) & 0x3f]; output[index + 1] = table[(value >> 12) & 0x3f]; output[index + 2] = (i + 1) < length ? table[(value >> 6) & 0x3f] : '='; output[index + 3] = (i + 2) < length ? table[(value >> 0) & 0x3f] : '='; } return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]; } @end 

To use it, just do something like:

 NSString* base64string = [transaction.transactionReceipt base64Encode]; 
+4
source share

It looks like an ASCII Property List - you must use NSPropertyListSerialization to decode it.

EDIT

What is a decoded object class? It also looks like what you get when you reset NSDictionary using NSLog ()

+2
source share

All Articles