-
Notifications
You must be signed in to change notification settings - Fork 316
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
Conversation
…transactions on the receipt
…ransactions, used it to decide whether or not to post the receipt
@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 |
There was a problem hiding this comment.
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 theBool
withNSNumber
or aninout
param, and the caller has to pass in an error, and then unwrap theNSNumber
or pass in theinout
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
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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
let objectIdentifier = objectIdentifierParser.build(fromPayload: internalContainer.internalPayload) | ||
let objectIdentifier = objectIdentifierBuilder.build(fromPayload: internalContainer.internalPayload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated naming cleanup
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 anoriginalPurchaseDate
, since that data is sometimes used to grandfather in subscribers.Requirements:
Tests