0

i'm developing the server side of an app with IAP, i know that i need to send the receipt from the app to my server when the user do a subscription, then validate the receipt with the app store for the status, date expiration, etc, & give the user the content.

But my question is, what receipt do i need to check for the renew status? i mean, the first time i check the receipt the app store give me back a receipt, status and a latest receipt, this latest receipt is the one that should i use to check the status the next time or should i use always the original receipt? i been testing with both of them and they give me the same status from the app store but i'm not sure of what is the correct way to doing.

Thanks

2 Answers2

1

Today, I have trouble with this problem.

Follow Apple doc here, I used this way to check subscription is expired or not.

+ (BOOL)checkInAppPurchaseStatus
{
    // Load the receipt from the app bundle.
    NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
    if (receipt) {
        BOOL sandbox = [[receiptURL lastPathComponent] isEqualToString:@"sandboxReceipt"];
        // Create the JSON object that describes the request
        NSError *error;
        NSDictionary *requestContents = @{
                                          @"receipt-data": [receipt base64EncodedStringWithOptions:0],@"password":@"SHARE_SECRET_CODE"
                                          };
        NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
                                                              options:0
                                                                error:&error];

        if (requestData) {
            // Create a POST request with the receipt data.
            NSURL *storeURL = [NSURL URLWithString:@"https://buy.itunes.apple.com/verifyReceipt"];
            if (sandbox) {
                storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
            }
            NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
            [storeRequest setHTTPMethod:@"POST"];
            [storeRequest setHTTPBody:requestData];

            BOOL rs = NO;
            //Can use sendAsynchronousRequest to request to Apple API, here I use sendSynchronousRequest
            NSError *error;
            NSURLResponse *response;
            NSData *resData = [NSURLConnection sendSynchronousRequest:storeRequest returningResponse:&response error:&error];
            if (error) {
                rs = NO;
            }
            else
            {
                NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:resData options:0 error:&error];
                if (!jsonResponse) {
                    rs = NO;
                }
                else
                {
                    NSLog(@"jsonResponse:%@", jsonResponse);

                    NSDictionary *dictLatestReceiptsInfo = jsonResponse[@"latest_receipt_info"];
                    long long int expirationDateMs = [[dictLatestReceiptsInfo valueForKeyPath:@"@max.expires_date_ms"] longLongValue];
                    long long requestDateMs = [jsonResponse[@"receipt"][@"request_date_ms"] longLongValue];
                    NSLog(@"%lld--%lld", expirationDateMs, requestDateMs);
                    rs = [[jsonResponse objectForKey:@"status"] integerValue] == 0 && (expirationDateMs > requestDateMs);
                }
            }
            return rs;
        }
        else
        {
            return NO;
        }
    }
    else
    {
        return NO;
    }
}

Hope this help.

Clover03ti05
  • 401
  • 1
  • 4
  • 11
0

after completion of your transaction you will get tansaction & trasaction.reciept for this transaction reciept you want to provide base64 here is the code for this

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

this jsonObjectString will save it to the server and while verifying the receipt you want to provide sharedsecret for this verify this link

Community
  • 1
  • 1
  • Thanks for the link, I have already the php script for validate the receipt and work fine, but when I have a response from the app store I receive a status, receipt & latest_receitp every time the subscription is renewed, so i'm confused about what to do with this last receipt, should i save it in my server and use it every time that I need to check for the status of the subscription or with the original receipt (the one that was generate when the transaction was made) is enough? – Alejandro Barranco Mar 10 '13 at 05:41
  • You can simply store the original receipt and just send that to Apple each time for verification. For ARS Apple will always respond with the latest receipt for that product ID. So you don't necessarily have to store the new receipts – MANCHIKANTI KRISHNAKISHORE Mar 11 '13 at 11:39