Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting 21004 as status value in reply from apple's sandbox server testing auto-renewable subscriptions in ios?

I'm testing In app purchase auto-renewable subscription but apple's sandbox server always returns status=21004

 #define SHARED_SECRET @"INSERT HERE YOUR ITUNESCONNECT SHARED SECRECT KEY FOR AUTORENEWABLE SUBCRIPTIONS RECEIPT VALIDATION"

-(void)checkReceipt {
// verifies receipt with Apple
NSError *jsonError = nil;
NSString *receiptBase64 = [NSString base64StringFromData:receiptData length:[receiptData length]];
NSLog(@"Receipt Base64: %@",receiptBase64);

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                                            receiptBase64,@"receipt-data",
                                                            SHARED_SECRET,@"password",
                                                            nil]
                                                   options:NSJSONWritingPrettyPrinted
                                                     error:&jsonError
                    ];
NSLog(@"%@",jsonData);
NSError * error=nil;
NSDictionary * parsedData = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
NSLog(@"%@",parsedData);
NSLog(@"JSON: %@",[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
// URL for sandbox receipt validation; replace "sandbox" with "buy" in production or you will receive
// error codes 21006 or 21007
NSURL *requestURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:requestURL];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:jsonData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if(conn) {
    receivedData = [[NSMutableData alloc] init];
} else {
    completionBlock(NO,@"Cannot create connection");
}
}

Can someone help me to get proper receipt verification?

like image 645
Ravindhiran Avatar asked Feb 20 '13 09:02

Ravindhiran


People also ask

How do I check my sandbox subscription?

You can choose a subscription renewal rate for each Sandbox Apple ID account in App Store Connect. For a complete list of subscription durations within the sandbox environment and more information, see Test in-app purchases.

How do I cancel sandbox iOS?

On the test iOS device, open Settings > App Store. In the Sandbox Account section, tap your highlighted Sandbox Apple ID, and tap Manage. In the sandbox Subscriptions page, select the subscription product that you want to cancel. Tap the Cancel Subscription button.


2 Answers

You must replace this text at the top INSERT HERE YOUR ITUNESCONNECT SHARED SECRECT KEY FOR AUTORENEWABLE SUBCRIPTIONS RECEIPT VALIDATION with the secret key that you get from iTunes Connect. (obviously, don't post the full secret on Stack Overflow, though).

The secret is typically a 32 digit, alpha-numeric string that looks something like this 39fkjc38jd02mg72k9cn29dfkm39fk00 (this one is fake).

In (the new) iTunes Connect go to My Apps > (Then click on your app) > In-App Purchases > View or generate a shared secret

like image 106
Andrew Avatar answered Oct 21 '22 09:10

Andrew


go to ituenes connet and then your app and then go to ManageInApp purchases and then here see the left bottom there is an option view or generate a sharedsecret here you can generate an shared secret or you can view the previous shared secret

like image 40
MANCHIKANTI KRISHNAKISHORE Avatar answered Oct 21 '22 08:10

MANCHIKANTI KRISHNAKISHORE