edmoks
edmoks

Reputation: 27

Error on In-App Purchase

I have an app on the App Store and it has an in-app purchase feature. The in-app purchase worked for months with no problem, but suddenly it stoped working on the receipt validation. I don't know why, since nothing on the code changed.

Does anyone can shade a light on this? Did Apple recently changed something regarding in-app purchase?

Thanks a lot! Eduardo Rangel

Upvotes: 0

Views: 173

Answers (1)

Rhm Akbari
Rhm Akbari

Reputation: 360

If you are using CargoBay third party library to validate receipts, this framework has been a while has been suffering from certificate expiration, and no longer fully work however there is a work around to get it partly working, but I'm not sure if it's your case.

If you are using CargoBay make the following change in CBPurchaseInfoFromTransactionReceipt and comment out a section of code which will disable part of local security check.

NSDictionary * CBPurchaseInfoFromTransactionReceipt(NSData *transactionReceiptData, NSError * __autoreleasing *error) {
NSDictionary *transactionReceiptDictionary = [NSPropertyListSerialization propertyListWithData:transactionReceiptData options:NSPropertyListImmutable format:nil error:error];
if (!transactionReceiptDictionary || ![transactionReceiptDictionary respondsToSelector:@selector(objectForKey:)]) {
    return nil;
}

NSString *purchaseInfo = [transactionReceiptDictionary objectForKey:@"purchase-info"];
NSDictionary *purchaseInfoDictionary = [NSPropertyListSerialization propertyListWithData:CBDataFromBase64EncodedString(purchaseInfo) options:NSPropertyListImmutable format:nil error:error];
if (!purchaseInfoDictionary) {
    return nil;
}

// Comment this section skipping local purchase validation. It's failing in Sandbox due to the old hardcoded certificate from April 2016, and it will move to Production in mid May 2016.
// Cargobay will still verify the purchase with the Apple Sandbox/Production server after skipping the local verification. Hopefully update hardcoded certificate
// in order to move back to Cargobay repository.

/*
NSString *signature = [transactionReceiptDictionary objectForKey:@"signature"];
NSDate *purchaseDate = CBDateFromDateString([purchaseInfoDictionary objectForKey:@"purchase-date"]);

if (!CBCheckReceiptSecurity(purchaseInfo, signature, purchaseDate)) {
    if (error) {
        NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
        [userInfo setValue:NSLocalizedStringFromTable(@"Cannot extract purchase info from transaction receipt because purchase info failed to validate against its signature.", @"CargoBay", nil) forKey:NSLocalizedDescriptionKey];
        [userInfo setValue:NSLocalizedStringFromTable(@"Purchase info failed to validate against its signature.", @"CargoBay", nil) forKey:NSLocalizedFailureReasonErrorKey];
        *error = [NSError errorWithDomain:CargoBayErrorDomain code:CargoBayErrorCannotExtractPurchaseInfoFromTransactionReceipt userInfo:userInfo];
    }

    return nil;
}
*/

return purchaseInfoDictionary;

}

Upvotes: 1

Related Questions