Returns many transactions on iOS In-App-Purchases receipt validation
Asked Answered
Q

1

7

My app contains consumable IAP products, returns more than one transactions when I call validation receipt with this code:

[[NSBundle mainBundle] appStoreReceiptURL];

Is there any way to return only last transaction?

Is it related about restoring transactions?

I checked this Multiple receipt count for restoreCompletedTransaction inapp purchasing and this iOS in-app-purchase restore returns many transactions.

I tried to restore all purchases but it didn't work.

I'm using these lines for calling receipt:

- (void) checkReceipt {

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if(!receipt) {

}
NSError *error;
NSDictionary *requestContents = @{@"receipt-data": [receipt base64EncodedStringWithOptions:0]};
NSLog(@"requestContents:%@", requestContents);
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
                                                      options:0
                                                        error:&error];

if (!requestData) {  }

NSURL *storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

                           if (connectionError) {


                           } else {


                           }
                       }];

}

Note: This app supports iOS 8+.

Quentinquercetin answered 11/11, 2015 at 20:44 Comment(0)
U
1

It's not related to restoring transactions, it is because apple responds with array of all in-app transactions made by the user when making a validation request. The same information is contained in the receipt if you decode it locally.

If you are looking for the last transaction made you can sort the array ascending by the purchase_date_ms and take the last one.

My objective-c is not so hot so I can't help you with sorting but this document may help: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html

Unchristian answered 20/11, 2015 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.