Building your own in-app discount codes for Stripe payments
Hey there, Tadabase users! It's Tim from Tadabase, and I'm excited to share a new video on how to build your own in-app discount codes for Stripe payments. In this video, we'll be using Tadabase to create this functionality and integrate it with your Stripe payment system.
The goal of this tutorial is to allow your end users to enter a discount code during checkout, check its validity, apply the discount if it's valid, and present the updated total for the purchase. If you need a refresher on how to build a Stripe payment application using Tadabase, you can find the link in the description or at the end of the video.
To achieve this goal, we'll need to use several features in Tadabase. We'll start by adding a new data table called "Discount Codes" to store the discount codes and their details. We'll set up fields for the discount code name, discount amount, and code status (active or inactive).
Next, we'll make some changes to the order table to accommodate the discount functionality. We'll add a text field for users to enter the discount code and a code status field to indicate if no code is entered, the code is invalid, or the code has been used. We'll also add fields for the subtotal, discount amount, amount saved, and final total.
The key part of this workflow involves using the Tadabase REST API pipe. We'll utilize this pipe to validate the discount code by making a request to the Discount Codes table and checking if the entered code exists and is active. If the code is valid, we'll retrieve the discount amount and apply it to the order.
To implement this, we'll set up a validation rule in the order form that triggers the REST API pipe. If the pipe returns no results, we'll display a message indicating that the code isn't available. If the code is valid, we'll use a record rule to save the discount amount and update the code status to "code used" on the order record.
Finally, we'll display the calculated values on the order detail component, including the discount code, amount saved, and final total. We'll also add an action link to allow users to remove the entered code if needed.
By following these instructions, you'll be able to create a seamless in-app discount code functionality for your Stripe payments using Tadabase. The REST API pipe allows you to validate codes from a separate data table and apply the appropriate discount to the order total.
I hope this tutorial has been helpful in expanding your Tadabase knowledge and enabling you to enhance your applications with discount code functionality. Feel free to watch the video for a more detailed walkthrough. Thank you for choosing Tadabase, and we'll see you in the next tutorial. Happy building!
Features Discussed:
-
Data Table (Time: 03:26)
Learn how to set up a data table for discount codes, including fields for the discount name, discount amount, and code status. For example, you'll learn how to create active and inactive discount codes and display discounts as percentages. -
Data Table (Time: 06:51)
Learn how to modify your order table to include discount code fields, subtotal, and final total calculations. For example, see how to calculate the discount amount and adjust the final order total based on the applied discount. -
Form Component (Time: 10:38)
Learn how to build a form that allows users to enter discount codes, validate them against active codes, and apply the discount to the order. For example, you'll see how to check if a code is active and calculate the amount saved. -
Tadabase Rest API (Time: 12:00)
Learn how to utilize Tadabase REST API pipes for filtering records based on two specific fields, such as verifying a discount code by both its name and status. This approach ensures you return accurate results, like active discount codes only. -
Validation Rule with Tadabase Rest API (Time: 16:24)
Learn to create validation rules that prevent invalid data entry, like blocking an inactive discount code. The system checks the validity of user inputs against the records before proceeding. -
Record Rules (Time: 18:00)
Learn how to trigger record rules that automatically update fields when a valid discount code is applied, ensuring correct discount amounts are applied and the status of the discount code is updated to "used." -
Action Link (Time: 20:28)
Learn to create action links that allow users to remove applied discount codes, ensuring flexibility and user control. The tutorial also covers dynamically displaying calculated values like discounts and final amounts.
Transcript Summary
Introduction
Hey everybody, it's Tadabase, and welcome back to Build It with Tadabase. In today's episode, we're revisiting the third video that I ever did for the Build It with Tadabase series. Way back, we built a Stripe payment system using the Stripe checkout module for a form component. Today, we're coming back to that particular video and app because we're going to build in a discount system. We're going to give the end user the ability to enter a discount code, check whether or not that code is valid, and if it's valid, we'll apply the discount and present the new total to the user for them to make a purchase. If you need a refresher on how to build that Stripe payment application, the link will be in the description and at the end of the video. So, no more talk—let's jump in and start building.
Overview of the Discount System
As an end result for what we're building today, we have this order form where we've created an order, added items to our order, and have a subtotal. We want to add a discount code, so I could enter in a discount code, and we're going to check whether or not that discount code exists and is valid. If it doesn't exist or isn't valid, nothing will happen. But if it is valid, we'll apply the discount saved on this particular discount code record. You’ll see that we saved 50% on our order, and the final amount left to pay is updated. We can then proceed to check out our order.
Updating the Data Structure
We don't have to make that many changes to our data structure. All we need to do is add another data table to track and store all of our discount codes and make a couple of changes to the actual order record so that we can apply a discount code to it.
The key part of this workflow is going to be the Tadabase REST API. If you've ever used validation rules before, you might notice that we don't have the ability to validate against something from another data table. We can only validate against the data source attached to the form component. However, you can add a pipe inside form validation rules, which allows us to validate anything we want, whether it lives inside or outside our application. In our case, we'll be using the Tadabase REST API pipe. We'll make a simple request to check whether a discount code matches by its name and ensure that it's active. If it does, we'll return the values needed to apply the correct discount.
Setting Up Discount Codes
We're going to add a new data table called "Discount Codes" and set up a few fields:
- Discount Code Name: The name of the discount code.
- Discount Amount: A number field to track the discount as a decimal value.
- Discount Percentage: A calculated field to show the percentage by multiplying the discount amount by 100.
- Code Status: A select field with options for "Active" and "Inactive" to manage the availability of discount codes.
For testing purposes, we'll create two discount codes:
- Wowza: 50% off and active.
- Big Time: 25% off and inactive.
Updating the Order Table
We also need to make some changes to our order table:
- Discount Code: A text field to store the discount code entered by the user.
- Code Status: To track whether no code has been entered, if the code is invalid, or if the code has been used.
- Subtotal: A calculated field summing the total values of connected order line items.
- Discount Amount: A number field to store the discount amount.
- Amount Saved: A calculated field showing how much was saved using the discount code.
- Final Total: A calculated field showing the final total after applying the discount.
Building the Application Page
We’ll jump to the Page Builder to set up the components and workflows:
- Order Details Page: We add a form component between the order details and order form, allowing users to edit the current order by entering a discount code.
- Validation Rule: We set up a validation rule using the Tadabase REST API pipe to check if the discount code exists and is active. If the discount code is not valid, an error message will be displayed.
- Record Rule: Once the validation is successful, a record rule will apply the discount code, save the discount amount to the order record, and update the code status to "Code Used."
Testing and Final Adjustments
We can now test the functionality by adding items to the order and entering a discount code. If the code is valid, it will apply the discount and update the final total.
Additionally, we add a feature to allow users to remove a discount code if they want to change or remove it.
Conclusion
Most of our time was spent discussing how to use the Tadabase REST API pipe inside validation and record rules. However, it's actually not as complicated as it might seem. The API pipe essentially sets up a filter to validate whether a discount code exists and is active, and then applies the discount accordingly.
We'd love to hear your feedback.