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

Paywalls: new .onPurchaseCancelled and paywallViewControllerDidCancelPurchase: #3578

Merged
merged 2 commits into from
Jan 17, 2024

Conversation

NachoSoto
Copy link
Contributor

This allows apps to be able to receive notifications when users cancel a purchase.

@NachoSoto NachoSoto requested review from a team January 16, 2024 22:08
@@ -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 {
Copy link
Contributor Author

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)
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (56741f0) 86.09% compared to head (aadbbdc) 86.01%.

❗ Current head aadbbdc differs from pull request most recent head bcbe6da. Consider uploading reports for the commit bcbe6da to get more accurate results

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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tonidero tonidero left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@NachoSoto NachoSoto force-pushed the paywalls-on-purchase-cancelled branch from aadbbdc to bcbe6da Compare January 17, 2024 16:20
@NachoSoto NachoSoto enabled auto-merge (squash) January 17, 2024 16:20
@NachoSoto NachoSoto merged commit 0098ee8 into main Jan 17, 2024
24 checks passed
@NachoSoto NachoSoto deleted the paywalls-on-purchase-cancelled branch January 17, 2024 17:08
NachoSoto pushed a commit that referenced this pull request Jan 17, 2024
**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)
tonidero added a commit that referenced this pull request Feb 15, 2024
…fier (#3692)

### Description
We added purchase cancellation callbacks in #3578 but we didn't add them
to the `paywallFooter` modifier.

This adds them there so it's more convenient.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants