Skip to main content

Step 3. Enable purchase

Congratulations! You've successfully set up your paywall to display product data from Adapty, including the product title and price.

Now, let's move on to the final step – letting users make a purchase through the paywall.

Step 3.1. Enable users to make purchases

  1. Double-click the buy button on your paywall page. In the right panel, open the Actions section if it's not already open.

  2. Open the Action Flow Editor.

  1. In the Select Action Trigger window, choose On Tap.
  2. In the No Actions Created window, click Add Action. Search for the makePurchase action and choose it.
  1. In the Set Actions Arguments section, choose getPaywallProductsResult variable created earlier.
  2. Fill in the fields as follows:
    • Available Options: Data Structure Field
    • Select Field: value
    • Available Options: Item at Index
    • List Index Options: First
  1. Click subscriptionUpdateParameters, search for AdaptySubscriptionUpdateParameters and select it. Click Confirm.
    info

    By default, you can leave all the object fields empty. You would need to fill them in to replace one subscription with another in Android apps. Read more here.

  2. Click Confirm.
  3. In the Action Output Variable Name, create a new variable and name it makePurchaseResult - this will be used later to confirm the purchase was successful.

Step 3.2. Check if the purchase was successful

Now, let's set up a check to see if the purchase went through.

  1. Click + and click Add Conditional.
  2. In Set Condition for Action, select the makePurchaseResult variable.
  3. In the Set Variable window, fill in the fields as follows:
    • Available Options: Has Field
    • Select Field: profile
  1. Click Confirm.

Step 3.3. Open paid content

If the purchase is successful, you can unlock the paid content. Here’s how to set that up:

  1. Click + under the TRUE label and click Add Action.
  2. In the Define Action field, search for and select the page you want to open from the Navigate To list. In this example, the page is Questions.

Step 3.4 Show error message if purchase failed

If the purchase fails, let's display an alert to the user.

  1. Add an Informational Dialog action to the FALSE label.
  2. In the Title field, enter the text you want for the dialog title, such as Purchase Failed.
  1. Click Value in the Message box. In the Set from Variable window, search for makePurchaseResult and choose it. Fill in the fields as follows:

    • Available Options: Data Structure Field
    • Select Field: error
    • Available Options: Data Structure Field
    • Select Field: errorMessage
  2. Click Confirm.

  3. Add a Terminate action to the FALSE flow.

  1. Finally, click Close in the top-right corner.

Congratulations! Your users can now purchase your products. As an extra step, let's set up a check for user access to paid content elsewhere to decide whether to display paid content or the paywall to them.