Purchasely
2.8
2.8
  • Welcome page
  • General
    • Presentation
  • Quick test
    • Test in 5 minutes
  • Basic configuration
    • Console Configuration
      • Creating a new application
      • Creating your Products
        • App Store
        • Play Store
        • Huawei App Gallery
        • Amazon App Store
        • Products & Plans
      • Design your Paywalls
    • SDK installation
      • iOS SDK
      • Android SDK
      • React Native SDK
      • Cordova SDK
    • SDK configuration
    • Webhook
      • Receiving and understanding messages
      • Managing entitlements
      • Subscription events
      • Events attributes
      • Detailed sequence diagrams
    • Observer mode
  • Dashboards
    • Introduction
    • Live
    • Subscriptions
    • Cohorts
    • Trials
    • Events
  • S2S notifications
    • Server-to-server notifications ?
    • App Store
    • Play Store
    • Huawei App Gallery
    • Amazon App Store
  • Integrations
    • Airship
    • Amplitude
    • Braze
    • Firebase
  • Advanced Features
    • Anonymous user
    • Associating content
    • Customising UI
      • Errors & alerts
      • Controllers (iOS) / Fragments (Android)
    • Deeplinks automations
    • Displaying users subscriptions
    • UI Analytics
    • Localization
    • Non-subscription products
    • Promoting your products
      • Self-promotion
      • Promoting In-App Purchases
    • Purchase interceptor
    • Purchase manually
    • Subscription status
    • Paywall Guidelines
  • Others
    • Frequently Asked Questions
    • Migration guides
      • Migrate to Purchasely
      • SDK
        • v2.1.3
        • v2.2.0
      • Webhooks
        • v3.0
  • TESTING
    • Testing Cycle Durations
Powered by GitBook

© Purchasely 2020-2023

On this page

Was this helpful?

  1. Advanced Features

Purchase interceptor

PreviousPromoting In-App PurchasesNextPurchase manually

Last updated 3 years ago

Was this helpful?

There are many possible cases where you would like to do something right before the user actually makes the purchase, right after he tapped the "Purchase button".

You might want to:

  • Ask the user to connect or create an account

  • Ask the user to acknowledge and accept the Terms of use

  • Make some specific backend check

  • Check that the content is available in the user geographical zone (media / videos)

Purchasely SDK gives you an opportunity to present or perform something to the user before it actually calls the stores to make the purchase. You can choose to continue the flow or cancel it.

// The handler gives you:
//  - the source controller to display something above
//  - a closure to notify the completion to the SDK that will proceed (or not) to the purchase

Purchasely.setConfimPurchaseHandler { [weak self](paywallController, processToPayment) in
	// Display the terms of use to your user
	self?.presentTermsAndConditions(above: paywallController) { (userAcceptedTerms) in
		// Don't forget to notify the SDK by calling `processToPayment`
		processToPayment(userAcceptedTerms)
	}
}
// The handler gives you:
//  - the source controller to display something above
//  - a closure to notify the completion to the SDK that will proceed (or not) to the purchase

[Purchasely setConfimPurchaseHandler:^(UIViewController *controller, void (^ processToPayment)(BOOL)) {
	// Display the terms of use to your user
	[self presentTermsAndConditionsAbove:controller handler:^(BOOL userAcceptedTerms) {
		// Don't forget to notify the SDK by calling `processToPayment`
		processToPayment(userAcceptedTerms);
	}];
}];
Purchasely.setConfirmPurchaseHandler { activity, processToPayment ->
        //if there is no activity then there is nothing to display
        if (activity == null) return@setConfirmPurchaseHandler
        
        //call your method to display your view 
        //and return boolean result to processToPayment
        presentTermsAndConditions(activity) { userAcceptedTerms ->
        		// Don't forget to notify the SDK by calling `processToPayment`
        		processToPayment(userAcceptedTerms)
        }
}
Purchasely.setConfirmPurchaseHandler((activity, listener) -> {
    //if there is no activity then there is nothing to display
    if (activity == null) return;

    /*  call your method to display your view
        and return boolean result to processToPayment
        listener.processToPayment(userAcceptedTerms);
     */
    presentTermsAndConditions(activity, listener);
});

//You can also use the method for kotlin with Function interface
Purchasely.setPurchaseCompletionCallback(() => {
    //Present your own screen before purchase
    console.log('Received callback from user tapped on purchase button');
    
    //Call this method to continue to payment flow when you close your screen
    Purchasely.processToPayment(true);
});
Purchasely.setConfirmPurchaseHandler(onPurchaseTapped => {
    //Present your own screen before purchase
    
    //Call this method to continue to payment flow when you close your screen
    Purchasely.processToPayment(true);
})

This parameter is set at the SDK level and not at the ViewController / Activity because these can be triggered automatically by a deeplink coming from a push, email, in-app message. If we had tied the handler to the activity you wouldn't have a chance to intercept the user before the purchase.

Setup your handler as soon as possible as you app might get opened by a deeplink linking to a paywall.

Example of this interceptor usage on The Explorers app