Мерчант системы
A Merchant Integration Documentation
This document outlines the structure and key components required to integrate a merchant plugin into our system.
File Structure
Your merchant should be organized in the following directory structure under the pluginsExternal/merchants
directory. The directory is imported into the system as a plugin and should contain the following files:
configure.js
: This is where you define the basic setup for your merchant plugin, such as API keys, API Secret, and other necessary configuration options.icon.png
: A graphical representation of the merchant. This icon is used throughout the system to visually identify your merchant plugin.index.js
: The core implementation file for the merchant plugin. This file contains the logic and functionality required to interact with the merchant's API and our system.templates/
: A directory containing HTML and JavaScript templates for the merchant's admin and client interfaces.admin.html
: A template file that defines the configuration interface seen by administrators when they set up the merchant in the system.admin.js
: A script that handles the data binding and interaction logic for the admin configuration page.client.html
: A template file that defines the interface seen by clients or end-users when interacting with the merchant's services.client.js
: A script that manages the data interaction for the client-side template.
Templates
The templates/
directory contains HTML and JavaScript files that define how the merchant's configuration and client-facing interfaces look and behave. This section provides details on the two main templates: the admin configuration page and the client page.
Admin Config Page (admin.html
)
admin.html
)The admin configuration page is a crucial part of the merchant plugin. This page allows system administrators to set up and manage the merchant's integration by providing the necessary configuration options such as API keys, supported currencies, and debug options.
Structure Explanation:
Merchant Name: Displays the name of the merchant being configured.
Supported Currencies: Lists the currencies that this merchant supports, which can help administrators quickly understand what options are available.
Config: Display the configuration options for the merchant where administrators can input the API key, API secret, and other necessary parameters
API Key:
: Input field for the API key.Secret Key:
: Input field for the API secret.Debug log?
: Select field for enabling debug logging.saveConfig
: Function to save the configuration options, such as API key, API secret, and debug log.
Public IP and Webhook URL: Displays the public IP address and webhook URL relevant to the merchant, which is useful for debugging and setup verification.
Admin Config Export (admin.js
)
admin.js
)The admin.js file is a Vue.js component that manages the admin configuration page. It handles data binding, user input, and communication with the backend to save the configuration settings provided by the administrator.
Key Components:
Template Loading: The
template
property loads theadmin.html
file into the Vue instance, allowing for seamless integration of the HTML template with the Vue component.Props: These are properties passed from the backend to the Vue instance, providing necessary context such as the server's domain, public IP, and merchant key.
Data: Defines reactive data properties like
debug
andapiKey
, which are used to bind user inputs in the admin template.Lifecycle Methods:
created()
: Initializes the component when it is first created, typically setting up default values or fetching initial data.mounted()
: Called when the component is inserted into the DOM, useful for any post-render logic.
Methods:
saveConfig(key, value)
: A method to save the merchant's configuration settings back to the server, ensuring that any changes made by the administrator are persisted.
Client Config Export (client.html
)
client.html
)The client page is used to display the merchant data to the client. It will display information like the Address, QR code, Account Owner & Number, Redirect URL, Form, etc. THis is the page where the client will interact with the merchant.
Structure Explanation:
Error Handling: The template checks for any errors in the payment data and displays an error message if necessary.
Merchant Data: This is where the merchant-specific data is displayed to the client, allowing them to interact with the merchant's services.
Payment Data: The
payData
object contains the payment information required by the merchant to process the payment, such as the payment amount, address, and payment method.Localization: The
t()
function is used to translate text strings based on the client's language preference, ensuring a seamless user experience.Order Information: The
order
object contains details about the current order, such as the currency, amount, and route information.
QR Code
Display a QR code for the client to scan and make a payment, along with the payment amount and address.
Account Information
Display the merchant's account owner and number for the client to make a bank transfer.
Form: A form that submits the payment data to the merchant's payment processing endpoint, allowing the client to complete the payment process.
Button: A button that triggers the form submission when clicked, initiating the payment process.
Hidden Fields: Hidden input fields containing the payment data required by the merchant to process the payment.
Redirect URL: The URL to which the client will be redirected after completing the payment process.
If the redirect URL is a simple get request to the merchant site, you can use the following code:
Manual Form Input
If the merchant requires manual input from the client, you can display a form with the necessary fields.
Form Fields: Input fields for the client to enter the required information, such as an E-Voucher number and activation code.
Labels: Descriptive labels for each input field, providing context for the client.
Button: A button that triggers the client script method when clicked, allowing the client to submit the form data for payment processing.
uploadCode(): A client script method that handles the form submission logic, processing the client's input and initiating the payment process.
Client Config Export (client.js
)
client.js
)The client.js file is a Vue.js component that manages the client page. It handles data binding, user interaction, and communication with the backend to process the payment and update the order status.
The client script is responsible for handling the local state of the client page, such as loading status, payment data, and localization.
Key Components:
Template Loading: The
template
property loads theclient.html
file into the Vue instance, allowing for seamless integration of the HTML template with the Vue component.Props: These are properties passed from the backend to the Vue instance, providing necessary context such as the order details, payment data, and QR code settings.
Data: Defines reactive data properties like
loadStatus
andopenPS
, which are used to manage the loading state and payment processing logic.loadStatus
: A boolean flag indicating whether the client page is still loading or has finished rendering.openPS
: A boolean flag that controls whether the payment processing page should be opened automatically based on localStorage and user agent.
Lifecycle Methods:
created()
: Initializes the component when it is first created, setting up the payment processing logic based on the client's device.mounted()
: Called when the component is inserted into the DOM, useful for any post-render logic.
Methods:
t(k, d)
: A method to translate text strings based on the client's language preference, ensuring a localized user experience.
In the client.js
file, you can define additional methods to handle client-side logic, such as form submission, payment processing, and order status updates. Just add the methods to the methods
object in the Vue component definition.
Configuration
The configure.js
file is where you define the basic setup for your merchant plugin, such as Title, Name, and required configuration options. This file is used to configure the merchant plugin and set up the necessary parameters for integration.
Structure Explanation:
Type: The type of plugin, in this case, a merchant plugin.
Title: The title of the merchant plugin, which is displayed in the system's interface.
Name: The name of the merchant plugin, used to identify the plugin in the system.
Required NPM Packages: Any required npm packages that need to be installed for the merchant plugin to function correctly.
Allow XML: An array of XML endpoints that the merchant plugin can interact with, if applicable.
Default Configuration: The default configuration settings for the merchant plugin, such as debug mode and API key.
Required Configuration: The required configuration settings that control weather the values are displayed in the admin configuration page or not.
Debug: A configuration option to enable or disable debug mode, useful for troubleshooting and testing.
API Key: A configuration option to set the API key required for the merchant plugin to interact with the merchant's API.
1: Indicates that the value is displayed as value in the admin configuration page.
2: Indicates that the value is displayed as a password in the admin configuration page.
Icon
The icon.png
file should be a PNG image with a minimum size of 150x150 pixels. This icon will represent your merchant plugin in the system's user interface, making it easily recognizable to administrators.
Implementation
The index.js
file contains the core logic of your merchant plugin. Below are the key methods that should be implemented:
Constructor
The constructor is responsible for initializing the merchant plugin with the necessary configurations and options.
Parameters:
API
: An object containing the system's API end for interacting with the backend locally.config
: An object containing the merchant's configuration settings, such as the API key and debug mode.
id_key
: The unique identifier for the merchant plugin, derived from the directory name.config
: A configuration object that loads the merchant's configuration settings from the system.i18n
: A localization function used to translate text strings based on the client's language preference.crypto
: A cryptographic module used for generating secure hashes and encryption.axios
: A popular HTTP client for making API requests.BigNumber
: A library for handling arbitrary-precision arithmetic, useful for dealing with financial calculations.checkPaymentModule
: A module that checks the payment status of a transaction, ensuring that payments are processed correctly.
Get Fields
The class MerchantName
should also define any necessary form fields to collect data from the client such as thier email, phone number, full name, etc. Although, most of the time, the fields methods return an empty array unless the merchant requires additional information from the client.
Parameters:
lang
: The language code for the client's preferred language, used for localization.xml
: An XML of the currency that the merchant supports, if applicable.The
getFields
method should return an array of field objects, each representing a form field that the client needs to fill out. Each field object should contain the following properties:_id
: A unique identifier for the field.name
: The display name of the field, used as a label in the client interface.placeholder
: A placeholder text for the field, providing guidance to the client on what to enter.regexp
: A regular expression pattern to validate the field's input, ensuring it meets the required format.regexp_error
: An error message to display if the client's input does not match the regular expression pattern.required
: A boolean flag indicating whether the field is required for the client to proceed.
The
i18n
function is used to translate text strings based on the client's language preference, ensuring a localized user experience.
API Query
The class MerchantName
should also define a method to query the merchant's API for payment processing or order status updates or any other necessary data.
Parameters:
method_name
: The name of the API method to call, including the HTTP method (e.g.,POST:/payment
).data
: The data to send in the API request, such as payment details or order information.The
api_query
method constructs an API request to the merchant's endpoint using the provided method name and data.The method extracts the API key and debug mode settings from the merchant's configuration.
The method sends an HTTP request to the merchant's API endpoint, handling success and error responses accordingly.
The method returns the response data from the API, ensuring that the necessary data is processed and available for further use.
The method also includes error handling logic to manage various types of API request failures and provide descriptive error messages.
Process Payment
The class MerchantName
should define a method to process a payment request from the client, including validating the payment details and interacting with the merchant's API.
The create_payment
method should handle the payment processing logic, including validating the payment details, generating a payment request, and interacting with the merchant's API to process the payment.
The method should return a payment object containing the payment error status, order ID, and merchant specific data.
Parameters:
order
: The order object containing the payment details, such as the amount, currency, and order ID.order.status
: The status of the order, indicating whether the payment is pending or in progress.order._id
: The unique identifier for the order, used to track the payment request.order.uid
: The order UID, which is typically a unique identifier for the payment transaction.order.amount
: The payment amount in the order's currency.order.route
: The currency route for the payment, including the source and destination currencies.order.lang
: The language code for the client's preferred language.
The
create_payment
method first checks the order's status to determine if the payment processing is required.The method retrieves the merchant-specific data for the order, such as the payment URL and currency provider.
If the merchant data is not available, the method constructs a payment request and interacts with the merchant's API to process the payment.
The method handles errors and returns a payment object containing the payment status, order ID, and merchant-specific data.
The method also updates the order's merchant data with the payment details, ensuring that the payment status is tracked correctly.
The method returns the payment object, which includes the payment error status, order ID, and merchant-specific data.
It is also recommended to include an
order._id
field in the merchant data to link the payment details to the order, so the system can track the payment status correctly.
URL Status
The class MerchantName
should define a method to handle the URL status endpoint(Webhook), which receives updates from the merchant's API regarding the payment status.
The url_status
method should process the incoming data from the merchant's API, update the order status accordingly, and return a response to the merchant.
Parameters:
req
: The express request object containing the incoming data from the merchant's API.res
: The express response object used to send a response back to the merchant's API.param
: The parameters object containing the parsed request data, such aspost
for POST data andget
for query parameters.The
url_status
method processes the incoming data from the merchant's API, updating the order status based on the payment status.The method validates the request method, authorization header, and order ID to ensure the request is legitimate. If the merchant have a signature, API key, or other security measures, they should be checked here.
The method retrieves the order details based on the order ID which we specify in the
create_payment
method.The method checks the payment module status to ensure that the payment processing is valid and secure using the
checkPaymentModule
method.The method validates the payment status, amount, and order status to ensure that the payment is successful and matches the expected values.
If the
currency
is passed in the request, it is compared with the expected currency to ensure that the payment currency matches the order currency.If the payment
amount
is less than the expected amount orstatus
is not success or done or approved , an error is logged, and the order status is updated toerrorPayment
to reflect the payment error.If the payment is successful, the order status is updated to
inProgressPayout
, indicating that the payment is being processed.this.API.call
: A method to call the system's API to update the order status based on the payment processing results.server/exchanger/order/update-status
: The API endpoint to update the order status in the system.orderId
: The unique identifier for the order, used to identify the order to update.status
: The new status to set for the order, such asinProgressPayout
orerrorPayment
.comment
: A comment to log with the order status update, providing context for the status change and this comment is displayed in the order history for the administrator.
The method returns a response to the merchant's API, indicating the order UID and payment status, such as
success
or an error message.
Optional Methods
The MerchantName
class can also define additional methods to handle specific merchant logic, such as getting the currency by XML, getting the network by XML, or signature validation.
XML
is used to determine the currency provider for the order, it is a standard representation of the currency. Sites like jsons.info and bestchange.com can be used to get the XML of the currency.getCurrencyByXML
method returns the currency based on the XML provided, such asUSDTERC20
for USDT orBTC
for Bitcoin.getNetworkByXML
method returns the network based on the XML provided, such asETH
for Ethereum orBTC
for Bitcoin.
Export
The index.js
file should export the MerchantName
class so that it can be used by the system to interact with the merchant plugin.
The
module.exports
statement exports theMerchantName
class, making it available for use by the system to process payments, update order statuses, and handle payment processing logic.
Last updated