Fix repeated paywall purchase cancellations#6826
Merged
Merged
Conversation
Co-authored-by: jacob.rakidzich <jacob.rakidzich@revenuecat.com>
Co-authored-by: jacob.rakidzich <jacob.rakidzich@revenuecat.com>
Comment on lines
12
to
892
| @@ -79,6 +80,11 @@ final class PurchaseHandler: ObservableObject { | |||
| @Published | |||
| fileprivate(set) var sessionPurchaseResult: PurchaseResultData? | |||
|
|
|||
| /// Unique identifier for the latest `sessionPurchaseResult`. | |||
| /// This allows SwiftUI preference listeners to receive consecutive identical results. | |||
| @Published | |||
| fileprivate(set) var sessionPurchaseResultID: UUID? | |||
|
|
|||
| /// Whether a purchase was successfully completed in the current session. | |||
| /// Convenience property for checking if we should skip exit offers. | |||
| var hasPurchasedInSession: Bool { | |||
| @@ -220,6 +226,7 @@ final class PurchaseHandler: ObservableObject { | |||
| self.paywallEventTracker.discardSession(sessionID: sessionID) | |||
| } | |||
| self.sessionPurchaseResult = nil | |||
| self.sessionPurchaseResultID = nil | |||
| self.purchaseResult = nil | |||
| self.activePaywallSessionID = nil | |||
| } | |||
| @@ -492,6 +499,7 @@ extension PurchaseHandler { | |||
| // onPurchaseCompleted and onPurchaseCancelled modifiers both work correctly. | |||
| withAnimation(Constants.defaultAnimation) { | |||
| self.sessionPurchaseResult = result | |||
| self.sessionPurchaseResultID = UUID() | |||
| } | |||
|
|
|||
| self.setResult(result) | |||
| @@ -555,6 +563,7 @@ extension PurchaseHandler { | |||
| // onPurchaseCompleted and onPurchaseCancelled modifiers both work correctly. | |||
| withAnimation(Constants.defaultAnimation) { | |||
| self.sessionPurchaseResult = resultInfo | |||
| self.sessionPurchaseResultID = UUID() | |||
| } | |||
|
|
|||
| self.setResult(resultInfo) | |||
| @@ -863,19 +872,21 @@ struct RestoreInProgressPreferenceKey: PreferenceKey { | |||
| struct PurchasedResultPreferenceKey: PreferenceKey { | |||
|
|
|||
| struct PurchaseResult: Equatable { | |||
| var id: UUID | |||
| var transaction: StoreTransaction? | |||
| var customerInfo: CustomerInfo | |||
| var userCancelled: Bool | |||
|
|
|||
| init(data: PurchaseResultData) { | |||
| init(data: PurchaseResultData, id: UUID) { | |||
| self.id = id | |||
| self.transaction = data.transaction | |||
| self.customerInfo = data.customerInfo | |||
| self.userCancelled = data.userCancelled | |||
| } | |||
|
|
|||
| init?(data: PurchaseResultData?) { | |||
| guard let data else { return nil } | |||
| self.init(data: data) | |||
| init?(data: PurchaseResultData?, id: UUID?) { | |||
| guard let data, let id else { return nil } | |||
| self.init(data: data, id: id) | |||
| } | |||
| } | |||
|
|
|||
Member
There was a problem hiding this comment.
out of scope, but should we just make all these let instead?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 515dd70. Configure here.
rickvdl
approved these changes
May 22, 2026
rickvdl
left a comment
Member
There was a problem hiding this comment.
Looks like a well scoped fix to me, good catch! One nit, LGTM!
| value: self.purchaseHandler.packageBeingPurchased) | ||
| .preference(key: PurchasedResultPreferenceKey.self, | ||
| value: .init(data: self.purchaseHandler.sessionPurchaseResult)) | ||
| value: .init( |
Member
There was a problem hiding this comment.
nit: we could create a helper init here to only take the purchaseHandler, in order to prevent drift between the two identical calls (this one and PaywallView.swift)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Checklist
purchases-androidand hybridsMotivation
If you cancel a paywall purchase by dismissing the payment sheet—you get the callback from
onPurchaseCancelledif you do it again… you don't.Description
Adds published ID that is set everytime the purchase session result is set, this way, if there is a duplicate value set, the view has what it needs to trigger the on canceled event