### Install FusionPay Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Commands to install the library using common package managers. ```bash # Using npm npm install fusionpay # Using yarn yarn add fusionpay # Using pnpm pnpm add fusionpay ``` -------------------------------- ### Initialize and Initiate Payment Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Basic setup for configuring payment details and redirecting the user to the gateway. ```typescript import { FusionPay } from "fusionpay"; // Initialize the payment client const payment = new FusionPay("https://api.moneyfusion.com"); // Configure the payment payment .totalPrice(1500) .addArticle("Premium Headphones", 1000) .addArticle("Extended Warranty", 500) .clientName("John Doe") .clientNumber("+123456789") .addInfo({ orderId: "ORD-12345", customerEmail: "john.doe@example.com", }) .returnUrl("https://your-store.com/return") .webhookUrl("https://your-store.com/webhook"); // Initiate payment try { const response = await payment.makePayment(); // Redirect user to payment gateway window.location.href = response.url; } catch (error) { console.error("Payment initiation failed:", error); } ``` -------------------------------- ### Handle Payment Callbacks Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Example implementation for verifying payment status via return URL or webhook in an Express application. ```typescript // Node.js Express example //In case you use returnUrl app.get("/return", async (req, res) => { const { token } = req.query; try { const payment = new FusionPay(process.env.FUSION_API_URL); const status = await payment.checkPaymentStatus(token as string); if (status.statut && status.data.statut === "paid") { // Payment successful const customData = status.data.personal_Info[0]; // Process order fulfillment... } else { // Payment failed or pending } } catch (error) { console.error("Payment verification failed:", error); res.status(500).send("Failed to verify payment"); } }); // In case you use webhook app.post("/webhook", async (req, res) => { // Handle webhook events const {...} = req.body; // Payment data from MoneyFusion(typeof PaymentVerificationData) //make your order fulfillment }); ``` -------------------------------- ### Git workflow commands for contributions Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Standard commands for creating a feature branch, committing changes, and pushing to the remote repository. ```bash git checkout -b feature/amazing-feature ``` ```bash git commit -m 'Add some amazing feature' ``` ```bash git push origin feature/amazing-feature ``` -------------------------------- ### FusionPay Client Configuration Methods Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Methods used to configure the payment request parameters before processing. ```APIDOC ## SDK Methods ### totalPrice(amount: number) - **Description**: Sets the total payment amount to be processed. - **Required**: Yes ### addArticle(name: string, value: number) - **Description**: Adds an individual item to the payment. At least one article is required. - **Required**: Yes ### clientName(name: string) - **Description**: Sets the customer's full name. - **Required**: Yes ### clientNumber(number: string) - **Description**: Sets the customer's phone number. - **Required**: Yes ### returnUrl(url: string) - **Description**: Sets the URL where the customer will be redirected after payment. - **Required**: No ### webhookUrl(url: string) - **Description**: Sets the URL for receiving server-to-server payment notifications. - **Required**: No ### addInfo(data: T) - **Description**: Adds custom data to store with the transaction. - **Required**: No ``` -------------------------------- ### PaymentResponse Source: https://github.com/yaya12085/fusionpay/blob/main/README.md The structure of the response received upon payment initiation. ```APIDOC ## PaymentResponse - **statut** (boolean) - Payment initiation status - **token** (string) - Token for payment verification - **message** (string) - Status message - **url** (string) - Payment gateway URL for user redirection ``` -------------------------------- ### PaymentVerificationResponse Source: https://github.com/yaya12085/fusionpay/blob/main/README.md The structure of the response received when verifying a payment. ```APIDOC ## PaymentVerificationResponse - **statut** (boolean) - Verification request status - **message** (string) - Status message - **data** (object) - Transaction details - **_id** (string) - Payment record ID - **tokenPay** (string) - Payment token - **numeroSend** (string) - Customer phone number - **nomclient** (string) - Customer name - **personal_Info** (T[]) - Custom data array - **numeroTransaction** (string) - Transaction reference - **Montant** (number) - Payment amount - **frais** (number) - Transaction fees - **statut** (string) - Payment status ("pending" | "paid" | "failed" | "no paid") - **moyen** (string) - Payment method used - **return_url** (string) - Callback URL - **createdAt** (string) - Transaction timestamp ``` -------------------------------- ### Define PaymentResponse Interface Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Interface representing the structure of the response received after initiating a payment. ```typescript interface PaymentResponse { statut: boolean; // Payment initiation status token: string; // Token for payment verification message: string; // Status message url: string; // Payment gateway URL for user redirection } ``` -------------------------------- ### Use Custom Data Types with Generics Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Define custom interfaces to ensure type safety when passing metadata to the payment client. ```typescript // Define your custom data type interface OrderData { orderId: string; customerEmail: string; productIds: string[]; } // Create a typed payment client const payment = new FusionPay("https://api.moneyfusion.com"); // Your custom data is now type-checked payment.addInfo({ orderId: "ORD-12345", customerEmail: "customer@example.com", productIds: ["PROD-001", "PROD-002"], }); ``` -------------------------------- ### Define PaymentVerificationResponse Interface Source: https://github.com/yaya12085/fusionpay/blob/main/README.md Interface representing the structure of the response received when verifying a payment status. ```typescript interface PaymentVerificationResponse { statut: boolean; // Verification request status message: string; // Status message data: { _id: string; // Payment record ID tokenPay: string; // Payment token numeroSend: string; // Customer phone number nomclient: string; // Customer name personal_Info: T[]; // Your custom data array numeroTransaction: string; // Transaction reference Montant: number; // Payment amount frais: number; // Transaction fees statut: "pending" | "paid" | "failed" | "no paid"; // Payment status moyen: string; // Payment method used return_url: string; // Callback URL createdAt: string; // Transaction timestamp }; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.