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

Support refreshing receipts #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions InAppUtils/InAppUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,52 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
}
}

RCT_EXPORT_METHOD(refreshReceipt:(RCTResponseSenderBlock)callback)
{
[self refreshReceipt:callback testExpired:NO testRevoked:NO];
}

RCT_EXPORT_METHOD(testRefreshExpiredReceipt:(RCTResponseSenderBlock)callback)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of exposing three methods can you expose one with options object for expired and revoked?

something like :

refreshReceipt({ expired: true }, callback);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I can't figure out how to do this without also requiring an empty dictionary to be passed in when neither are required, which is the most common case. I am not sure if this is the best interface in that case. I would be possible to do if we also had a js layer that abstracted the objc layer but as it stands, I don't know how to do this in a clean way.

{
[self refreshReceipt:callback testExpired:YES testRevoked:NO];
}

RCT_EXPORT_METHOD(testRefreshRevokeReceipt:(RCTResponseSenderBlock)callback)
{
[self refreshReceipt:callback testExpired:NO testRevoked:YES];
}

- (void)refreshReceipt:(RCTResponseSenderBlock)callback
testExpired:(BOOL)testExpired
testRevoked:(BOOL)testRevoked
{
SKReceiptRefreshRequest *refreshRequest;
if (testExpired || testRevoked) {
NSDictionary *properties = @{
SKReceiptPropertyIsExpired:@(testExpired),
SKReceiptPropertyIsRevoked:@(testRevoked)
};
refreshRequest = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:properties];
} else {
refreshRequest = [[SKReceiptRefreshRequest alloc] init];
}
refreshRequest.delegate = self;
_callbacks[RCTKeyForInstance(refreshRequest)] = callback;
[refreshRequest start];
}

// SKProductsRequestDelegate protocol method

- (void)requestDidFinish:(SKRequest *)request
{
NSString *key = RCTKeyForInstance(request);
RCTResponseSenderBlock callback = _callbacks[key];
if (callback) {
callback(@[[NSNull null], @"finished"]);
[_callbacks removeObjectForKey:key];
}
}

- (void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
Expand Down