Created
June 21, 2025 06:06
-
-
Save yousuf-hossain-shanto/0b351fdd8ac0783197a99bd64524aba4 to your computer and use it in GitHub Desktop.
WithPersona KYC Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import axios, { AxiosError } from "axios"; | |
| const $withPersona = axios.create({ | |
| baseURL: "https://withpersona.com/api/v1", | |
| }); | |
| $withPersona.defaults.headers.common[ | |
| "Authorization" | |
| ] = `Bearer ${process.env.WITHPERSONA_API_KEY}`; | |
| $withPersona.defaults.headers.common["Persona-Version"] = `2023-01-05`; | |
| $withPersona.defaults.headers.common["Content-Type"] = "application/json"; | |
| $withPersona.defaults.headers.common["Accept"] = "application/json"; | |
| export type WithPersonaError = AxiosError<{ | |
| errors: Array<{ | |
| title: string; | |
| details: string; | |
| }>; | |
| }>; | |
| export const isWithPersonaError = (error: any): error is WithPersonaError => { | |
| return axios.isAxiosError(error); | |
| }; | |
| export type WithPersonaAccount = { | |
| type: "account", | |
| id: string; | |
| }; | |
| export type WithPersonaInquiry = { | |
| type: "inquiry", | |
| id: string; | |
| attributes: { | |
| status: "created" | "pending" | "completed" | "expired" | "needs_review" | "failed" | "approved" | "declined"; | |
| "reviewer-comment": string | null; | |
| } | |
| } | |
| export type WithPersonaEvent = { | |
| type: "event", | |
| id: string; | |
| attributes: { | |
| name: "inquiry.completed" | "inquiry.failed" | "inquiry.approved" | "inquiry.declined"; | |
| payload: { | |
| data: WithPersonaInquiry; | |
| } | |
| } | |
| } | |
| export const createWithPersonaAccount = async (refId: string) => { | |
| const response = await $withPersona.post<{ | |
| data: WithPersonaAccount; | |
| }>("/accounts", { | |
| data: { | |
| attributes: { | |
| "reference-id": refId, | |
| }, | |
| }, | |
| }); | |
| return response.data.data.id; | |
| }; | |
| export const createWithPersonaInquiry = async (config: {accountId: string, redirectUrl?: string, fields?: Record<"crypto_wallet_address", string>}) => { | |
| const response = await $withPersona.post<{ | |
| data: WithPersonaInquiry; | |
| }>("/inquiries", { | |
| data: { | |
| attributes: { | |
| "inquiry-template-id": process.env.WITHPERSONA_INQUIRY_TEMPLATE_ID, | |
| "account-id": config.accountId, | |
| "redirect-uri": config.redirectUrl??null, | |
| "fields": config.fields??null, | |
| }, | |
| }, | |
| }); | |
| return response.data.data; | |
| } | |
| export const getWithPersonaInquiry = async (inquiryId: string) => { | |
| const response = await $withPersona.get<{ | |
| data: WithPersonaInquiry; | |
| }>(`/inquiries/${inquiryId}`); | |
| return response.data.data; | |
| } | |
| export const createWithPersonaInquiryOTL = async (inquiryId: string) => { | |
| const response = await $withPersona.post<{ | |
| data: WithPersonaInquiry; | |
| meta: { | |
| "one-time-link": string; | |
| "one-time-link-short": string; | |
| } | |
| }>(`/inquiries/${inquiryId}/generate-one-time-link`) | |
| return response.data.meta["one-time-link"]; | |
| } | |
| export const withPersonaHandler = $withPersona |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment