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

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


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

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