1.0.2 • Published 7 months ago
mypvit-js v1.0.2
MyPVit SDK
The MyPVit SDK is a JavaScript library designed to interact with the MyPVit API. It simplifies integration by providing easy-to-use methods for managing transactions, retrieving balances, handling KYC data, and more.
Features
- Transaction Management: Initialize REST and LINK transactions effortlessly to process payments and other financial operations.
- Status Enquiry: Easily check the status of any transaction using its unique identifier, ensuring real-time monitoring of operations.
- Balance Enquiry: Retrieve the balance of a specific merchant or operation account securely through the API.
- KYC Data Retrieval: Access customer KYC (Know Your Customer) information securely, including full name, account status, and more.
- Secret Key Retrieval: Generate or refresh secret keys securely for API authentication, ensuring continued access and secure communications.
- Error Handling: Detailed error management through custom exceptions like
MyPVitException
, which provides clear and structured error information for debugging. - Lightweight: Built with minimal dependencies (e.g., Axios) for optimal performance and simplicity.
Installation
Install the SDK via npm:
npm install mypvit-sdk
Install the SDK via yarn:
yarn add mypvit-sdk
Usage
Initialization
To use the SDK, start by importing and initializing the MyPVitClient
:
const { MyPVitClient } = require('mypvit-sdk');
const client = new MyPVitClient();
Examples
Secret Key Retrieval
(async () => {
try {
const urlCode = 'your-url-code';
const response = await client.getToken(
'ACC_XXXXXXFFF3',
'ABCDE',
'your-secret-key-pass',
urlCode
);
console.log('Token Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Initialize a REST Transaction
(async () => {
try {
const secretKey = 'your-account-operation-secret-key';
const urlCode = 'your-url-code';
const transaction = {
agent: "AGENT-1",
amount: 200,
callback_url_code: "OGNAE",
customer_account_number: "074XXXXX6",
merchant_operation_account_code: "ACC_XXXXXXFFF3",
transaction_type: "PAYMENT",
owner_charge: "CUSTOMER",
owner_charge_operator: "MERCHANT",
free_info: "INFORMATION",
product: "PRODUIT TEL",
reference: "REF181020309",
service: "RESTFUL"
}
const response = await client.initRestTransaction(
transaction,
urlCode,
secretKey
);
console.log('Transaction Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Initialize a LINK Transaction
(async () => {
try {
const secretKey = 'your-account-operation-secret-key';
const urlCode = 'your-url-code';
const transaction = {
agent: "AGENT-1",
amount: 200,
callback_url_code: "OGNAE",
customer_account_number: "074XXXXX6",
merchant_operation_account_code: "ACC_XXXXXXFFF3",
transaction_type: "PAYMENT",
owner_charge: "CUSTOMER",
owner_charge_operator: "MERCHANT",
free_info: "INFORMATION",
product: "PRODUIT TEL",
reference: "REF181020310",
service: "VISA_MASTERCARD",
failed_redirection_url_code: "CBFOU",
success_redirection_url_code: "ABCDE"
}
const response = await client.initLinkTransaction(
transaction,
urlCode,
secretKey
);
console.log('Transaction LINK Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Status Enquiry
(async () => {
try {
const secretKey = 'your-account-operation-secret-key';
const urlCode = 'your-url-code';
const response = await client.getStatus(
'REF181020310',
'ACC_XXXXXXFFF3',
'PAYMENT',
urlCode,
secretKey
);
console.log('Status Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Balance Enquiry
(async () => {
try {
const secretKey = 'your-account-operation-secret-key';
const urlCode = 'your-url-code';
const response = await client.getBalance(
'ACC_XXXXXXFFF3',
urlCode,
secretKey
);
console.log('Balance Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Retrieve KYC Information
(async () => {
try {
const urlCode = 'your-url-code';
const response = await client.getKyc(
'074XXXX6',
urlCode
);
console.log('KYC Response:', response);
} catch (error) {
console.error('Error:', error.message);
}
})();
Error Handling
The SDK uses a custom exception class, MyPVitException
, to provide detailed error messages. You can use this for advanced error handling and debugging.
Example
const { MyPVitException } = require('mypvit-sdk');
try {
const urlCode = 'your-url-code';
const transaction = {
agent: "AGENT-1",
amount: 200,
callback_url_code: "OGNAE",
customer_account_number: "074XXXXX6",
merchant_operation_account_code: "ACC_XXXXXXFFF3",
transaction_type: "PAYMENT",
owner_charge: "CUSTOMER",
owner_charge_operator: "MERCHANT",
free_info: "INFORMATION",
product: "PRODUIT TEL",
reference: "REF181020309",
service: "RESTFUL"
};
// Simulate a failing API request
await client.initRestTransaction(
transaction,
urlCode,
'invalid-secret-key'
);
} catch (error) {
if (error instanceof MyPVitException) {
console.error('API Error:', error.toString());
} else {
console.error('Unexpected Error:', error.message);
}
}
License
This project is licensed under the MIT License.
Terms of Use
By using this SDK, you agree to comply with the Terms of Use that prohibit specific activities such as illegal transactions, promotion of hate, or violation of applicable laws.