Skip to content

Commit a487696

Browse files
authored
Merge pull request #11 from timoschwarzer/inappstore-restore-receipt
Return the receipt for restored purchases
2 parents 05b1098 + 1df2cc5 commit a487696

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

plugins/inappstore/in_app_store.mm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,31 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran
298298
} break;
299299
case SKPaymentTransactionStateRestored: {
300300
printf("status transaction restored!\n");
301+
String transactionId = String::utf8([transaction.transactionIdentifier UTF8String]);
301302
InAppStore::get_singleton()->_record_purchase(pid);
302303
ret["type"] = "restore";
303304
ret["result"] = "ok";
305+
ret["transaction_id"] = transactionId;
306+
307+
NSData *receipt = nil;
308+
int sdk_version = [[[UIDevice currentDevice] systemVersion] intValue];
309+
310+
NSBundle *bundle = [NSBundle mainBundle];
311+
// Get the transaction receipt file path location in the app bundle.
312+
NSURL *receiptFileURL = [bundle appStoreReceiptURL];
313+
314+
// Read in the contents of the transaction file.
315+
receipt = [NSData dataWithContentsOfURL:receiptFileURL];
316+
317+
NSString *receipt_to_send = nil;
318+
319+
if (receipt != nil) {
320+
receipt_to_send = [receipt base64EncodedStringWithOptions:0];
321+
}
322+
Dictionary receipt_ret;
323+
receipt_ret["receipt"] = String::utf8(receipt_to_send != nil ? [receipt_to_send UTF8String] : "");
324+
receipt_ret["sdk"] = sdk_version;
325+
ret["receipt"] = receipt_ret;
304326
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
305327
} break;
306328
case SKPaymentTransactionStatePurchasing: {

0 commit comments

Comments
 (0)