The Credit Application process enables users to secure auto loans, providing them with information on loan amounts and interest rates. This guide covers various scenarios, including applications for primary applicants and co-applicants, with or without trade-ins.
Now, we can export the sdk to use in our application
3
Make a function to CREATE the Credit Application.
credit.action.ts
'use server'// Next JS specific for server actionsimport{CreditApplication}from'@drivly/commerce'import{ sdk }from'./sdk'type CreditData=Omit<CreditApplication,'id'|'createdAt'|'updatedAt'>exportconstcreateCreditApp=async(data:CreditData)=>{try{// Change to 'Production' for live applicationsconst environment ='Development'const result =await sdk?.commerce.creditApplications.create({doc:{ environment,...data },})console.log(result)}catch(error){console.error(error)}}
4
We might need to CREATE a Trade, we will need a few more functions.
In cases where a trade-in is involved, we need to create a trade record for the vehicle being traded.
'use server'// Next JS specific for server actionsimport{ sdk }from'./sdk'import{ createLienholder, getLienholderId }from'./lienholder.action'import{CreateTradeParams}from'./shared.param.types'import{ createCommerceVehicle, getCommerceVehicleId }from'./vehicle.action'exportconstcreateTrade=(params:CreateTradeParams)=>{try{const{ data,id: creditApplication }= paramsconst{lienholder: companyName, payoff, odometer,...rest }= dataletlienholder: string |undefinedif(companyName){const prevLien =awaitgetLienholderId({ companyName }) lienholder = prevLien !=='Lienholder not found'? prevLien:awaitcreateLienholder({data:{ companyName }})}const prevVehicleId =awaitgetCommerceVehicleId(rest.vinas string)const vehicle = prevVehicleId !=='Vehicle not found'? prevVehicleId:awaitcreateCommerceVehicle({data: rest })if(vehicle ==='Failed to create vehicle')thrownewError(vehicle)if(lienholder ==='Lienholder not created')thrownewError(lienholder)const result =await sdk?.commerce.trades.create({doc:{ creditApplication,// Credit Application ID lienholder,// Lienholder ID odometer,tradeInPayoffBalance: payoff, vehicle,// Vehicle ID},depth:0,})if(!result)thrownewError('Trade not created')return result.doc.id}catch(error){console.error(error)}}
We can use https://commerce.driv.ly/api/creditApplications to create and manage Credit Applications.
1
Create an environment variable for your API Key.
.env
DRIVLY_API_KEY='YOUR_API_KEY'
2
Make a function to CREATE the Credit Application.
credit.action.ts
import{CreditApplication}from'@drivly/commerce'type CreditData=Omit<CreditApplication,'id'|'createdAt'|'updatedAt'>const url ='https://commerce.driv.ly/api/creditApplications'exportconstcreateCreditApp=async(data:CreditData)=>{try{// Change to 'Production' for live applicationsconst environment ='Development'const response =awaitfetch(url,{method:'POST',headers:{'Content-Type':'application/json',Authorization:`${process.env.DRIVLY_API_KEY}`,},body:JSON.stringify({ environment,...data }),}).then((res)=> res.json())console.log(response)}catch(error){console.error(error)}}
3
We might need to CREATE a Trade, we will need a few more functions.
In cases where a trade-in is involved, we need to create a trade record for the vehicle being traded.
import{ createLienholder, getLienholderId }from'./lienholder.action'import{CreateTradeParams}from'./shared.param.types'import{ createCommerceVehicle, getCommerceVehicleId }from'./vehicle.action'const url ='https://commerce.driv.ly/api/trades'exportconstcreateTrade=(params:CreateTradeParams)=>{try{const{ data,id: creditApplication }= paramsconst{lienholder: companyName, payoff, odometer,...rest }= dataletlienholder: string |undefinedif(companyName){const prevLien =awaitgetLienholderId({ companyName }) lienholder = prevLien !=='Lienholder not found'? prevLien:awaitcreateLienholder({data:{ companyName }})}const prevVehicleId =awaitgetCommerceVehicleId(rest.vinas string)const vehicle = prevVehicleId !=='Vehicle not found'? prevVehicleId:awaitcreateCommerceVehicle({data: rest })if(vehicle ==='Failed to create vehicle')thrownewError(vehicle)if(lienholder ==='Lienholder not created')thrownewError(lienholder)const response =awaitfetch(url,{method:'POST',headers:{'Content-Type':'application/json',Authorization:`${process.env.DRIVLY_API_KEY}`,},body:JSON.stringify({ creditApplication,// Credit Application ID lienholder,// Lienholder ID odometer,tradeInPayoffBalance: payoff, vehicle,// Vehicle ID}),}).then((res)=> res.json())if(!response?.doc)thrownewError('Trade not created')return response.doc.id}catch(error){console.error(error)}}
Danny found the car of his dreams. He wants to secure a loan to buy the car. He goes to your
website and fills out a form to find out how much of a loan he can secure.
When a user, such as Danny, wishes to secure a loan for his dream car, follow these steps:
1
Direct the user to the Credit Application Form on your Website.
Make sure the form includes fields for the primary applicant’s personal, residence, employment, and vehicle information.
Also include fields for the application type, finance amount, pre-approval ID and has
co-applicant.
Danny’s wife Michelle found a car she loves. They want to secure a loan to buy the car. They go to
your website and fill out a form to find out how much of a loan they can secure.
When both Danny and Michelle want to secure a loan for a car they love, their journey through your website will be slightly different to account for the additional information needed from the co-applicant. Here’s how to guide them:
1
Direct Both Applicants to the Credit Application Form.
Ensure your form is set up to handle input from both the primary applicant and the co-applicant. It’s crucial to clearly label which sections pertain to each applicant to avoid confusion.
Include identical fields for both the primary applicant and the co-applicant.
2
Collect and Format Data for Both Applicants.
While collecting the data, remember to gather information from both Danny and Michelle, treating Michelle’s data as the coApplicant’s or vice-versa. The data structure for the coApplicant will mirror that of the primaryApplicant.
For the relationshipType in the coApplicant’s data, select the appropriate option that describes
their relationship to the primary applicant.
Format Data
const creditData ={sendTo:'RouteOne',state:'DRAFT',environment:'Production',// Previous fields for primaryApplicantcoApplicant:{// Repeat the fields from primaryApplicant,// filling in Michelle's information},hasCoApplicant:true,// Other necessary fields (vehicle, applicationType, etc.)}
3
Send the Request.
Now that we have the data formatted, we can send the request to create the Credit Application.
Danny is looking to trade-in his 2011 Lincoln Town Car for a 2023 Genesis G80. He wants to secure
a loan to buy the car and trade-in his old car. He goes to your website and fills out a form to
find out how much of a loan he can secure.
In cases where Danny is looking to trade in his current vehicle as part of securing a new loan, the process involves an additional step to include trade-in information.
1
Guide Danny to the Enhanced Credit Application Form.
Adjust your form to include a section for vehicle trade-in details.
Danny and Michelle are looking to trade-in their 2011 Lincoln Town Car for a 2023 Genesis G80.
They want to secure a loan to buy the car and trade-in their old car. They go to your website and
fill out a form to find out how much of a loan they can secure.
For scenarios involving both a primary and a co-applicant intending to trade in a vehicle, combine the steps and considerations from the previous scenarios.
1
Guide Both Applicants to the Enhanced Credit Application Form.
Ensure your form includes sections for both applicants and trade-in details. Ensure clarity and ease of navigation within the form.
2
Collect Information Including Trade-In Details.
Gather information from both Danny and Michelle, including details about the vehicle they intend to trade.
3
Create a Trade.
Before sending the Credit Application, create a trade-in record for the vehicle Danny and Michelle intend to trade.
Congratulations! You’ve successfully integrated Credit Applications into your platform.
By following this guide, you’ve learned how to handle various scenarios, including primary applicants, co-applicants, and trade-ins. You’re now equipped to provide a seamless experience for users looking to secure auto loans.
If you have any questions or need further assistance, please don’t hesitate to reach out to our support team. Happy coding!