CustomerCenterDelegate

Receive callbacks for Customer Center actions, restores, surveys, refunds, and dismissal.

Purpose

Pass a CustomerCenterDelegate to Superwall.instance.presentCustomerCenter() to observe or handle Customer Center interactions. All methods have default implementations and run on the main thread. The SDK retains the delegate only while the Customer Center is presented.

Signature

interface CustomerCenterDelegate {
    fun customerCenterShouldRestorePurchases(proceed: (Boolean) -> Unit) {
        proceed(true)
    }

    fun customerCenterDidSelectAction(
        action: CustomerCenterAction,
        pathId: String,
        purchase: CustomerCenterPurchase?
    ) {}

    fun customerCenterDidCompleteSurvey(
        surveyId: String,
        optionId: String,
        action: CustomerCenterAction,
        pathId: String
    ) {}

    fun customerCenterDidCompleteRefundRequest(
        productId: String,
        status: CustomerCenterRefundStatus
    ) {}

    fun customerCenterDidDismiss() {}
}

Callbacks

  • customerCenterShouldRestorePurchases(proceed) runs before a restore starts. Call proceed(true) to continue or proceed(false) to cancel. Call it exactly once; restoration waits for the decision and ignores later calls.
  • customerCenterDidSelectAction(action, pathId, purchase) runs when a path is selected, before its action. purchase is null for screen-level actions such as restore. Custom paths do not perform an app-specific action automatically; route them from this callback.
  • customerCenterDidCompleteSurvey(surveyId, optionId, action, pathId) reports the selected survey option.
  • customerCenterDidCompleteRefundRequest(productId, status) reports whether the refund request could be handed off. On Android, SUCCESS means Google Play was opened and ERROR means it could not be opened. USER_CANCELLED is not reported on Android because the SDK cannot observe when a customer leaves Google Play's page.
  • customerCenterDidDismiss() runs when the Customer Center is dismissed. You can also pass an onDismiss callback to presentCustomerCenter().

CustomerCenterAction identifies the selected built-in action (Restore, ManageSubscription, Refund, ChangePlan, or ContactSupport) or a Url or Custom action. CustomerCenterPurchase describes the purchase associated with a path, when there is one. Its entitlements may include entitlements the purchase no longer grants, so check each entitlement's isActive value before treating it as current.

Usage

val delegate = object : CustomerCenterDelegate {
    override fun customerCenterShouldRestorePurchases(proceed: (Boolean) -> Unit) {
        // For example, ask the customer to sign in before restoring.
        proceed(true)
    }

    override fun customerCenterDidSelectAction(
        action: CustomerCenterAction,
        pathId: String,
        purchase: CustomerCenterPurchase?
    ) {
        if (action is CustomerCenterAction.Custom) {
            openBillingSettings(action.identifier)
        }
    }

    override fun customerCenterDidCompleteSurvey(
        surveyId: String,
        optionId: String,
        action: CustomerCenterAction,
        pathId: String
    ) {
        analytics.track("customer_center_survey", mapOf("option_id" to optionId))
    }
}

Superwall.instance.presentCustomerCenter(delegate = delegate)

How is this guide?

On this page