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

Support Redeeming Win-Back Offers with Streamlined Purchasing Disabled #4370

Conversation

fire-at-will
Copy link
Contributor

@fire-at-will fire-at-will commented Oct 10, 2024

This PR adds support for redeeming win-back offers with Streamlined Purchasing disabled.

Feature Availability

This feature is available for developers under the following conditions:

  • The app is run on:
    • iOS 18.0+
    • macOS 15.0+
  • The app is compiled with Xcode 16.0+

Implementation Details

Observing the SK1 Payment Queue

Apple has a note in their PurchaseIntent docs that reads:

Important

To enable promoted in-app purchases, your app must use either PurchaseIntent (starting in iOS 16.4) or paymentQueue(_:shouldAddStorePayment:for:) (starting in iOS 11). Don’t use both at the same time. If necessary, use conditional compilation to identify the OS version the app is running in. For more information, see Running code on a specific platform or OS version.

Of course, we can't perform conditional compilation based on the OS since version since that isn't known at compile time. Instead, this PR modifies the PaymentQueueWrapper class used when the SDK is running in SK2 mode so that it only observes the SK1 payment queue when the PurchaseIntents API is available (iOS >=16.4, macOS >=14.4, compiled on Xcode >=16.0).

API Changes

There are no breaking API changes with this PR. When we receive a Purchase Intent with a win-back offer attached to it, we call the PurchaseDelegate's readyForPromotedProduct() function, and when the developer is ready for the user to complete the win-back offer redemption flow, they call its completion handler.

OS/Feature Availability

PurchaseIntents were introduced in iOS 16.4, so we need to be careful about whether we use PurchaseIntents or SK1, depending on the runtime environment. Here's a full matrix of what features/technologies are available on each OS version:
Screenshot 2024-10-24 at 1 50 41 PM

Testing

  • ✅ I've been able to successfully manually test that the promoted purchase flow works with these changes with both SK1 & SK2.
  • ⚠️ Apple does not provide a way to test redeeming win-back offers with streamlined purchasing disabled, so this is currently untested.

@fire-at-will fire-at-will added pr:feat A new feature feat:Win-Back Offers Supporting iOS 18's Win-Back Offers labels Oct 10, 2024
@fire-at-will fire-at-will self-assigned this Oct 10, 2024
@fire-at-will fire-at-will changed the title [WIP DRAFT] CAT-1708: Support Redeeming Win-Back Offers with Streamlined Purchasing Disabled CAT-1708: Support Redeeming Win-Back Offers with Streamlined Purchasing Disabled Oct 24, 2024
/**
* Constructs an Error with the ``ErrorCode/invalidSubscriptionOffer`` code.
*/
static func invalidSubscriptionOfferError(
Copy link
Member

Choose a reason for hiding this comment

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

I'm probably missing something but I can't find where this error is used 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh. This was used in the purchase(sk2Product:winbackOffer:) function that we removed earlier in the review process. Good catch! 😄

I've removed this in 08ebe4f. We might want to bring back something similar when implementing win-backs into the purchase params, but we can cross that bridge when we get there 😄

@fire-at-will fire-at-will changed the title CAT-1708: Support Redeeming Win-Back Offers with Streamlined Purchasing Disabled Support Redeeming Win-Back Offers with Streamlined Purchasing Disabled Nov 5, 2024
// stop the compiler from checking availability in the functions.
// We also need to ensure that we're on Xcode >= 15.3, since that is when
// PurchaseIntents were first made available on macOS.
#if !os(tvOS) && !os(watchOS) && compiler(>=5.10)
Copy link
Member

Choose a reason for hiding this comment

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

Does it work if we add the availability to the function instead?

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will
Copy link
Contributor Author

@RCGitBot please test

@fire-at-will fire-at-will merged commit f638ae7 into main Nov 8, 2024
34 of 35 checks passed
@fire-at-will fire-at-will deleted the CAT-1708_purchase_winback_offer_with_streamlined_purchases_disabled branch November 8, 2024 16:44
This was referenced Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat:Win-Back Offers Supporting iOS 18's Win-Back Offers pr:feat A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants