Getting Started with Pre-Approvals
Get up and running with Pre-Approvals with our step-by-step guide.
This guide uses The official Drivly SDK and Next.js.
Prerequisites
Before diving into the integration process, ensure you have the following:
- Sign up for a Drivly account
- Create a DRIVLY_API_KEY.
- Basic understanding of TypeScript and REST APIs.
- A secure environment for handling sensitive data.
- Install the Drivly SDK
Overview
The concept of pre-approvals is to allow a user to get pre-approved for a loan before they start shopping for a car. This allows the user to know how much they can afford and what their interest rate will be. This is a great way to get users to commit to a purchase.
Robert Jones is looking to buy a new car. He wants to know how much he can afford and what his interest rate will be. He goes to the Drivly website and fills out a form to get pre-approved.
To complete this scenario, you will need to:
- Install Dependencies
- Create a Schema
- Setup the SDK
- Create a Pre-Approval
- (Bonus) Update a Pre-Approval
Install Dependencies
This guide uses some other dependencies along with the Drivly SDK. Let’s install those dependencies.
Create a Schema
Next, we will use Zod to create a schema for the Pre-Approval. This schema will be used to validate the form data before we send it to the server.
The states
is an array of all the states that are defined in the SDK’s exported interface PreApproval
. You will need to either create this array or cast the value of state
from string
to as PreApproval['state']
to ensure that value is valid for the SDK.
Setup the SDK
Let’s create a singleton instance of the SDK and export it for use in our application.
Create a Pre-Approval
Now that we have the schema and the SDK setup, we can create the form that will be used to collect the user’s information. We will use react-hook-form
to handle the form state and @hookform/resolvers
to use the Zod schema to validate the form data.
We will Server Actions for this example.
We also need a server action to handle the creation of the pre-approval. This action will use the SDK to create the pre-approval and return the pre-approval ID.
Update a Pre-Approval
If we need to update or add information to their pre-approval, we can use the updatePreApproval
action.
Conclusion
You have successfully created a form that will allow users to get pre-approved for a loan. You have also created a server action that will use the SDK to create the pre-approval. You can now use this form to get users pre-approved for a loan.
You can also use the updatePreApproval
action to update the pre-approval if more information is needed from the user (e.g. income
).
Robert Jones can now fill out the form and get pre-approved for a loan. He can then use the
preApprovalId
to associate himself with his pre-approval. This will allow you to show him cars
that he can afford and give him an idea of what his interest rate will be.
Next Steps
Ready to get started with Pre-Approvals? Check out the official Drivly SDK documentation to learn more.
Drivly SDK Documentation
Learn how to use the Drivly SDK to create Pre-Approvals.