Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returns many transactions on iOS In-App-Purchases receipt validation

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+.

like image 964
Gokhan Gultekin Avatar asked Nov 11 '15 20:11

Gokhan Gultekin


1 Answers

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

like image 196
Marc Greenstock Avatar answered Oct 04 '22 21:10

Marc Greenstock