Step 4. 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 4.1. Enable users make your purchase
- Double-click the buy button on your paywall page.
- In the right panel, open the Actions section if it's not already open.
- Open the Action Flow Editor.
- In the Select Action Trigger window, choose On Tap.
- In the No Actions Created window, click the Add Action button.
- In the Actions Flow Editor window, search for
makePurchase
custom action and choose it.
-
In the Set Actions Arguments section, choose
getPaywallProductsResult
variable created earlier. -
Fill in the fields as follows:
Parameter Value Available Options Data Structure Field Select Field value Available Options Item is Index List Index Options First -
Click the Confirm button.
-
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 4.2. Check if the purchase was successful
Now, let's set up a check to see if the purchase went through.
-
Click the plus (+) button and click Add Conditional.
-
In the Set Condition for Action section, select the
makePurchaseResult
variable. -
In the Set Variable window, fill in the fields as follows:
Parameter Value Available Options Has Field Select Field profile
- Click the Confirm button.
Step 4.3. Open paid content
If the purchase is successful, you can unlock the paid content. Here’s how to set that up:
- Click the plus (+) button under the TRUE label and click Add Action.
- In the Select Action field, search for and select the page you want to open from the Navigate To list. In this example, the page is YogaClessSession.
Step 4.4 Show error message if purchase failed
If the purchase fails, let's display an alert to the user.
- Add an Informational Dialog action to the FALSE label.
- In the Title field, enter the text you want for the dialog title, such as Purchase Failed.
- Click at the Value button of the Message box.
-
Fill in the fields as follows:
Parameter Value Set Variable makePurchaseResult
variable we've createdAvailable Options Data Structure Field Select Field error Available Options Data Structure Field Select Field errorMessage -
Click the Confirm button.
-
Add a Terminate action to the FALSE flow.
- Finally, click the Close button 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.