Hi! I am creating a plugin that implements the In App Purchases and Subscriptions. I have done everything already and the only error I am debugging right now is with the validation of receipts.
I always get status 21002 even the format is base64 already. I prefer to use the verifyReceipt as it is intended for my plugin.
I have tried everything but still the response I get is status 21002 which is I know the data in receipt-data is malformed or missing. What can I do about this? Thank you so much in advance!
This is my code too: (Objective-C)
NSString *receiptString = [receiptData base64EncodedStringWithOptions:2];
if (!receiptString) {
[self post_receipt_validation_result:@{@"status": @"error", @"message": @"Failed to encode receipt data"}];
return;
}
NSLog(@"Requesting to Sandbox: %@", receiptString);
NSURL *storeURL = [NSURL URLWithString:@"https://api.storekit-sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSDictionary *requestContents = @{@"receipt-data": receiptString};
NSError *jsonError;
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents options:0 error:&jsonError];
if (jsonError) {
[self post_receipt_validation_result:@{@"status": @"error", @"message": jsonError.localizedDescription}];
return;
}
NSLog(@"Request Data: %@", requestData);
[storeRequest setHTTPBody:requestData];
NSLog(@"Store Request: %@", storeRequest);