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

Implement hasReceipt method #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion InAppUtils/InAppUtils.m
Expand Up @@ -129,7 +129,7 @@ - (void)paymentQueue:(SKPaymentQueue *)queue
callback(@[@"restore_failed"]);
break;
}

[_callbacks removeObjectForKey:key];
} else {
RCTLogWarn(@"No callback registered for restore product request.");
Expand Down Expand Up @@ -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];
Expand Down
23 changes: 22 additions & 1 deletion Readme.md
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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:** Exists boolean flag.


### Can make payments

Check if in-app purchases are enabled/disabled.
Expand Down