### Installation Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Install the Paydunya Node.js library using npm. ```APIDOC ## Installation ```javascript npm install --save paydunya ``` ``` -------------------------------- ### Install Paydunya Node.js Client Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Install the Paydunya Node.js library using npm. This is the first step to integrating Paydunya into your project. ```javascript npm install --save paydunya ``` -------------------------------- ### Initialize Onsite Invoice Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Create a new Onsite Invoice instance by passing the setup and store configuration objects. ```javascript var invoice = new paydunya.OnsiteInvoice(setup, store); ``` -------------------------------- ### Initialize Checkout Invoice Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Create a new Checkout Invoice instance by passing the setup and store configuration objects. ```javascript var invoice = new paydunya.CheckoutInvoice(setup, store); ``` -------------------------------- ### Install Mocha for Running Tests Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Install the Mocha testing framework globally using npm. An internet connection is required for some tests. ```bash npm install -g mocha ``` -------------------------------- ### Initialize Onsite Invoice Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Initialize a new Onsite Invoice object with the setup and store configurations. ```APIDOC ## Initialize Onsite Invoice ```javascript var invoice = new paydunya.OnsiteInvoice(setup, store); ``` ``` -------------------------------- ### Initialize Checkout Invoice Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Initialize a new Checkout Invoice object with the setup and store configurations. ```APIDOC ## Initialize Checkout Invoice ```javascript var invoice = new paydunya.CheckoutInvoice(setup, store); ``` ``` -------------------------------- ### Create Checkout Invoice Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Generate a checkout invoice and retrieve the hosted payment URL. The process involves configuring setup and store objects, adding items, taxes, and custom data before calling the create method. ```javascript var paydunya = require('paydunya'); var setup = new paydunya.Setup({ masterKey: 'your-master-key', privateKey: 'your-private-key', token: 'your-token', mode: 'test' }); var store = new paydunya.Store({ name: 'My Store', returnURL: 'http://mystore.com/payment/success', cancelURL: 'http://mystore.com/payment/cancel' }); var invoice = new paydunya.CheckoutInvoice(setup, store); // Add items to invoice invoice.addItem('Ordinateur Lenovo L440', 1, 400000, 400000); invoice.addItem('Souris sans fil', 2, 5000, 10000); invoice.description = 'Purchase from My Store'; // Add taxes (optional) invoice.addTax('VAT (18%)', 73800); invoice.addTax('Service Fee', 1000); // Add custom data for your records (optional) invoice.addCustomData('OrderID', 'ORD-12345'); invoice.addCustomData('CustomerID', 'CUST-789'); // Set total amount invoice.totalAmount = 484800; // Create the checkout invoice.create() .then(function() { console.log('Status:', invoice.status); // 'pending' console.log('Invoice Token:', invoice.token); // 'abcd1234xyz' console.log('Checkout URL:', invoice.url); // 'https://app.paydunya.com/...' // Redirect customer to invoice.url }) .catch(function(error) { console.error('Error:', error.message); if (error.data) console.error('API Response:', error.data); }); ``` -------------------------------- ### API Configuration Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Set up your Paydunya API keys. You can either pass them directly during initialization or rely on environment variables. ```APIDOC ## API configuration Setup paydunya API keys. ```javascript var setup = new paydunya.Setup({ masterKey: 'wQzk9ZwR-Qq9m-0hD0-zpud-je5coGC3FHKW', privateKey: 'test_private_rMIdJM3PLLhLjyArx9tF3VURAF5', publicKey: 'test_public_kb9Wo0Qpn8vNWMvMZOwwpvuTUja-OSDNhUqKoaTI4wc', token: 'IivOiOxGJuWhc5znlIiK', mode: 'test' // optional. use in sandbox mode. }); ``` It might usually be suitable to put your API configuration in environment variables. In that case you can initialize `paydunya.Setup` without passing configuration parameters. The library will automatically detect the environment variables and use them. Auto-detected environment variables: `PAYDUNYA_MASTER_KEY`, `PAYDUNYA_PRIVATE_KEY`, `PAYDUNYA_PUBLIC_KEY`, `PAYDUNYA_TOKEN` ``` -------------------------------- ### Initialize Checkout Store Configuration Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Configure your store details, including name, tagline, phone number, postal address, and logo URL. The store name is the only required field. ```javascript var store = new paydunya.Store({ name: 'Magasin Chez Sandra', // only name is required tagline: "L'élégance n'a pas de prix", phoneNumber: '336530583', postalAddress: 'Dakar Plateau - Etablissement kheweul', logoURL: 'http://www.chez-sandra.sn/logo.png' }); ``` -------------------------------- ### Configure PAYDUNYA API Client Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Initialize the API client using merchant credentials. Credentials can be provided explicitly or loaded automatically from environment variables. ```javascript var paydunya = require('paydunya'); // Direct configuration var setup = new paydunya.Setup({ masterKey: 'wQzk9ZwR-Qq9m-0hD0-zpud-je5coGC3FHKW', privateKey: 'test_private_rMIdJM3PLLhLjyArx9tF3VURAF5', publicKey: 'test_public_kb9Wo0Qpn8vNWMvMZOwwpvuTUja-OSDNhUqKoaTI4wc', token: 'IivOiOxGJuWhc5znlIiK', mode: 'test' // Use 'test' for sandbox, omit for production }); // Or use environment variables (auto-detected) // PAYDUNYA_MASTER_KEY, PAYDUNYA_PRIVATE_KEY, PAYDUNYA_PUBLIC_KEY, PAYDUNYA_TOKEN var setupFromEnv = new paydunya.Setup(); ``` -------------------------------- ### Configure Paydunya API Keys Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Set up your Paydunya API credentials including master key, private key, public key, and token. The mode can be set to 'test' for sandbox environments. ```javascript var setup = new paydunya.Setup({ masterKey: 'wQzk9ZwR-Qq9m-0hD0-zpud-je5coGC3FHKW', privateKey: 'test_private_rMIdJM3PLLhLjyArx9tF3VURAF5', publicKey: 'test_public_kb9Wo0Qpn8vNWMvMZOwwpvuTUja-OSDNhUqKoaTI4wc', token: 'IivOiOxGJuWhc5znlIiK', mode: 'test' // optional. use in sandbox mode. }); ``` -------------------------------- ### Create Onsite Payment Request (Step 1) Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Initiates an OPR by creating an invoice and triggering a confirmation code to the customer's PayDunya account. The resulting OPR token is required for the final charge step. ```javascript var paydunya = require('paydunya'); var setup = new paydunya.Setup({ masterKey: 'your-master-key', privateKey: 'your-private-key', token: 'your-token', mode: 'test' }); var store = new paydunya.Store({ name: 'My Store', callbackURL: 'http://mystore.com/webhook' }); var invoice = new paydunya.OnsiteInvoice(setup, store); // Add items invoice.addItem('Premium Subscription', 1, 25000, 25000); invoice.description = 'Monthly subscription renewal'; // Add custom data invoice.addCustomData('SubscriptionID', 'SUB-456'); invoice.addCustomData('Plan', 'Premium'); // Set total amount invoice.totalAmount = 25000; // Create OPR with customer's PAYDUNYA email or phone invoice.create('alioune@gmail.com') .then(function() { console.log('OPR Token:', invoice.oprToken); // Save this for Step 2 console.log('Invoice Token:', invoice.token); console.log('Response:', invoice.responseText); // Customer receives a confirmation code via SMS/email // Proceed to Step 2 with oprToken and the confirmation code }) .catch(function(error) { console.error('OPR creation failed:', error.message); if (error.data) console.error('API Response:', error.data); }); ``` -------------------------------- ### POST /onsite/create Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Initiates an Onsite Payment Request (OPR) by creating an invoice and sending a confirmation code to the customer's PayDunya account. ```APIDOC ## POST /onsite/create ### Description Step 1 of the Onsite Payment process. Creates an invoice and triggers a confirmation code sent to the customer's PayDunya account via SMS or email. ### Parameters #### Request Body - **customerAccount** (string) - Required - The customer's PayDunya email or phone number. - **items** (array) - Required - List of items being purchased. - **totalAmount** (number) - Required - The total amount to be charged. ### Response #### Success Response (200) - **oprToken** (string) - The OPR token required for the charge step. - **token** (string) - The invoice token. ``` -------------------------------- ### Onsite Payment Request (OPR) - Step 1: Token Request Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Initiate an Onsite Payment Request by providing the customer's email. This step generates an OPR token required for the next step. ```javascript invoice.create('alioune@gmail.com') .then(function(){ invoice.oprToken; // You need to pass the OPR Token on Step 2 invoice.token; // invoice token invoice.responseText; }) .catch(function (e) { console.log(e); }); ``` -------------------------------- ### Onsite Payment Request (OPR): Step 1 - Token Request Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Initiate an Onsite Payment Request by providing the customer's email or phone number. This step generates an OPR token required for the next step. ```APIDOC ## Onsite Payment Request (OPR): Step 1 - Token request After setting total amount and adding items to your invoice get the paydunya customer's username or phone number and start an OPR request. ```javascript invoice.create('alioune@gmail.com') .then(function(){ invoice.oprToken; // You need to pass the OPR Token on Step 2 invoice.token; // invoice token invoice.responseText; }) .catch(function (e) { console.log(e); }); ``` ``` -------------------------------- ### Onsite Payment Request (OPR) - Step 2: Charge Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Complete the OPR charge by providing the OPR token and the confirmation code sent to the customer. After a successful charge, you can access the receipt URL, customer information, and more. ```javascript invoice.charge('oprToken', '0000') .then(function (){ invoice.status; invoice.responseText; invoice.receiptURL; invoice.customer; // {name: 'Alioune Badara', phone: '773830279', email: 'alioune@gmail.com'} }) .catch(function (e) { console.log(e); }); ``` -------------------------------- ### Configure CheckoutInvoice items and taxes Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Build an invoice by adding line items, taxes, custom metadata, and payment channels. The totalAmount property is mandatory before calling the create method. ```javascript var paydunya = require('paydunya'); var setup = new paydunya.Setup({ masterKey: 'your-master-key', privateKey: 'your-private-key', token: 'your-token', mode: 'test' }); var store = new paydunya.Store({ name: 'My Store' }); var invoice = new paydunya.CheckoutInvoice(setup, store); // Add items: name, quantity, unit price, total price, description (optional) invoice.addItem('Laptop', 1, 500000, 500000, 'Dell XPS 15'); invoice.addItem('Mouse', 2, 10000, 20000); invoice.addItem('Keyboard', 1, 25000, 25000, 'Mechanical RGB'); // Set invoice description invoice.description = 'Computer accessories order'; // Add taxes invoice.addTax('VAT (18%)', 98100); invoice.addTax('Eco Tax', 500); // Add custom data (not shown on checkout, stored for your reference) invoice.addCustomData('OrderID', 'ORD-2024-001'); invoice.addCustomData('CustomerEmail', 'customer@example.com'); invoice.addCustomData('ShippingMethod', 'Express'); // Restrict payment to specific channels (optional) invoice.addChannel('mtn-benin'); invoice.addChannel('moov-benin'); // Or add multiple channels at once invoice.addChannels(['mtn-benin', 'moov-benin', 'visa']); // Set URLs per invoice (overrides store defaults) invoice.returnURL = 'http://mystore.com/order/ORD-2024-001/success'; invoice.cancelURL = 'http://mystore.com/order/ORD-2024-001/cancel'; invoice.callbackURL = 'http://mystore.com/webhook/paydunya'; // Set total amount (required) invoice.totalAmount = 643600; // Create the invoice invoice.create() .then(function() { console.log('Checkout URL:', invoice.url); }) .catch(function(error) { console.error('Error:', error.message); }); ``` -------------------------------- ### Onsite Payment Request (OPR): Step 2 - Charge Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Complete the onsite payment charge by providing the OPR token obtained in Step 1 and the confirmation code sent to the customer. Upon success, you can access receipt details and customer information. ```APIDOC ## Onsite Payment Request (OPR): Step 2 - Charge To successfully complete an OPR charge, you need both your OPR Token & the Confirmation code sent to the customer. After a successfull charge you can programatically access the receipt url, customer information and more. ```javascript invoice.charge('oprToken', '0000') .then(function (){ invoice.status; invoice.responseText; invoice.receiptURL; invoice.customer; // {name: 'Alioune Badara', phone: '773830279', email: 'alioune@gmail.com'} }) .catch(function (e) { console.log(e); }); ``` ``` -------------------------------- ### POST /onsite/charge Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Completes the onsite payment by charging the customer's account using the OPR token and the confirmation code. ```APIDOC ## POST /onsite/charge ### Description Step 2 of the Onsite Payment process. Finalizes the transaction using the OPR token and the confirmation code provided by the customer. ### Parameters #### Request Body - **oprToken** (string) - Required - The token received from the create step. - **confirmationCode** (string) - Required - The code received by the customer via SMS/email. ### Response #### Success Response (200) - **status** (string) - The final status of the transaction. - **receiptURL** (string) - URL to the transaction receipt. - **customer** (object) - Details of the customer charged. ``` -------------------------------- ### Charge Onsite Payment Account (Step 2) Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Completes the payment process using the OPR token and the confirmation code provided by the customer. This finalizes the transaction and returns receipt details. ```javascript var paydunya = require('paydunya'); var setup = new paydunya.Setup({ masterKey: 'your-master-key', privateKey: 'your-private-key', token: 'your-token', mode: 'test' }); var store = new paydunya.Store({ name: 'My Store' }); var invoice = new paydunya.OnsiteInvoice(setup, store); // OPR token from Step 1 var oprToken = 'opr_token_from_step_1'; // Confirmation code entered by customer (received via SMS/email) var confirmationCode = '5241'; invoice.charge(oprToken, confirmationCode) .then(function() { console.log('Status:', invoice.status); // 'completed' console.log('Response:', invoice.responseText); console.log('Receipt URL:', invoice.receiptURL); console.log('Customer:', invoice.customer); // { name: 'Alioune Badara', phone: '773830279', email: 'alioune@gmail.com' } // Payment successful - fulfill the order }) .catch(function(error) { console.error('Charge failed:', error.message); if (error.data) console.error('API Response:', error.data); // Invalid OPR token or confirmation code }); ``` -------------------------------- ### Create Checkout and Redirect Customer Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Create a checkout invoice and obtain the Paydunya redirect URL. This method is called after setting the total amount and adding items. The callback receives the updated invoice object containing the URL. ```javascript invoice.create() .then(function (){ invoice.status; invoice.token; // invoice token invoice.responseText; invoice.url; // PAYDUNYA redirect checkout url }) .catch(function (e) { console.log(e); }); ``` -------------------------------- ### Add Invoice Items and Description Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Add items to the invoice, specifying the name, quantity, unit price, and total price for each item. You can also set a general description for the invoice. ```javascript invoice.addItem('Ordinateur Lenovo L440', 1, 400000, 400000); // name, quantity, unit price, total price invoice.description = 'Lenovo Product' ``` -------------------------------- ### Checkout Store Configuration Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Configure your store details for use in checkout invoices. ```APIDOC ## Checkout Store Configuration ```javascript var store = new paydunya.Store({ name: 'Magasin Chez Sandra', // only name is required tagline: "L'élégance n'a pas de prix", phoneNumber: '336530583', postalAddress: 'Dakar Plateau - Etablissement kheweul', logoURL: 'http://www.chez-sandra.sn/logo.png' }); ``` ``` -------------------------------- ### Adding Tax Information Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Include tax information that will be displayed on the invoice and receipt. ```APIDOC ## Adding Tax Information You may include tax information on on the checkout page. This information will be available on the invoice & receipt printouts and PDF downloads. ```javascript invoice.addTax('VAT (18%)', 3000); invoice.addTax('Autre taxe (5%)', 200); ``` ``` -------------------------------- ### Set Return URL for Paydunya Checkouts Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Configure a return URL to redirect customers after a successful payment. This can be set globally for a store or per checkout invoice. ```javascript var store = new paydunya.Store({ name: 'Magasin chez Sandra', returnURL: 'http://www.ma-super-boutique.com/confirm' }); ``` ```javascript invoice.returnURL = 'http://www.ma-super-boutique.com/confirm'; ``` -------------------------------- ### Add Invoice Items & Description Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Add items to the invoice, specifying name, quantity, unit price, and total price. You can also set a general description for the invoice. ```APIDOC ## Add Invoice Items & Description ```javascript invoice.addItem('Ordinateur Lenovo L440', 1, 400000, 400000); // name, quantity, unit price, total price invoice.description = 'Lenovo Product' ``` ``` -------------------------------- ### Redirecting to Paydunya Checkout Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md After setting the total amount and adding items, create a checkout invoice. This will generate a redirect URL for the customer to complete the payment. ```APIDOC ## Redirecting to paydunya Checkout After setting total amount and adding items to your invoice you can create a checkout and redirect the customer. It takes a callback which gets passed the updated invoice object containing the url. ```javascript invoice.create() .then(function (){ invoice.status; invoice.token; // invoice token invoice.responseText; invoice.url; // PAYDUNYA redirect checkout url }) .catch(function (e) { console.log(e); }); ``` ``` -------------------------------- ### Setting Total Amount Chargeable Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Set the total amount that will be charged for the invoice. ```APIDOC ## Setting Total Amount Chargeable ```javascript invoice.totalAmount = 400000; ``` ``` -------------------------------- ### Initiate Direct Payment with Paydunya Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Send funds directly to a Paydunya account from your third-party application. Useful for implementing custom payment solutions. ```javascript var directPay = new paydunya.DirectPay(setup); directPay.creditAccount('alioune@gmail.com', 5000) .then(function (){ directPay.description; directPay.responseText; directPay.transactionID; }) .catch(function (e) { console.log(e); }); ``` -------------------------------- ### Set Total Amount Chargeable Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Set the total amount that will be charged for the invoice. This should be set after adding all items. ```javascript invoice.totalAmount = 400000; ``` -------------------------------- ### Setting a Cancel URL Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Optionally set a URL where customers will be redirected if they cancel the checkout process. This can be set globally for the store or per invoice. ```APIDOC ## Setting a Cancel URL You can optionally set the URL where your customers will be redirected to after canceling a checkout. Note: There are two options as to how the cancel URL is set, one is to set it globally using the checkout setup information and the other is set it as per checkout invoice. Setting the cancel URL directly on the invoice instance will overwrite the global settings if already set. ```javascript // Globally var store = new paydunya.Store({ name: 'Magasin chez Sandra', cancelURL: 'http://www.ma-super-boutique.com/' }); // Per Checkout invoice.cancelURL = 'http://www.ma-super-boutique.com/'; ``` ``` -------------------------------- ### Configure Merchant Store Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Define store details displayed on checkout pages and receipts. The store name is mandatory, while other fields like URLs and contact information are optional. ```javascript var paydunya = require('paydunya'); var store = new paydunya.Store({ name: 'Magasin Chez Sandra', // Required: Store name tagline: "L'élégance n'a pas de prix", // Optional: Store tagline phoneNumber: '336530583', // Optional: Contact phone postalAddress: 'Dakar Plateau - Etablissement kheweul', // Optional: Address logoURL: 'http://www.chez-sandra.sn/logo.png', // Optional: Store logo URL websiteURL: 'http://www.chez-sandra.sn', // Optional: Website URL cancelURL: 'http://www.chez-sandra.sn/cancel', // Optional: Redirect on cancel returnURL: 'http://www.chez-sandra.sn/confirm', // Optional: Redirect on success callbackURL: 'http://www.chez-sandra.sn/webhook' // Optional: IPN callback URL }); ``` -------------------------------- ### Set Cancel URL for Checkout Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Optionally set a URL for redirecting customers after they cancel a checkout. This can be set globally via the store configuration or per invoice. ```javascript // Globally var store = new paydunya.Store({ name: 'Magasin chez Sandra', cancelURL: 'http://www.ma-super-boutique.com/' }); // Per Checkout invoice.cancelURL = 'http://www.ma-super-boutique.com/'; ``` -------------------------------- ### POST /checkout/confirm Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Confirms the status of a checkout invoice using a unique token. This endpoint is used to verify if a payment has been completed. ```APIDOC ## POST /checkout/confirm ### Description Programmatically check the status of a checkout invoice using its token. This is useful for verifying payment completion via webhooks or polling. ### Parameters #### Request Body - **invoiceToken** (string) - Required - The unique token associated with the checkout invoice. ### Response #### Success Response (200) - **status** (string) - The current status of the invoice ('completed', 'pending', 'canceled', or 'fail'). - **customer** (object) - Customer information if payment is completed. - **receiptURL** (string) - URL to the PDF receipt. - **totalAmount** (number) - The total amount of the invoice. ``` -------------------------------- ### Add Tax Information to Invoice Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Include tax information on the checkout page, which will be reflected on invoices and receipts. Multiple tax entries can be added. ```javascript invoice.addTax('VAT (18%)', 3000); invoice.addTax('Autre taxe (5%)', 200); ``` -------------------------------- ### Confirm Paydunya Checkout Programmatically Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Check the status of a Paydunya checkout using its token. This allows retrieval of receipt links and customer information if the checkout is completed. ```javascript var token = 'odaff0a023'; var invoice = new paydunya.CheckoutInvoice(setup, store); invoice.confirm(token) .then(function (){ invoice.status; // completed, pending, canceled or fail invoice.responseText; // available if status == 'completed' invoice.customer; // {name: 'Alioune Badara', phone: '772639273', email: 'alioune@gmail.com'} invoice.receiptURL; // 'https://app.paydunya.com/sandbox-checkout/receipt/pdf/test_44a6fef19a.pdf' }) .catch(function (e) { console.log(e); }); ``` -------------------------------- ### Adding Custom Data Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Add custom data to the invoice for your internal use. This data is stored by Paydunya but not displayed to the customer. ```APIDOC ## Adding Custom Data There are times when you may need to add an extra load of data with the checkout information for later use. paydunya allows saving of custom data on their servers which are persisted even after successful payment. Note: Custom data is not displayed anywhere on the checkout page, invoice/receipt download & printouts. ```javascript invoice.addCustomData('CartID', 32393); invoice.addCustomData('Plan', 'NOEL'); ``` ``` -------------------------------- ### Transfer funds with DirectPay Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Use DirectPay to transfer funds to a PAYDUNYA account via email, phone, or username. Ensure the merchant account has sufficient balance before initiating the transfer. ```javascript var paydunya = require('paydunya'); var setup = new paydunya.Setup({ masterKey: 'your-master-key', privateKey: 'your-private-key', token: 'your-token', mode: 'test' }); var directPay = new paydunya.DirectPay(setup); // Credit a PAYDUNYA account by email, phone, or username var recipientAccount = 'alioune@gmail.com'; var amount = 5000; // Amount in local currency directPay.creditAccount(recipientAccount, amount) .then(function() { console.log('Response:', directPay.responseText); console.log('Description:', directPay.description); console.log('Transaction ID:', directPay.transactionID); // Funds transferred successfully }) .catch(function(error) { console.error('Transfer failed:', error.message); if (error.data) console.error('API Response:', error.data); // Check account alias and ensure sufficient balance }); ``` -------------------------------- ### Add Custom Data to Invoice Source: https://github.com/paydunyadev/paydunya-node-master/blob/master/README.md Attach custom data to the checkout information for later use. This data is stored on Paydunya's servers and is not displayed on the checkout page or receipts. ```javascript invoice.addCustomData('CartID', 32393); invoice.addCustomData('Plan', 'NOEL'); ``` -------------------------------- ### Confirm Checkout Invoice Status Source: https://context7.com/paydunyadev/paydunya-node-master/llms.txt Verifies the payment status of a checkout invoice using its token. Use this to retrieve customer details and receipt information once payment is completed. ```javascript var paydunya = require('paydunya'); var setup = new paydunya.Setup({ masterKey: 'your-master-key', privateKey: 'your-private-key', token: 'your-token', mode: 'test' }); var store = new paydunya.Store({ name: 'My Store' }); var invoice = new paydunya.CheckoutInvoice(setup, store); // Confirm using a previously received token var invoiceToken = 'odaff0a023'; invoice.confirm(invoiceToken) .then(function() { console.log('Status:', invoice.status); // 'completed', 'pending', 'canceled', or 'fail' console.log('Response:', invoice.responseText); console.log('Total Amount:', invoice.totalAmount); if (invoice.status === 'completed') { console.log('Customer:', invoice.customer); // { name: 'Alioune Badara', phone: '772639273', email: 'alioune@gmail.com' } console.log('Receipt URL:', invoice.receiptURL); // 'https://app.paydunya.com/sandbox-checkout/receipt/pdf/test_44a6fef19a.pdf' console.log('Receipt ID:', invoice.receipt_identifier); console.log('Provider Ref:', invoice.provider_reference); if (invoice.customData) { console.log('Custom Data:', invoice.customData); // { OrderID: 'ORD-12345', CustomerID: 'CUST-789' } } } }) .catch(function(error) { console.error('Confirmation failed:', error.message); if (error.data) console.error('API Response:', error.data); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.