### Installing UniPayment SDK using npm Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This snippet demonstrates how to install the UniPayment SDK into your Node.js project using the npm package manager. It's the recommended and easiest way to include the SDK as a dependency. ```bash npm install unipayment-sdk ``` -------------------------------- ### Installing UniPayment SDK via npm Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This snippet demonstrates how to install the UniPayment SDK using the npm package manager. It's the recommended and easiest way to add the SDK to your Node.js project, ensuring all dependencies are managed automatically. ```bash npm install unipayment-sdk ``` -------------------------------- ### Example Create Invoice Response JSON Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This JSON snippet provides an example structure of the response received after successfully creating an invoice using the UniPayment API. It includes details such as `invoice_id`, `order_id`, `price_amount`, `price_currency`, `status`, `invoice_url`, and other relevant payment information. ```json { "msg": "", "code": "OK", "data": { "app_id": "df01ae1f-8c31-4ecd-8ab1-9e31289d4823", "payment_method_type": "UNKNOWN", "invoice_id": "88144dSLPujPsUJYakkJdx", "order_id": "ORDER_1721023791051", "price_amount": 2.0, "price_currency": "USD", "network": null, "address": null, "pay_amount": 0.0, "pay_currency": null, "exchange_rate": 0.0, "paid_amount": 0.0, "refunded_price_amount": 0.0, "create_time": "2024-07-15T06:09:54", "expiration_time": "2024-07-15T06:29:54", "confirm_speed": "Medium", "status": "New", "error_status": "None", "invoice_url": "https://sandbox.api.unipayment.com/i/88144dSLPujPsUJYakkJdx" } } ``` -------------------------------- ### Example Response for Create Invoice API Call Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This JSON snippet illustrates the typical structure of a successful response from the `createInvoice` API call. It includes details such as `invoice_id`, `order_id`, `price_amount`, `price_currency`, `status`, and `invoice_url`, which are essential for tracking and displaying payment information. ```json { "msg": "", "code": "OK", "data": { "app_id": "df01ae1f-8c31-4ecd-8ab1-9e31289d4823", "payment_method_type": "UNKNOWN", "invoice_id": "88144dSLPujPsUJYakkJdx", "order_id": "ORDER_1721023791051", "price_amount": 2.0, "price_currency": "USD", "network": null, "address": null, "pay_amount": 0.0, "pay_currency": null, "exchange_rate": 0.0, "paid_amount": 0.0, "refunded_price_amount": 0.0, "create_time": "2024-07-15T06:09:54", "expiration_time": "2024-07-15T06:29:54", "confirm_speed": "Medium", "status": "New", "error_status": "None", "invoice_url": "https://sandbox.api.unipayment.com/i/88144dSLPujPsUJYakkJdx" } } ``` -------------------------------- ### Example UniPayment IPN Notification Payload Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This JSON snippet provides an example of the payload structure for an Instant Payment Notification (IPN) sent by UniPayment. IPNs are crucial for real-time updates on invoice status changes (e.g., paid, confirmed, complete) and include details like `ipn_type`, `event`, `invoice_id`, `order_id`, and current `status`. ```json { "ipn_type": "invoice", "event": "invoice_expired", "app_id": "cee1b9e2-d90c-4b63-9824-d621edb38012", "invoice_id": "3Q7fyLnB2YNhUDW1fFNyEz", "order_id": "20", "price_amount": 6.0, "price_currency": "SGD", "network": null, "address": null, "pay_currency": null, "pay_amount": 0.0, "exchange_rate": 0.0, "paid_amount": 0.0, "confirmed_amount": 0.0, "refunded_price_amount": 0.0, "create_time": "2022-09-12T03:36:03", "expiration_time": "2022-09-12T03:41:03", "status": "Expired", "error_status": "None", "ext_args": null, "transactions": null, "notify_id": "8ccd2b61-226b-48e5-99b8-acb1f350313e", "notify_time": "2022-09-12T03:56:10.5852752Z" } ``` -------------------------------- ### Example IPN Notification JSON Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This JSON snippet illustrates the structure of an Instant Payment Notification (IPN) sent by UniPayment. It contains details about the event (e.g., `invoice_expired`), `app_id`, `invoice_id`, `order_id`, payment amounts, currencies, status, and timestamps, allowing the receiving application to update its records accordingly. ```json { "ipn_type": "invoice", "event": "invoice_expired", "app_id": "cee1b9e2-d90c-4b63-9824-d621edb38012", "invoice_id": "3Q7fyLnB2YNhUDW1fFNyEz", "order_id": "20", "price_amount": 6.0, "price_currency": "SGD", "network": null, "address": null, "pay_currency": null, "pay_amount": 0.0, "exchange_rate": 0.0, "paid_amount": 0.0, "confirmed_amount": 0.0, "refunded_price_amount": 0.0, "create_time": "2022-09-12T03:36:03", "expiration_time": "2022-09-12T03:41:03", "status": "Expired", "error_status": "None", "ext_args": null, "transactions": null, "notify_id": "8ccd2b61-226b-48e5-99b8-acb1f350313e", "notify_time": "2022-09-12T03:56:10.5852752Z" } ``` -------------------------------- ### Running Project Tests (Bash) Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This command executes the test suite defined in the UniPaymentClient.Node project's `package.json` file, verifying the project's functionality and ensuring all components work as expected. ```bash npm test ``` -------------------------------- ### UniPayment SDK Configuration File Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This JSON snippet defines the configuration structure required for initializing the UniPayment SDK. It includes essential parameters like `apiHost`, `clientId`, `clientSecret`, `appId`, and `apiVersion` which are crucial for authenticating and interacting with the UniPayment API. ```json { "apiHost": "https://api.unipayment.io", "clientId": "your client id", "clientSecret": "you client secret", "appId": "your app id", "apiVersion": "1.0" } ``` -------------------------------- ### Running Tests for UniPaymentClient Node.js Project in Bash Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This command executes the test suite for the UniPaymentClient.Node project. It typically runs scripts defined in the 'package.json' file, ensuring that all functionalities are working as expected and validating the project's integrity. ```bash npm test ``` -------------------------------- ### Configuring UniPayment SDK with JSON Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This JSON snippet illustrates the structure of the `configuration.json` file required for initializing the UniPayment SDK. It defines essential parameters like API host, client ID, client secret, app ID, and API version, which are crucial for authenticating and interacting with the UniPayment API. ```json { "apiHost": "https://api.unipayment.io", "clientId": "your client id", "clientSecret": "you client secret", "appId": "your app id", "apiVersion": "1.0" } ``` -------------------------------- ### Initializing UniPayment SDK Modules in Node.js Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This Node.js snippet shows how to import various API modules (BeneficiaryAPI, BillingAPI, CommonAPI, ExchangeAPI, PaymentAPI, WalletAPI) from the `unipayment-sdk` package. These modules provide access to different functionalities of the UniPayment API, enabling developers to interact with specific payment-related services. ```nodejs const {BeneficiaryAPI, BillingAPI, CommonAPI, ExchangeAPI, PaymentAPI, WalletAPI} = require('unipayment-sdk'); ``` -------------------------------- ### Cloning UniPaymentClient Node.js Repository in Bash Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This command is used to clone the source code of the UniPaymentClient.Node project from its GitHub repository. Executing this command will download all project files to the current directory, enabling local development and testing. ```bash git clone https://github.com/UniCryptoLab/UniPaymentClient.Node.git ``` -------------------------------- ### Initializing UniPayment SDK Modules in JavaScript Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This JavaScript snippet shows how to import various API modules from the `unipayment-sdk` package. These modules (BeneficiaryAPI, BillingAPI, CommonAPI, ExchangeAPI, PaymentAPI, WalletAPI) provide access to different functionalities of the UniPayment API, allowing developers to interact with specific services. ```javascript const {BeneficiaryAPI, BillingAPI, CommonAPI, ExchangeAPI, PaymentAPI, WalletAPI} = require('unipayment-sdk'); ``` -------------------------------- ### Cloning UniPaymentClient.Node Repository (Bash) Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This command clones the UniPaymentClient.Node project source code from its GitHub repository, allowing local access to the project files for development or testing purposes. ```bash git clone https://github.com/UniCryptoLab/UniPaymentClient.Node.git ``` -------------------------------- ### Creating an Invoice with UniPayment SDK in JavaScript Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This JavaScript snippet demonstrates how to create a new invoice using the `BillingAPI` of the UniPayment SDK. It requires a `configuration` object and constructs a `createInvoiceRequest` with details like app ID, order ID (generated using `uuidv4`), price amount, currency, and optional arguments. The `createInvoice` method returns a promise that resolves with the response or rejects with an error. ```javascript const {v4: uuidv4} = require('uuid'); const {BillingAPI} = require('unipayment-sdk'); const billingAPI = new BillingAPI(configuration); const createInvoiceRequest = { 'app_id': configuration.appId, 'order_id': uuidv4(), 'price_amount': 1.00, 'price_currency': 'USD', 'lang': 'en', 'ext_args': 'Merchant Pass Through Data' }; billingAPI.createInvoice(createInvoiceRequest).then(response => { printResponse(response); assert.equal(response.data.code === 'OK', true); done(); }).catch(error => { done(); console.log(error); }) ``` -------------------------------- ### Creating an Invoice with UniPayment SDK in JavaScript Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This JavaScript snippet demonstrates how to create a new invoice using the `BillingAPI` from the UniPayment SDK. It requires a `configuration` object and constructs a `createInvoiceRequest` with details like `app_id`, `order_id`, `price_amount`, and `price_currency`. The `createInvoice` method returns a promise that resolves with the invoice details or rejects on error. ```javascript const {v4: uuidv4} = require('uuid'); const {BillingAPI} = require('unipayment-sdk'); const billingAPI = new BillingAPI(configuration); const createInvoiceRequest = { 'app_id': configuration.appId, 'order_id': uuidv4(), 'price_amount': 1.00, 'price_currency': 'USD', 'lang': 'en', 'ext_args': 'Merchant Pass Through Data' }; billingAPI.createInvoice(createInvoiceRequest).then(response => { printResponse(response); assert.equal(response.data.code === 'OK', true); done(); }).catch(error => { done(); console.log(error); }) ``` -------------------------------- ### Verifying Instant Payment Notification (IPN) in JavaScript Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This JavaScript snippet demonstrates how to verify an Instant Payment Notification (IPN) received from UniPayment using the `CommonAPI`. The `checkIpn` method validates the authenticity and integrity of the notification, ensuring that the payment status updates are legitimate. It expects the raw IPN payload as input. ```javascript const {CommonAPI} = require('unipayment-sdk'); const commonAPI = new CommonAPI(configuration); const notify = 'notify from unipayment' commonAPI.checkIpn(notify).then(response => { printResponse(response); assert.equal(response.data.code === 'OK', true); assert.equal(response.data.msg === 'IPN is verified.', true) done(); }).catch(error => { done(); console.log(error); }) ``` -------------------------------- ### Handling Instant Payment Notifications (IPN) with UniPayment SDK in JavaScript Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This JavaScript snippet demonstrates how to verify an Instant Payment Notification (IPN) received from UniPayment using the `CommonAPI`. IPNs are sent to a `notify_url` when an invoice's status changes. The `checkIpn` method validates the incoming notification, ensuring its authenticity and integrity. ```javascript const {CommonAPI} = require('unipayment-sdk'); const commonAPI = new CommonAPI(configuration); const notify = 'notify from unipayment' commonAPI.checkIpn(notify).then(response => { printResponse(response); assert.equal(response.data.code === 'OK', true); assert.equal(response.data.msg === 'IPN is verified.', true) done(); }).catch(error => { done(); console.log(error); }) ``` -------------------------------- ### Verifying Webhook Signatures with UniPayment SDK (JavaScript) Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/unipaymentsdk/README.md This snippet demonstrates how to verify the 'hmac_signature' of a webhook request using the `WebhookSignatureUtil` from the `unipayment-sdk`. It requires the raw JSON payload, a secret key, and the signature to be verified to determine its validity. ```javascript const {WebhookSignatureUtil} = require('unipayment-sdk'); //Use raw json payload (no formatting or pretty print) const payload = 'json payload'; const secretKey = 'your secret key'; const signature = 'signature to verify'; const valid = WebhookSignatureUtil.isValid($payload, $secretKey, $signature); ``` -------------------------------- ### Verifying Webhook Signatures with UniPayment SDK in JavaScript Source: https://github.com/elharaka/unipaymentclient/blob/v2.x.x/README.md This snippet demonstrates how to verify the 'hmac_signature' from a webhook request header using the 'WebhookSignatureUtil' from the 'unipayment-sdk'. It requires the raw JSON payload, a secret key, and the signature to be verified for validation. ```javascript const {WebhookSignatureUtil} = require('unipayment-sdk'); //Use raw json payload (no formatting or pretty print) const payload = 'json payload'; const secretKey = 'your secret key'; const signature = 'signature to verify'; const valid = WebhookSignatureUtil.isValid($payload, $secretKey, $signature); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.