-
Notifications
You must be signed in to change notification settings - Fork 292
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
Paywalls
: new .onPurchaseCancelled
and paywallViewControllerDidCancelPurchase:
#3578
Conversation
@@ -129,14 +147,34 @@ private struct OnPurchaseCompletedModifier: ViewModifier { | |||
func body(content: Content) -> some View { | |||
content | |||
.onPreferenceChange(PurchasedResultPreferenceKey.self) { result in | |||
if let result { | |||
if let result, !result.userCancelled { |
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.
This little important change is covered by a test.
@@ -41,7 +41,7 @@ class PurchaseCompletedHandlerTests: TestCase { | |||
.addToHierarchy() | |||
|
|||
Task { | |||
_ = try await Self.purchaseHandler.purchase(package: Self.package) | |||
_ = try await handler.purchase(package: Self.package) |
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.
This was wrong in the test, potentially leading to false positives.
@@ -38,6 +38,7 @@ class PurchaseHandlerTests: TestCase { | |||
_ = try await handler.purchase(package: TestData.packageWithIntroOffer) | |||
|
|||
expect(handler.purchaseResult?.customerInfo) === TestData.customerInfo | |||
expect(handler.purchaseResult?.userCancelled) == false |
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.
Small addition to this test.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3578 +/- ##
==========================================
- Coverage 86.09% 86.01% -0.08%
==========================================
Files 242 242
Lines 17629 17617 -12
==========================================
- Hits 15177 15154 -23
- Misses 2452 2463 +11 ☔ View full report in Codecov by Sentry. |
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.
Looks great!
@@ -144,6 +148,10 @@ public protocol PaywallViewControllerDelegate: AnyObject { | |||
didFinishPurchasingWith customerInfo: CustomerInfo, | |||
transaction: StoreTransaction?) | |||
|
|||
/// Notifies that a purchase has been cancelled in a ``PaywallViewController``. | |||
@objc(paywallViewControllerDidCancelPurchase:) | |||
optional func paywallViewControllerDidCancelPurchase(_ controller: PaywallViewController) |
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.
Can be done in a different PR but we could add another one for errors purchasing and another for errors restoring.
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.
Yup, I'll do that too.
@@ -206,10 +208,12 @@ struct PurchasedResultPreferenceKey: PreferenceKey { | |||
struct PurchaseResult: Equatable { | |||
var transaction: StoreTransaction? | |||
var customerInfo: CustomerInfo | |||
var userCancelled: Bool |
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.
So in case this is true, the result would contain the preexisting customerInfo correct?
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.
Yeah that's how the Purchases SDK works. But for the SwiftUI API I chose to not forward that.
self.delegate?.paywallViewController?(self, didFinishPurchasingWith: customerInfo) | ||
self.delegate?.paywallViewController?(self, | ||
didFinishPurchasingWith: customerInfo, | ||
transaction: transaction) | ||
} | ||
.onPurchaseCancelled { [weak self] in |
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.
FFTI. Should we add this modifier to paywall tester, even if it's just to log a message, so people looking at it for examples know it exists?
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.
👍🏻
…ancelPurchase:` This allows apps to be able to receive notifications when users cancel a purchase.
aadbbdc
to
bcbe6da
Compare
**This is an automatic release.** ### New Features * `StoreProduct`: add localized price per period strings (#3546) via Andy Boedo (@aboedo) ### RevenueCatUI * `Paywalls`: new `.onPurchaseCancelled` and `paywallViewControllerDidCancelPurchase:` (#3578) via NachoSoto (@NachoSoto) * `Paywalls`: improve error display (#3577) via NachoSoto (@NachoSoto) ### Dependency Updates * Bump fastlane-plugin-revenuecat_internal from `0ddee10` to `e6ba247` (#3575) via dependabot[bot] (@dependabot[bot]) ### Other Changes * `PurchaseTester`: improved `ReceiptInspector` so it accepts receipts with escape sequences (#3554) via Andy Boedo (@aboedo)
This allows apps to be able to receive notifications when users cancel a purchase.