I am working on our first in-app purchase and trying to use our server to verify the receipt using our server to connect to Apple's server. I keep getting Status 21003. Here is our Objective C code....
-(IBAction)NewVerifyReceipt {
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (receipt) {
NSString *receiptEncoded = [receipt base64EncodedStringWithOptions:0];
// In addition we need to replace +(plus) sign for encoding
receiptEncoded = [receiptEncoded stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
NSString *post = [NSString stringWithFormat:@"receipt-data=%@", receiptEncoded];
NSLog(@"\n\n\n POST:%@", receiptEncoded);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@“our_server_code.php”]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"result =%@",result);
NSLog(@"json =%@",json);
if (!error) {
int statusCode = [[json objectForKey:@"status"] intValue];
if (statusCode == 0) { // Receipt-data is valid
}
}
}];
[dataTask resume];
}
Here is our server code: PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://sandbox.itunes.apple.com/verifyReceipt");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
Can anyone please help?