Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the receipt for restored purchases #11

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions plugins/inappstore/in_app_store.mm
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,31 @@ - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)tran
} break;
case SKPaymentTransactionStateRestored: {
printf("status transaction restored!\n");
String transactionId = String::utf8([transaction.transactionIdentifier UTF8String]);
InAppStore::get_singleton()->_record_purchase(pid);
ret["type"] = "restore";
ret["result"] = "ok";
ret["transaction_id"] = transactionId;

NSData *receipt = nil;
int sdk_version = [[[UIDevice currentDevice] systemVersion] intValue];

NSBundle *bundle = [NSBundle mainBundle];
// Get the transaction receipt file path location in the app bundle.
NSURL *receiptFileURL = [bundle appStoreReceiptURL];

// Read in the contents of the transaction file.
receipt = [NSData dataWithContentsOfURL:receiptFileURL];

NSString *receipt_to_send = nil;

if (receipt != nil) {
receipt_to_send = [receipt base64EncodedStringWithOptions:0];
}
Dictionary receipt_ret;
receipt_ret["receipt"] = String::utf8(receipt_to_send != nil ? [receipt_to_send UTF8String] : "");
receipt_ret["sdk"] = sdk_version;
ret["receipt"] = receipt_ret;
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
} break;
case SKPaymentTransactionStatePurchasing: {
Expand Down