Channel Params Request

API Overview

The Payment Form Dynamic Fields API is used to retrieve form field rules for specified payment channels. Different payment channels may require different mandatory fields. This API helps developers dynamically generate payment forms to ensure correct parameter submission.

API Information

Request URL: /channel/formRule Request Method: POST Content-Type: application/json

Request Parameters

ParameterRequiredTypeDescription
uidYesstringMerchant account
currencyYesstringCurrency
pay_codeYesstringPayment type code
timestampYesstringGMT timestamp
useripYesstringIP address of merchant member
signYesstring32-bit uppercase MD5 signature value

Request Example

{
    "uid": "test1",
    "currency": "VND",
    "pay_code": "812",
    "timestamp": 1758210270,
    "userip": "127.0.0.1",
    "sign": "200AF28BB3E4C4F0E93EBD48DB1FF623"
}

Response Parameters

Basic Response Structure

ParameterFieldTypeDescription
Status CodestatusintMore error codes see status code table
Response DataresultobjectReturns JSON string when status code is "Success"
MessagemessagestringReturn message
Data Signaturesignstring32-bit uppercase MD5 signature value

result.data Object Description

ParameterFieldTypeDescription
Payment Codepay_codestringPayment type code
Channel NamenamestringPayment channel name
Channel DescriptiondescriptionstringPayment channel description
Form Fieldsform_fieldsarrayForm field rules array

form_fields Field Description

ParameterFieldTypeDescription
Field NamenamestringField parameter name
Field LabellabelstringField display label
Field TypetypestringField type: input/select
RequiredrequiredbooleanWhether the field is mandatory
Max Lengthmax_lengthintMaximum length limit for the field
PlaceholderplaceholderstringInput field placeholder text
Options ListoptionsarrayDropdown options list (only has value when type is select)
Validation Rulesvalidation_rulesarrayField validation rules array

options Option Description

ParameterFieldTypeDescription
Bank IDbankIDintBank unique identifier
Bank NamenamestringBank display name

Response Examples

Success Response Example

{
    "status": 10000,
    "result": {
        "data": {
            "pay_code": "812",
            "name": "Bank Transfer",
            "description": "Payment through bank transfer",
            "form_fields": [
                {
                    "name": "pay_code",
                    "label": "Channel Code",
                    "type": "input",
                    "required": true,
                    "max_length": 100,
                    "placeholder": "",
                    "options": null,
                    "validation_rules": [
                        "required",
                        "string",
                        "max:100"
                    ]
                },
                {
                    "name": "bank_id",
                    "label": "Bank ID",
                    "type": "select",
                    "required": true,
                    "max_length": 100,
                    "placeholder": "Please select the corresponding Bank ID",
                    "options": [
                        {
                            "bankID": 6763,
                            "name": "AB Bank"
                        },
                        {
                            "bankID": 6764,
                            "name": "Asia Commercial Bank"
                        },
                        {
                            "bankID": 6788,
                            "name": "Vietcom Bank"
                        },
                        {
                            "bankID": 6789,
                            "name": "Vietin Bank"
                        }
                    ],
                    "validation_rules": [
                        "required",
                        "string",
                        "max:100"
                    ]
                }
            ]
        }
    },
    "message": "Successfully executed",
    "sign": "C2BBC28D47DB018175E884DAD30708D9"
}

Error Handling

When a request fails, the system will return the corresponding error status code. Common error codes include:

  • 10000: Success
  • 10001: Parameter Error
  • 10002: Signature Verification Failed
  • 10003: Payment Code Does Not Exist
  • 10004: Currency Not Supported
  • 10005: Merchant Account Does Not Exist

Use Cases

1. Dynamic Form Generation

// Get field rules
const formRules = await fetch('/channel/formRule', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        uid: 'test1',
        currency: 'VND',
        pay_code: '812',
        timestamp: Math.floor(Date.now() / 1000),
        userip: '127.0.0.1',
        sign: 'your_signature'
    })
});

const rules = await formRules.json();

// Dynamically generate form
rules.result.data.form_fields.forEach(field => {
    if (field.type === 'input') {
        // Generate input field
        createInputField(field);
    } else if (field.type === 'select') {
        // Generate select field
        createSelectField(field);
    }
});

2. Form Validation

// Validate form based on validation rules
function validateField(field, value) {
    const rules = field.validation_rules;
    
    if (rules.includes('required') && !value) {
        return `${field.label} is required`;
    }
    
    if (rules.includes('string') && typeof value !== 'string') {
        return `${field.label} must be a string`;
    }
    
    const maxRule = rules.find(rule => rule.startsWith('max:'));
    if (maxRule && value.length > parseInt(maxRule.split(':')[1])) {
        return `${field.label} cannot exceed ${maxRule.split(':')[1]} characters`;
    }
    
    return null; // Validation passed
}

Integration Recommendations

  1. Caching: Recommend caching field rules to avoid frequent requests
  2. Error Handling: Properly handle error messages returned by the API
  3. User Experience: Provide appropriate user interface based on field types
  4. Data Validation: Perform data validation on both client and server side
  5. Internationalization: Display corresponding field labels based on user language

Signature Algorithm

Signature generation rules:

  1. Sort all request parameters by parameter name ASCII code from small to large
  2. Concatenate into string using URL key-value pair format
  3. Add merchant secret key at the end of the string
  4. Perform MD5 encryption on the concatenated string
  5. Convert the encryption result to uppercase

Support

For technical support and questions, please contact our development team or refer to the complete API documentation.