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

Prevent unnecessary receipt posts #323

Merged
merged 6 commits into from
Aug 31, 2020

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Aug 27, 2020

https://app.clubhouse.io/revenuecat/story/70/ios-only-post-receipt-on-restore-if-there-are-transactions

Adds logic to check if a receipt has transactions, and if it doesn't, prevent an unnecessary post.
The one exception to the rule is if purchaserInfo is empty or it doesn't have an originalPurchaseDate, since that data is sometimes used to grandfather in subscribers.

Requirements:

  • Tests

…ransactions, used it to decide whether or not to post the receipt
@aboedo aboedo self-assigned this Aug 27, 2020
Comment on lines +31 to +36
@objc public func receiptHasTransactions(receiptData: Data) -> Bool {
if let receipt = try? parse(from: receiptData) {
return receipt.inAppPurchases.count > 0
}
// if the receipt can't be parsed, conservatively return true
return true
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a huge fan of returning a Bool here, since there are technically three possible cases:

  • true
  • false
  • unknown (receipt can't be parsed).

However, this isn't trivial to do in swift-objc interoperability:

  • you can either use a throws, which forces you to replace the Bool with NSNumber or an inout param, and the caller has to pass in an error, and then unwrap the NSNumber or pass in the inout param
  • encode the return into an object that basically wraps a Bool, then use that to encode the value.

They're not bad, but they did feel too complicated for what we're doing here.

More info: https://stackoverflow.com/a/36673027/5074358

Copy link
Member Author

Choose a reason for hiding this comment

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

if you're curious about what this would look like, I have a stash that I can upload into a branch for perspective

@@ -625,6 +630,15 @@ - (void)restoreTransactionsWithCompletionBlock:(nullable RCReceivePurchaserInfoB
CALL_IF_SET_ON_MAIN_THREAD(completion, nil, [RCPurchasesErrorUtils missingReceiptFileError]);
return;
}

RCPurchaserInfo * _Nullable cachedPurchaserInfo = [self readPurchaserInfoFromCache];
Copy link
Member Author

Choose a reason for hiding this comment

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

we'll move a lot of stuff out of this class eventually, but it's out-of-scope for this PR

Comment on lines -43 to +58
let objectIdentifier = objectIdentifierParser.build(fromPayload: internalContainer.internalPayload)
let objectIdentifier = objectIdentifierBuilder.build(fromPayload: internalContainer.internalPayload)
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated naming cleanup

@aboedo aboedo marked this pull request as ready for review August 28, 2020 14:46
@aboedo aboedo requested a review from vegaro August 28, 2020 18:43
@aboedo aboedo merged commit b6c8acb into develop Aug 31, 2020
@aboedo aboedo deleted the feature/prevent_unnecessary_receipt_posts branch August 31, 2020 20:18
@aboedo aboedo added this to the 3.7.0 milestone Sep 16, 2020
@aboedo aboedo mentioned this pull request Sep 16, 2020
@aboedo aboedo mentioned this pull request Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants