import MtnAPISoftVerifyParams from '../interfaces/MtnAPISoftVerifyParams'; import TokenInfo from '../objects/TokenInfo.object'; import TokenTypes from '../enums/TokenTypes'; import MtnAPIPayParams from '../interfaces/MtnAPIPayParams'; import MtnAPIVerifyParams from '../interfaces/MtnAPIVerifyParams'; const API_URL = 'https://api.mtnapi.com'; // const API_URL = 'https://magically-production.ngrok.io'; const createPaymentLink = (params: MtnAPIPayParams, ref: string): string | null => { let link: string | null = null; if (params.link) { link = params.link; } else { link = `${API_URL}/pay?wallet=${params.wallet}&payerToken=${params.payerToken}&ref=${ref}`; if (params.quantity) { link += `&quantity=${params.quantity}`; } else { link += `&size=${params.size}`; } } return link; }; const createVerificationLink = (params: MtnAPIVerifyParams, ref: string): string | null => { let link: string = `${API_URL}/verify?ref=${ref}`; if (params.collection) { link += `&collection=${params.collection}`; } else if (params.list) { link += `&list=${params.list}`; } return link; }; const createSoftVerificationLink = (params: MtnAPISoftVerifyParams): string | null => { let link: string = `${API_URL}/soft-verify?account=${params.account}`; if (params.collection) { link += `&collection=${params.collection}`; } else if (params.list) { link += `&list=${params.list}`; } return link; }; const createPollingLink = (ref: string): string | null => { return `${API_URL}/status?ref=${ref}`; }; const paymentAmountFromPayParams = (params: MtnAPIPayParams): number | null => { return params.quantity ? PayUtil.convertQuantityToSize( params.quantity, params?.payerToken?.toUpperCase() as TokenTypes, ) : params.size ?? null; }; const convertSizeToQuantity = (size: number, tokenType: TokenTypes): number | null => { const tokenInfo: any = TokenInfo[tokenType?.toUpperCase()]; if (!tokenInfo) return null; return size * (10 ** tokenInfo.decimals); }; const convertQuantityToSize = (quantity: number, tokenType: TokenTypes): number | null => { const tokenInfo: any = TokenInfo[tokenType?.toUpperCase()]; if (!tokenInfo) return null; return quantity / (10 ** tokenInfo.decimals); }; const PayUtil = { createPaymentLink, createVerificationLink, createSoftVerificationLink, createPollingLink, paymentAmountFromPayParams, convertSizeToQuantity, convertQuantityToSize, }; export default PayUtil;