Error 21002 - Validating Receipts Server-Side

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);

It looks like you're mixing up the App Store Server API with the /verifyReceipt endpoint (which is now also deprecated as of June 2024).

The URL should be: https://sandbox.itunes.apple.com/verifyReceipt

For subscriptions, the request body also requires a password which is your app's shared secret (you can obtain this from App Store Connect)

In addition to all of the above information, see TN3122: Receipt validation with the App Store fails with a non-zero error code that describes common configurations that cause unsuccessful receipt validation with the App Store and how to resolve them.

Error 21002 - Validating Receipts Server-Side
 
 
Q