Skip to main content

Functions Documentation

This document provides an in-depth overview of the core functions available in the Mileston Payment Client SDK. Each function is designed to handle specific tasks related to payments, user management, and wallet operations.

fetchPayment

Fetches payment details from the server. This function is versatile and supports fetching details for invoices, payment links, and recurring payments.

Usage

import { fetchPayment } from "mileston-payment-client";

const paymentDetails = await fetchPayment({
apikey: "your-api-key", // Use your Checkout API Key here
businessid: "your-business-id",
paymentId: "payment-id",
paymentType: "invoice", // or "payment-link", "recurring"
});
console.log(paymentDetails);

Parameters

Parameter NameTypeDescription
apikeystringYour API key. This is required for authentication.
businessidstringYour business ID. This identifies your business in the system.
paymentIdstringThe ID of the payment to fetch. This is unique for each payment.
paymentTypestringThe type of payment. Supported values are:
- "invoice": For invoice payments.
- "payment-link": For payment link-based payments.
- "recurring": For recurring payments.

Returns

Return TypeDescription
Promise<object>A promise that resolves to the payment details. The structure of the response depends on the paymentType.

Notes

  • Ensure that the apikey and businessid are valid; otherwise, the request will fail.
  • Handle errors gracefully by wrapping the function call in a try-catch block.

getUserDetails

Fetches user details from the server. This function is useful for retrieving information about a specific user associated with your business.

Usage

import { getUserDetails } from "mileston-payment-client";

const userDetails = await getUserDetails("your-api-key", "business-id");
console.log(userDetails);

Parameters

Parameter NameTypeDescription
apikeystringYour API key. This is required for authentication.
businessIdstringThe business ID to include in the headers. This is mandatory.

Returns

Return TypeDescription
Promise<object>A promise that resolves to the user details. The response includes user-specific information such as name, email, and roles.

Notes

  • This function throws an error if the apikey or businessId is missing.
  • Use this function to verify user information before initiating sensitive operations.

MilestonPayButton

A class for creating and managing payment buttons. This class provides a customizable button that integrates seamlessly with the Mileston Payment system.

Usage

import { MilestonPayButton } from "mileston-payment-client";

const container = document.getElementById("payment-button-container");
const payButton = new MilestonPayButton(container, {
buttonText: "Pay Now",
onPaymentComplete: () => console.log("Payment complete!"),
onPaymentError: (error) => console.error("Payment error:", error),
});

Methods

Method NameParametersReturn TypeDescription
updateButtonTexttext: stringvoidUpdates the button's text. Use this to dynamically change the button label.
updateButtonStylestyles: Partial<CSSStyleDeclaration>voidUpdates the button's styles. This allows for custom styling.
destroyNonevoidRemoves the button from the DOM and cleans up event listeners.

Notes

  • The onPaymentComplete and onPaymentError callbacks are critical for handling payment events.
  • Ensure the container element exists in the DOM before initializing the button.

getOnRampData

Fetches onramp data for payments. This function is used to retrieve information required for initiating onramp transactions.

Usage

import { getOnRampData } from "mileston-payment-client";

const data = await getOnRampData(
{
amount: "100",
recipientWalletAddress: "0xRecipientAddress",
chain: "eth", //or "avax", "base", "pol", "arb"
},
"your-api-key",
"your-business-id"
);
console.log(data);

Parameters

Parameter NameTypeDescription
amountstringThe amount for the onramp.
recipientWalletAddressstringThe recipient's wallet address.
chainstringThe blockchain network (e.g., "eth").
apikeystringYour API key.
businessidstringYour business ID.

Returns

Return TypeDescription
Promise<object>A promise that resolves to the onramp data. The response includes details such as payment links and transaction metadata.

Notes

  • This function is essential for integrating onramp services into your application.
  • Validate the params object to ensure all required fields are provided.

getPaymentWallet

Manages wallet-related payment operations. This function retrieves information about a specific wallet type.

Usage

import { getPaymentWallet } from "mileston-payment-client";

const walletData = await getPaymentWallet({
apikey: "your-api-key",
businessid: "your-business-id",
walletType: "sui", //or "evm"
});
console.log(walletData);

Parameters

Parameter NameTypeDescription
apikeystringYour API key.
businessidstringYour business ID.
walletTypestringThe type of wallet.

Returns

Return TypeDescription
Promise<object>A promise that resolves to the wallet data. The response includes wallet-specific details such as balance and transaction history.

Notes

  • Use this function to verify wallet information before initiating transactions.
  • Handle errors gracefully to provide a better user experience.

savePayment

Saves payment details to the server. This function is used to store payment information for future reference or processing.

Usage

import { savePayment } from "mileston-payment-client";

const response = await savePayment({
apikey: "your-api-key",
businessid: "your-business-id",
type: "invoice", // or "payment-link", "recurring"
body: {
/* payment details */
},
nativeTokens: "optional-native-tokens",
});
console.log(response);

Parameters

Parameter NameTypeDescription
apikeystringYour API key.
businessidstringYour business ID.
typestringThe type of payment (e.g., "invoice", "payment-link", "recurring").
bodyobjectThe payment details.
nativeTokensstringNative tokens for the payment (optional).

Returns

Return TypeDescription
Promise<object>A promise that resolves to the server response. The response includes a confirmation of the saved payment.

Notes

  • Ensure the body object contains all required fields for the payment type.
  • This function is critical for storing payment data securely.

handlePayWithEVMWalletConnect

Handles payment transactions using EVM-compatible wallets via WalletConnect. This function supports both native tokens (e.g., AVAX, POL, ETH) and ERC-20 tokens (e.g., USDC, USDT).

Usage

import { handlePayWithEVMWalletConnect } from "mileston-payment-client";

const result = await handlePayWithEVMWalletConnect({
env: "prod",
evm: "eth",
recipientAddress: "0xRecipientAddress",
amount: "100",
token: "USDC",
});
console.log(result.txHash, result.payerAddress);

Parameters

Parameter NameTypeDescription
envstringThe environment (e.g., "test", "prod").
evmstringThe EVM chain identifier (e.g., "eth", "pol").
recipientAddressstringThe recipient's wallet address.
amountstringThe amount to send (in token units, not Wei).
tokenstringThe token type (e.g., "AVAX", "ETH", "USDC", "USDT").

Returns

Return TypeDescription
Promise<object>A promise that resolves with the transaction details, including txHash, feeHash, and payerAddress.

Example

const result = await handlePayWithEVMWalletConnect({
env: "prod",
evm: "eth",
recipientAddress: "0xRecipientAddress",
amount: "100",
token: "USDC",
});
console.log(result.txHash, result.payerAddress);