From 0c11c3920ce49bd63e14281f34a03abf9b08ac2b Mon Sep 17 00:00:00 2001 From: Francsico Vera Date: Thu, 5 Oct 2017 14:15:08 +0200 Subject: [PATCH 1/2] Implement hasReceipt method --- InAppUtils/InAppUtils.m | 9 ++++++++- Readme.md | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/InAppUtils/InAppUtils.m b/InAppUtils/InAppUtils.m index f382e75..23da39b 100644 --- a/InAppUtils/InAppUtils.m +++ b/InAppUtils/InAppUtils.m @@ -129,7 +129,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue callback(@[@"restore_failed"]); break; } - + [_callbacks removeObjectForKey:key]; } else { RCTLogWarn(@"No callback registered for restore product request."); @@ -204,6 +204,13 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue callback(@[@(canMakePayments)]); } +RCT_EXPORT_METHOD(hasReceipt:(RCTResponseSenderBlock)callback) +{ + NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL]; + BOOL hasReceipt = [[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]]; + callback(@[@(hasReceipt)]); +} + RCT_EXPORT_METHOD(receiptData:(RCTResponseSenderBlock)callback) { NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL]; diff --git a/Readme.md b/Readme.md index 46b5757..a1044f9 100644 --- a/Readme.md +++ b/Readme.md @@ -111,7 +111,7 @@ InAppUtils.restorePurchases((error, response) => { Alert.alert('itunes Error', 'Could not connect to itunes store.'); } else { Alert.alert('Restore Successful', 'Successfully restores all your purchases.'); - + if (response.length === 0) { Alert.alert('No Purchases', "We didn't find any purchases to restore."); return; @@ -148,6 +148,7 @@ iTunes receipts are associated to the users iTunes account and can be retrieved ```javascript InAppUtils.receiptData((error, receiptData)=> { if(error) { + // Could also advice the user to restore purchases Alert.alert('itunes Error', 'Receipt not found.'); } else { //send to validation server @@ -157,6 +158,26 @@ InAppUtils.receiptData((error, receiptData)=> { **Response:** The receipt as a base64 encoded string. + +### Checking if receipt exists + +You can limit user login prompts by checking if the receipt exists before trying to read it. +Useful if you don't want a prompt for new users + +```javascript +InAppUtils.hasReceipt((exists) => { + if(exists) { + // Continue with receipt validation before prompting for restoring + InAppUtils.receiptData((error, receiptData)=> { + //... + }) + } +}); +``` + +**Response:** The receipt as a base64 encoded string. + + ### Can make payments Check if in-app purchases are enabled/disabled. From ef194c5c7e1719782dca0b0e0191a12d07682272 Mon Sep 17 00:00:00 2001 From: Francsico Vera Date: Thu, 5 Oct 2017 14:27:04 +0200 Subject: [PATCH 2/2] Fix hasReceipt method Response in README --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index a1044f9..69de5f8 100644 --- a/Readme.md +++ b/Readme.md @@ -175,7 +175,7 @@ InAppUtils.hasReceipt((exists) => { }); ``` -**Response:** The receipt as a base64 encoded string. +**Response:** Exists boolean flag. ### Can make payments