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 Fetching and Redeeming Win-Back Offers on Custom Paywall #366

Merged
merged 17 commits into from
Jan 13, 2025

Conversation

fire-at-will
Copy link
Contributor

@fire-at-will fire-at-will commented Dec 4, 2024

Description

This PR introduces four new functions to the Capacitor SDK that enables developers to fetch & redeem win-back offers on their custom paywalls. These functions are only supported on on iOS 18.0+ and require StoreKit 2 to be used.

Fetching eligible win-back offers

getEligibleWinBackOffersForProduct(
  options: GetEligibleWinBackOffersForProductOptions,
): Promise<{
  eligibleWinBackOffers: PurchasesWinBackOffer[]; 
}>;

getEligibleWinBackOffersForPackage(
  options: GetEligibleWinBackOffersForPackageOptions,
): Promise<{
  eligibleWinBackOffers: PurchasesWinBackOffer[];
}>;

Redeeming win-back offers

purchaseProductWithWinBackOffer(
  options: PurchaseProductWithWinBackOfferOptions,
 ): Promise<MakePurchaseResult | undefined>;

purchasePackageWithWinBackOffer(
  options: PurchasePackageWithWinBackOfferOptions,
): Promise<MakePurchaseResult | undefined>;

Each function throws an appropriate error if it is called on an unsupported platform, OS version, or StoreKit version.

Other Changes

The PurchaseTester app was updated with a new screen to support testing these flows

Testing

All flows were tested manually through the new screen in the PurchaseTester app.

@fire-at-will fire-at-will self-assigned this Dec 4, 2024
@@ -41,6 +41,29 @@ internal extension PurchasesPlugin {
return handleResponse
}

func getCompletionBlockHandlerForArrayResponse(
Copy link
Contributor Author

@fire-at-will fire-at-will Jan 10, 2025

Choose a reason for hiding this comment

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

The function signature for fetching eligible winback offers in PHC is:

static func eligibleWinBackOffers(
     for productIdentifier: String,
     completion: @escaping ([[String: Any]]?, ErrorContainer?) -> Void
 )

Note the [[String: Any]]? in the callback - it returns an array of objects. This function allows us to parse that response type, since the normal getCompletionBlockHandler assumes a return type of [String: Any]?

@fire-at-will fire-at-will changed the title [WIP] Support fetching/redeeming eligible win-backs Support Fetching and Redeeming Win-Back Offers on Custom Paywall Jan 10, 2025
@fire-at-will fire-at-will marked this pull request as ready for review January 10, 2025 23:19
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.

LGTM! Nicely done!

@PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
fun purchasePackageWithWinBackOffer(call: PluginCall) {
logNotSupportedFunctionalityInAndroid("purchasePackageWithWinBackOffer")
call.unavailable()
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm right, we probably should use unavailable for more methods 😅 (not for this PR!)

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.

Thanks for doing the change!

@fire-at-will fire-at-will merged commit ee2e61c into main Jan 13, 2025
5 checks passed
@fire-at-will fire-at-will deleted the support-fetching-and-redeeming-winbacks branch January 13, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants