cpay-client
v0.0.7
Published
The `CpayClient` library provides a straightforward way to integrate a payment gateway into your applications, allowing you to generate URLs for processing payments with ease.
Downloads
2
Readme
CpayClient Library
The CpayClient library provides a straightforward way to integrate a payment gateway into your applications, allowing you to generate URLs for processing payments with ease.
Features
- Easy initialization with API key and language settings.
- Generate payment gateway URLs with detailed transaction information.
Installation
Install CpayClient using npm:
npm i cpay-clientOr if you prefer using yarn:
yarn add cpay-clientUsage
Initialize the Client First, initialize the CpayClient with your API key and optional language preference:
import CpayClient from 'cpay-client';
CpayClient.initial('YOUR_API_KEY', 'en'); // Replace 'YOUR_API_KEY' with your actual API keyGenerate a Payment Gateway
To generate a payment gateway URL, provide the necessary transaction details as shown in the example below:
async function generatePaymentGateway() {
const transactionDetails = {
description: 'Wireless Headphones JBL', // Description of the item/service
title: 'Online Store Purchase', // Title of the transaction
price: 99.99, // Price of the transaction
uiqueId: '123456789', // A unique identifier for the transaction
useExternalAddress: false, // Set to true if using an external wallet address
returnUrl: 'https://yourwebsite.com/payment-return', // URL to redirect after payment
externalAddress: '', // Optional: External wallet address (if useExternalAddress is true)
};
try {
const response = await CpayClient.generateGateway(transactionDetails);
console.log('Payment Gateway URL:', response.url);
} catch (error) {
console.error('Error generating payment gateway:', error);
}
}
generatePaymentGateway();CpayClient Library
The CpayClient library enables easy integration of payment gateway functionalities into your applications, allowing for the generation of payment gateway URLs for various transactions.
API Reference
initial(apiKey: string, lang: string = 'en')
Initializes the CpayClient with the provided API key and language setting.
apiKey: Your unique API key for accessing the payment gateway.lang: (Optional) The preferred language for API responses, default is'en'.
generateGateway(data: object): Promise<Response<GenerateUrlResponse>>
Generates a payment gateway URL using the provided transaction details.
data: An object containing key transaction details.
Parameters for data:
description: A brief description of the transaction item or service.title: The title or name of the transaction.price: The total price of the transaction.uniqueId: A unique identifier for the transaction.useExternalAddress: A boolean indicating whether an external address is used for the transaction.returnUrl: The URL to redirect to after payment completion.externalAddress: (Optional) The external address to use for the transaction, ifuseExternalAddressistrue.
getTransactionInfo(tnx: string): Promise<Response<GetTransactionInfoById>>
Retrieves detailed information about a specific transaction by its unique identifier. This function makes a GET request to the /invoice/getBy-api-key/{tnx} endpoint, where {tnx} is the transaction identifier.
tnx: The unique identifier for the transaction you want to retrieve information about.
Response Structure:
The function returns a promise that resolves to a Response object containing transaction details. The Response object has the following structure:
status: The HTTP status code of the response.message: A message describing the outcome of the request.success: A boolean indicating whether the request was successful.result: An object containing the detailed transaction information wrapped in adataproperty.
Example Usage:
async function fetchTransactionInfo() {
const transactionId = 'unique_transaction_id';
try {
const transactionInfo = await CpayClient.getTransactionInfo(transactionId);
console.log('Transaction Info:', transactionInfo);
} catch (error) {
console.error('Error fetching transaction info:', error);
}
}
fetchTransactionInfo();
Support
For support, please open an issue on our GitHub repository or contact our support team directly through our official channels.
Contributing
Contributions to the CpayClient library are warmly welcomed. Please refer to our contributing guidelines for more information on how to contribute effectively.
License
This project is licensed under the ISC License - see the LICENSE file for details.
