import { callApi } from "../index" import { GetBnplInfoRequest, GetBnplInfoResponse, GetOffersRequest, LodgeRequest, OfferType } from "../../types/common" import { getMarketApiUrl } from "../../config" import { camelize, decamelize } from "@credify/crypto" /** Send bnpl offer data */ export const postBnplInfo = async (offerData: OfferType): Promise => { console.log(`offerData`, offerData) const result = await callApi({ url: `${getMarketApiUrl()}/bnpl-consumer/create-order`, body: { ...offerData, }, method: "POST", }) return result } export const lodgeNewIntent = async ( marketName: string, lodgeRequest: LodgeRequest ): Promise => { console.log(`lodgeRequest`, lodgeRequest) const result = await callApi({ url: `${getMarketApiUrl()}/${marketName}/intents`, body: { ...decamelize(lodgeRequest), }, method: "POST", }) return result } /** Get demo user */ export const getDemoUser = async ( marketName: string, userId: string ): Promise => { const url = `${getMarketApiUrl()}/${marketName}/demo-user?id=${userId}` const result = await callApi({ url, method: "GET", }) return result } /** Get bnpl offer info */ export const getBNPLInfo = async ( marketName: string, token: string, data: GetBnplInfoRequest, ): Promise => { const url = `${getMarketApiUrl()}/${marketName}/offers-with-connected-providers` try { const result = await callApi({ url, method: "POST", body: { local_id: data.localId, phone_number: data.phoneNumber, country_code: data.countryCode, product_types: data.productTypes, credify_id: data.credifyId || undefined, }, }) return camelize(result) } catch (error) { console.log('error', error) } } /** Update user phone number */ export const updateUserProfile = async ( marketName: string, userId: string, data: { [key: string]: string } ) => { try { const url = `${getMarketApiUrl()}/${marketName}/demo-user/${userId}` const result = await callApi({ url, method: "PUT", body: { ...decamelize(data), }, }) return camelize(result) } catch (error) { console.log("error", error) } }