AptosPay is a streamlined NPM package designed to facilitate Aptos payment processing within your application. Key functionalities include shop initialization, order creation, payment status checks, and the ability to claim payments.
To install the AptosPay package, use the npm or yarn command:
npm install aptos-pay
yard add aptos-pay
Begin by importing the required functions and types:
import {
initShop,
createOrder,
getPaymentAddressByUid,
checkPaymentStatus,
claimPayments
} from 'aptos-pay';
function initShop(privateKey: string, moduleAddress: string): Promise<{ success: boolean; }>
- Initializes a shop.
- Returns a Promise with a success status.
function createOrder(amount: number, privateKey: string, moduleAddress: string): Promise<{ success: boolean; orderId: number; }>
- Creates a new order.
- Returns a Promise with a success status and an orderId
function getPaymentAddressByUid(orderId: string, storeOwnerAddress: string, moduleAddress: string)
- Retrieves payment address by order UID.
function checkPaymentStatus(orderId: string, storeOwnerAddress: string, moduleAddress: string): Promise<{ success: boolean; status: string; }>
- Checks the payment status for an order.
- Returns a Promise with a success status and a payment status (e.g., "COMPLETED").
function claimPayments(privateKey: string, moduleAddress: string): Promise<{ success: boolean; message: string; }>
- Claims all pending payments.
- Returns a Promise with a success status and a message.
Exports:
- `initShop`
- `createOrder`
- `getPaymentAddressByUid`
- `checkPaymentStatus`
- `claimPayments`
-
Ensure that you handle exceptions and errors adequately within your application. The provided functions do log the errors to the console, but it's recommended to implement a more robust error handling mechanism based on your specific needs.
-
Always keep your private keys secure and never expose them in client-side code.