tenpn
tenpn

Reputation: 4716

iOS receipt does not include repurchased transaction

If I wipe the data in my app, then re-purchase some managed IAP that I know the account already owns, iOS gives me the native "are you sure you wish to repurchase this item you will not be charged" dialog. That's as expected.

When the purchase returns to my app, I get the receipt with [[NSBundle mainBundle] appStoreReceiptURL]. I then attempt to verify the SKPaymentTransaction's transactionIdentifier with the receipt via my server.

However the receipt's transaction ID for this IAP, because I've already purchased it long ago, is not the same as the SKPaymentTransaction.

How should I be verifying that this is a valid repurchase? Can I get a signed receipt for this repurchase somehow?

Upvotes: 2

Views: 1071

Answers (3)

bealex
bealex

Reputation: 10014

All the purchases will be in a single receipt. You do have to check all iAPs there and look for the needed ones.

If you want the id of the original iAP transaction, there is Original Transaction Identifier

For a transaction that restores a previous transaction, the transaction identifier of the original transaction. Otherwise, identical to the transaction identifier.

More information about receipt fields is here: https://developer.apple.com/library/prerelease/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html

Anyway, does it really matter whether this is an original purchase or a repurchase? My checks of this are usually the same.

Upvotes: 3

ChikabuZ
ChikabuZ

Reputation: 10195

You can use RMStore library, and check all purchases:

RMStoreAppReceiptVerificator *verificator = [[RMStoreAppReceiptVerificator alloc] init];

if ([verificator verifyAppReceipt])
{
    NSArray *inAppPurchases = [RMAppReceipt bundleReceipt].inAppPurchases;

    for (RMAppReceiptIAP *inAppPurchase in inAppPurchases)
    {
        NSLog(@"productIdentifier %@ originalPurchaseDate %@", inAppPurchase.productIdentifier, inAppPurchase.originalPurchaseDate);
    }
}

If your receipt is nil you can refresh receipt:

 [[RMStore defaultStore] refreshReceiptOnSuccess:^{
        //get purchases
    } failure:^(NSError *error) {

    }];

Upvotes: 0

hypercrypt
hypercrypt

Reputation: 15376

As far as I understand it you should check the originalTransaction to check that this is valid for transactions that are SKPaymentTransactionStateRestored.

[[NSBundle mainBundle] appStoreReceiptURL] is for the receipt of the main application, not the IAP.

Upvotes: 2

Related Questions