purchase

open suspend fun purchase(activity: Activity, product: StoreProduct, basePlanId: String?, offerId: String?): PurchaseResult(source)

Called when the user initiates purchasing of a product.

Add your purchase logic here and return its result. You can use Android's Billing APIs, or if you use RevenueCat, you can call Purchases.shared.purchase(product).

For Google Play products, the underlying ProductDetails are available via StoreProduct.rawStoreProduct's underlyingProductDetails.

Custom products: when StoreProduct.isCustomProduct is true, the product's metadata is sourced from the Superwall API rather than Google Play — route the purchase through your own payment system (e.g. Stripe, web checkout). The SDK does not grant entitlements for custom products: on a successful purchase you must update the user's entitlements yourself by calling Superwall.instance.setSubscriptionStatus(...). The product's StoreProduct.customTransactionId is pre-generated by the SDK and used as the original transaction identifier in analytics.

The default implementation routes Google Play products to the deprecated purchase(activity, productDetails, basePlanId, offerId) so existing implementations keep working, and fails for custom products.

Return

A PurchaseResult object, which is the result of your purchase logic. Note: Make sure you handle all cases of PurchaseResult.

Parameters

activity

The Activity from which the purchase was initiated.

product

The Superwall StoreProduct the user would like to purchase.

basePlanId

An optional base plan identifier of the product that's being purchased.

offerId

The identifier of the offer to buy, already chosen by the SDK from the paywall's product (including sw-auto resolution). null means buy the base plan with no offer: don't pick a free trial or other offer yourself.


open suspend fun purchase(activity: Activity, product: StoreProduct, basePlanId: String?, offerId: String?, replacement: ProductReplacement?): PurchaseResult(source)

Called when the user initiates purchasing of a product that should replace one of their existing subscriptions, e.g. an upgrade, downgrade or plan switch.

The SDK calls this instead of purchase(activity, product, basePlanId, offerId) for every purchase. replacement is non-null only when the paywall's Purchase action is set to replace an existing subscription and the user has an active subscription that shares an entitlement with product. For Google Play products, pass ProductReplacement.oldPurchaseToken and ProductReplacement.mode to the billing flow's SubscriptionUpdateParams (or the equivalent in your billing library, such as RevenueCat's oldProductId and googleReplacementMode).

The default implementation ignores replacement and calls purchase(activity, product, basePlanId, offerId), so existing implementations keep working.

Return

A PurchaseResult object, which is the result of your purchase logic.

Parameters

activity

The Activity from which the purchase was initiated.

product

The Superwall StoreProduct the user would like to purchase.

basePlanId

An optional base plan identifier of the product that's being purchased.

offerId

The identifier of the offer to buy, already chosen by the SDK from the paywall's product (including sw-auto resolution). null means buy the base plan with no offer: don't pick a free trial or other offer yourself.

replacement

The existing subscription this purchase replaces, if any.


open suspend fun purchase(activity: Activity, productDetails: ProductDetails, basePlanId: String?, offerId: String?): PurchaseResult(source)

Deprecated

Implement purchase(activity, product, basePlanId, offerId) instead. It receives a StoreProduct, which also supports custom store products.

Replace with

purchase(activity, product, basePlanId, offerId)

Called when the user initiates purchasing of a product.

Add your purchase logic here and return its result. You can use Android's Billing APIs, or if you use RevenueCat, you can call Purchases.shared.purchase(product).

Return

A PurchaseResult object, which is the result of your purchase logic. Note: Make sure you handle all cases of PurchaseResult.

Parameters

productDetails

The ProductDetails the user would like to purchase.

basePlanId

An optional base plan identifier of the product that's being purchased.

offerId

The identifier of the offer to buy, already chosen by the SDK from the paywall's product (including sw-auto resolution). null means buy the base plan with no offer: don't pick a free trial or other offer yourself.