In App Purchase Autorenew Receipt Format Problems

171 views Asked by At

I have an auto-renewable in-app purchase. When the user signs up for the first time, the app receives a receipt in the form of NSDATA. I encode that into a string:

[NSString stringWithUTF8String:[receiptData bytes]]];

Then I post it to my server as a blob.

Then when the user signs into the app, I get the receipt from my server, change it into NSDATA:

[receipt dataUsingEncoding:NSUTF8StringEncoding]

then I run a method on it to verify that the receipt is valid. From my reading I have gathered that responses will be a newer receipt, or a status code of some sort saying its valid or not.

NSString *jsonObjectString = [self encodeBase64:(uint8_t *)receipt.bytes
                                         length:receipt.length];



NSString *itunescombo = @"xxxxxxxxxxxxxxxxxxxxxx";
// Create the POST request payload.
NSString *payload = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\", \"password\" : \"%@\"}",
                     jsonObjectString, itunescombo];

NSData *payloadData = [payload dataUsingEncoding:NSUTF8StringEncoding];


NSString *serverURL = ITMS_SANDBOX_VERIFY_RECEIPT_URL; 

// Create the POST request to the server.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverURL]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:payloadData];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];



[conn start];

Then as a response, I keep getting either:

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

or just

{"status":21002}

Can someone please tell me where I am going wrong? That error means that the format of the receipt is incorrect but I am not sure where this is happening between all the format manipulating.

Thank you! R

1

There are 1 answers

0
MANCHIKANTI KRISHNAKISHORE On

Once change your code to

NSString *jsonObjectString = [self encodeBase64:(uint8_t *)transaction.transactionReceipt.bytes
                                         length:transaction.transactionReceipt.length];