### cURL Example: Add BIDV Bank Account Source: https://docs.pay2s.vn/partner/bank Example cURL command to add a BIDV bank account using the OpenAPI specification. Demonstrates POST request with required headers and JSON body. ```bash curl -X POST https://api-partner.pay2s.vn/v1/banks -H "Authorization: Bearer " -H "Content-Type: application/json" -d '{ "type": "openapi", "bankShortName": "BIDV", "accountNumber": "8810281999", "cccd": "068095012120", "merchantId": "VYTEOO1", "accName": "NGUYEN TRONG VY", "accMobile": "0708077478", "accEmail": "trongvy.nguyen@gmail.com" }' ``` -------------------------------- ### List Pay2S Webhooks (Bash) Source: https://docs.pay2s.vn/partner/webhook This code example shows how to retrieve a list of all currently configured webhooks for your account. It requires your authorization token to authenticate the request to the Pay2S API. ```bash curl -X GET https://api-partner.pay2s.vn/v1/webhooks \ -H "Authorization: Bearer " ``` -------------------------------- ### List Existing Webhooks (GET) Source: https://docs.pay2s.vn/partner/webhook Retrieve a list of all webhooks currently configured for your account. The response includes details for each webhook, such as its ID, associated bank account, URL, type, status, and timestamps. ```json { "status": true, "data": [ { "id": 101, "user_bank_id": 25, "webhook_url": "https://merchant-domain.com/pay2s/handler", "type": "IN", "status": 1, "token": "e3a19a5a65a48ff3b3ef198fcb2a5a6c", "created_at": "2025-10-14 10:00:12", "updated_at": "2025-10-14 10:00:12", "bankName": "ACB", "accountNumber": "19354957" } ] } ``` -------------------------------- ### GET /v1/webhooks Source: https://docs.pay2s.vn/partner/webhook Retrieve a list of all registered webhooks for the authenticated partner account. Returns detailed information about each webhook including status, associated bank account, and creation timestamps. ```APIDOC ## GET /v1/webhooks ### Description Retrieve a complete list of all webhooks registered for the partner account. ### Method GET ### Endpoint https://api-partner.pay2s.vn/v1/webhooks ### Headers - **Authorization** (string) - Required - Bearer token authentication - **Content-Type** (string) - Required - application/json ### Response #### Success Response (200) - **status** (boolean) - Request status - **data** (array) - Array of webhook objects - **id** (integer) - Webhook ID - **user_bank_id** (integer) - Associated bank account ID - **webhook_url** (string) - Webhook endpoint URL - **type** (string) - Transaction type (IN, OUT, ALL) - **status** (integer) - Webhook status (1 = active, 0 = inactive) - **token** (string) - Webhook authentication token - **created_at** (string) - Creation timestamp - **updated_at** (string) - Last update timestamp - **bankName** (string) - Associated bank name - **accountNumber** (string) - Associated bank account number #### Response Example { "status": true, "data": [ { "id": 101, "user_bank_id": 25, "webhook_url": "https://merchant-domain.com/pay2s/handler", "type": "IN", "status": 1, "token": "e3a19a5a65a48ff3b3ef198fcb2a5a6c", "created_at": "2025-10-14 10:00:12", "updated_at": "2025-10-14 10:00:12", "bankName": "ACB", "accountNumber": "19354957" } ] } ``` -------------------------------- ### GET /v1/webhooks/history Source: https://docs.pay2s.vn/downloads/pay2s-partner Retrieve the complete history of webhook events and their delivery status. Shows all webhook invocations and responses. ```APIDOC ## GET /v1/webhooks/history ### Description Retrieve historical records of all webhook events including delivery attempts, responses, and status for troubleshooting and auditing purposes. ### Method GET ### Endpoint https://{{domain}}/v1/webhooks/history ### Authentication - **Type**: Bearer Token (JWT) ### Query Parameters - **page** (integer) - Optional - Page number for pagination (default: 1) - **limit** (integer) - Optional - Records per page (default: 20) - **webhook_id** (integer) - Optional - Filter by specific webhook ID - **status** (string) - Optional - Filter by delivery status (success, failed, pending) - **from_date** (string) - Optional - Start date for history range (ISO 8601 format) - **to_date** (string) - Optional - End date for history range (ISO 8601 format) ### Response #### Success Response (200) - **data** (array) - Array of webhook history records - **id** (integer) - History record ID - **webhook_id** (integer) - Associated webhook ID - **event_type** (string) - Type of payment event - **status** (string) - Delivery status (success, failed, pending) - **url** (string) - Webhook URL that was called - **request_body** (object) - Data sent in the webhook - **response_code** (integer) - HTTP response code - **response_body** (string) - Response from the webhook endpoint - **sent_at** (timestamp) - When webhook was sent - **received_at** (timestamp) - When response was received - **pagination** (object) - **current_page** (integer) - Current page number - **total_pages** (integer) - Total number of pages - **total_records** (integer) - Total number of records ``` -------------------------------- ### Get Bank List Source: https://docs.pay2s.vn/partner/bank Retrieves the list of available banks from the Pay2s partner API. Requires bearer token authentication. Returns array of bank objects with their details and identifiers. ```bash curl -X GET "https://api-partner.pay2s.vn/v1/banks" \ -H "Authorization: Bearer " ``` -------------------------------- ### GET /v1/banks Source: https://docs.pay2s.vn/partner/bank Retrieves a list of supported banks available through the Pay2S platform. ```APIDOC ## GET /v1/banks ### Description Fetches a list of all banks that are supported and available for integration via the Pay2S API. ### Method GET ### Endpoint /v1/banks ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```bash curl -X GET "https://api-partner.pay2s.vn/v1/banks" -H "Authorization: Bearer " ``` ### Response #### Success Response (200) - **banks** (array) - A list of bank objects. - Each object contains: - **id** (integer) - The unique identifier for the bank. - **name** (string) - The full name of the bank. - **shortName** (string) - The short name or code for the bank. #### Response Example ```json { "banks": [ { "id": 1, "name": "Bank A", "shortName": "BANKA" }, { "id": 2, "name": "Bank B", "shortName": "BANKB" } ] } ``` ``` -------------------------------- ### POST /v1/webhooks Source: https://docs.pay2s.vn/partner/webhook Create a new webhook to receive automatic transaction notifications for a specific bank account. Specify the webhook URL and transaction type (IN, OUT, or ALL) to start receiving real-time notifications. ```APIDOC ## POST /v1/webhooks ### Description Create a new webhook endpoint to receive automatic transaction notifications (IN/OUT) for a specific bank account. ### Method POST ### Endpoint https://api-partner.pay2s.vn/v1/webhooks ### Headers - **Authorization** (string) - Required - Bearer token authentication - **Content-Type** (string) - Required - application/json ### Request Body - **user_bank_id** (integer) - Required - ID of the bank account to attach webhook (obtained from /v1/banks) - **webhook_url** (string) - Required - URL to receive transaction data - **type** (string) - Required - Transaction type to receive: IN, OUT, or ALL ### Request Example { "user_bank_id": 25, "webhook_url": "https://merchant-domain.com/pay2s/handler", "type": "IN" } ### Response #### Success Response (200) - **status** (boolean) - Webhook creation status - **message** (string) - Success message - **token** (string) - Unique webhook token for authentication #### Response Example { "status": true, "message": "Webhook đã được thêm thành công.", "token": "e3a19a5a65a48ff3b3ef198fcb2a5a6c" } ``` -------------------------------- ### Verify MoMo Payment Signature - ASP.NET Core Source: https://docs.pay2s.vn/api/payment-notification ASP.NET Core controller implementation for processing MoMo payment callbacks with HMAC SHA256 signature verification. Accepts redirect parameters via HTTP GET, constructs the raw hash string in specified order, computes HMAC SHA256 signature using .NET cryptography APIs, and validates against the returned m2signature to ensure transaction authenticity. ```csharp using System; using System.Security.Cryptography; using System.Text; using Microsoft.AspNetCore.Mvc; namespace Pay2SRedirect.Controllers { public class PaymentController : Controller { [HttpGet("redirect")] public IActionResult RedirectFromPay2S( string partnerCode, string orderId, string requestId, string amount, string orderInfo, string orderType, string transId, string resultCode, string message, string payType, string responseTime, string extraData, string m2signature) { string accessKey = ""; string secretKey = ""; var rawHash = $"accessKey={accessKey}&amount={amount}&message={message}&orderId={orderId}&orderInfo={orderInfo}&orderType={orderType}&partnerCode={partnerCode}&payType={payType}&requestId={requestId}&responseTime={responseTime}&resultCode={resultCode}"; var partnerSignature = CreateHmacSha256Signature(rawHash, secretKey); } } } ``` -------------------------------- ### Successful API Response with Data Source: https://docs.pay2s.vn/partner/authentication This is a sample JSON response for a successful API call after authentication. It includes a 'success' flag set to true and a 'data' array containing the requested information, such as bank details in this example. ```json { "success": true, "data": [ { "bank": "ACB", "accountNumber": "123456789", "status": "active" }, { "bank": "VCB", "accountNumber": "987654321", "status": "inactive" } ] } ``` -------------------------------- ### Generate Bearer Token using Basic Authentication Source: https://docs.pay2s.vn/partner/authentication This code snippet demonstrates how to generate a Bearer Token by using Basic Authentication with your Access Key and Secret Key. The Access Key and Secret Key are concatenated with a colon and then Base64 encoded. This encoded string is sent in the Authorization header for the `/v1/auth/authorize` endpoint. ```text access_key = "YOUR_ACCESS_KEY" secret_key = "YOUR_SECRET_KEY" # Concatenate keys credentials = f"{access_key}:{secret_key}" # Encode to Base64 import base64 encoded_credentials = base64.b64encode(credentials.encode()).decode() # Construct the Authorization header authorization_header = f"Basic {encoded_credentials}" # Example headers for the request headers = { "Authorization": authorization_header, "Content-Type": "application/json" } # The endpoint to call url = "https://api-partner.pay2s.vn/v1/auth/authorize" # Make the POST request (using a hypothetical library like 'requests') # response = requests.post(url, headers=headers) # print(response.json()) ``` -------------------------------- ### cURL Get Recent API Activity Logs Source: https://docs.pay2s.vn/partner/analytics Example cURL command to retrieve recent API activity logs from the Partner account with proper authorization header. ```bash curl -X GET https://partner.pay2s.vn/v1/metrics/logs \ -H "Authorization: Bearer " ``` -------------------------------- ### cURL Get Overall API Calls Statistics Source: https://docs.pay2s.vn/partner/analytics Example cURL command to retrieve overall API call statistics with bearer token authentication from Pay2S partner endpoint. ```bash curl -X GET https://partner.pay2s.vn/v1/metrics/calls \ -H "Authorization: Bearer " ``` -------------------------------- ### Sample Response for Creating a Webhook Source: https://docs.pay2s.vn/partner/webhook Upon successful creation of a webhook, the API will return a success status, a confirmation message, and a token associated with the new webhook. ```json { "status": true, "message": "Webhook đã được thêm thành công.", "token": "e3a19a5a65a48ff3b3ef198fcb2a5a6c" } ``` -------------------------------- ### GET /v1/banks Source: https://docs.pay2s.vn/partner/authentication Retrieve list of bank accounts using Bearer Token authentication. This is an example of a protected API endpoint that requires a valid Bearer Token obtained from the authorization endpoint. ```APIDOC ## GET /v1/banks ### Description Retrieve list of bank accounts associated with the authenticated partner account. Requires valid Bearer Token from authorization endpoint. ### Method GET ### Endpoint `https://api-partner.pay2s.vn/v1/banks` ### Headers - **Authorization** (string) - Required - Bearer {token} ### Request Example ``` GET /v1/banks HTTP/1.1 Host: api-partner.pay2s.vn Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.... ``` ### Response #### Success Response (200) - **success** (boolean) - Request success status - **data** (array) - Array of bank account objects - **bank** (string) - Bank code (e.g., ACB, VCB) - **accountNumber** (string) - Bank account number - **status** (string) - Account status (active/inactive) #### Response Example ```json { "success": true, "data": [ { "bank": "ACB", "accountNumber": "123456789", "status": "active" }, { "bank": "VCB", "accountNumber": "987654321", "status": "inactive" } ] } ``` ### Notes - Requires valid Bearer Token in Authorization header - Protected endpoint requiring prior authentication via /v1/auth/authorize ``` -------------------------------- ### GET /v1/metrics/status - Get System Status Source: https://docs.pay2s.vn/partner/analytics Checks the operational status of the Pay2S API system, including uptime, latency, and database status. ```APIDOC ## GET /v1/metrics/status ### Description Check the operational status of the Pay2S API system, including uptime, latency, and database status. ### Method GET ### Endpoint /v1/metrics/status ### Query Parameters None ### Request Body None ### Request Example Not provided, but similar to other GET requests: `curl -X GET https://partner.pay2s.vn/v1/metrics/status -H "Authorization: Bearer "` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the request was successful. - **data** (object) - Contains the system status details: - **uptime** (string) - The system uptime percentage. - **average_latency_ms** (integer) - The average latency in milliseconds. - **db_status** (string) - The status of the database. - **api_gateway** (string) - The status of the API gateway. - **last_check** (string) - The timestamp of the last system check. #### Response Example ```json { "status": true, "data": { "uptime": "99.98%", "average_latency_ms": 185, "db_status": "OK", "api_gateway": "Operational", "last_check": "2025-10-14T13:30:00+07:00" } } ``` ``` -------------------------------- ### Sample Response for Updating a Webhook Source: https://docs.pay2s.vn/partner/webhook Confirms that the webhook has been successfully updated with the new configuration. ```json { "status": true, "message": "Webhook đã được cập nhật thành công." } ``` -------------------------------- ### Pay2S Sandbox Environment Source: https://docs.pay2s.vn/api/tich-hop-ky-thuat Information about the Pay2S sandbox environment for testing purposes. This includes the website URL, API endpoint, and links for creating virtual transactions and IPN requests. ```APIDOC ## Pay2S Sandbox Information ### Description Information about the Pay2S sandbox environment for testing purposes. This includes the website URL, API endpoint, and links for creating virtual transactions and IPN requests. ### Website Sandbox `https://sandbox.pay2s.vn` ### API EndPoint (Sandbox) `https://sandbox-payment.pay2s.vn` ### Create Virtual Transaction `https://sandbox.pay2s.vn/demo/transfer_demo.html` ### Initialize IPN `https://sandbox.pay2s.vn/demo/ipn_demo.html` ``` -------------------------------- ### GET /v1/metrics/period - Get Statistics by Period Source: https://docs.pay2s.vn/partner/analytics Fetches statistics aggregated by a specified period (daily, weekly, or monthly). Useful for observing trends over time. ```APIDOC ## GET /v1/metrics/period ### Description Get statistics aggregated by a specified period (daily, weekly, or monthly). ### Method GET ### Endpoint /v1/metrics/period ### Query Parameters - **range** (string) - Required - Specifies the time range for statistics. Allowed values: `daily`, `weekly`, `monthly`. ### Request Body None ### Request Example ```bash curl -X GET "https://partner.pay2s.vn/v1/metrics/period?range=daily" \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the request was successful. - **data** (array) - An array of statistics for the specified period: - **date** (string) - The date (or period identifier) for the statistics. - **calls** (integer) - The number of calls during that period. - **average_ms** (integer) - The average response time in milliseconds for that period. #### Response Example ```json { "status": true, "data": [ { "date": "2025-10-10", "calls": 42, "average_ms": 190 }, { "date": "2025-10-11", "calls": 55, "average_ms": 210 }, { "date": "2025-10-12", "calls": 45, "average_ms": 230 } ] } ``` ``` -------------------------------- ### PHP Payment Redirect Handler Source: https://docs.pay2s.vn/api/payment-notification This PHP script demonstrates how to handle the redirect from Pay2S VN, verify the transaction signature, and display the payment status. ```APIDOC ## GET /websites/pay2s_vn ### Description Handles the redirect from Pay2S VN after a payment attempt. It verifies the transaction signature using the provided keys and displays the payment status to the user. ### Method GET ### Endpoint /websites/pay2s_vn ### Parameters #### Query Parameters - **partnerCode** (string) - Required - The partner code provided by Pay2S. - **orderId** (string) - Required - The unique order identifier. - **requestId** (string) - Required - The request identifier. - **amount** (string) - Required - The transaction amount. - **orderInfo** (string) - Required - Information about the order. - **orderType** (string) - Required - The type of the order. - **transId** (string) - Optional - The transaction ID from Pay2S. - **resultCode** (string) - Required - The result code of the transaction. - **message** (string) - Required - A message associated with the transaction result. - **payType** (string) - Required - The payment method used. - **responseTime** (string) - Required - The timestamp of the response. - **extraData** (string) - Optional - Additional data provided by the partner. - **m2signature** (string) - Required - The signature generated by Pay2S for verification. ### Request Example (No request body for GET requests) ### Response #### Success Response (200) Returns an HTML snippet indicating the payment status (Success or Failure). #### Response Example ```html
Payment status: Success
``` #### Error Response Returns an HTML snippet indicating an error, potentially due to a signature mismatch or a failed transaction. #### Error Response Example ```html
Payment status: Transaction failed
``` ``` -------------------------------- ### Get Webhook Call History (GET) Source: https://docs.pay2s.vn/partner/webhook Retrieve a history of all attempts made by Pay2S to send transaction notifications to your webhook endpoints. Includes details about the call time, status code, and response. ```json { "status": true, "data": [ { "id": 991, "webhook_id": 101, "endpoint": "https://merchant-domain.com/pay2s/handler", "status_code": 200, "status": 1, "call_time": "2025-10-14 11:00:00", "response": "Transactions sent successfully", "payload": { "transactions": [ { "id": 3521, "gateway": "ACB", "transactionDate": "2025-10-14 10:59:30", "transactionNumber": "FT253146879VN", "vaNumber": "963869789", "accountNumber": "19354957", "content": "NAPTIEN MOMO 963869789", "transferType": "IN", "transferAmount": 200000, "checksum": "a8e97b098f45f6e2dfdbf33d10d1dc4b" } ] } } ] } ``` -------------------------------- ### Create Pay2S Webhook (Bash) Source: https://docs.pay2s.vn/partner/webhook This snippet demonstrates how to create a new webhook subscription with the Pay2S API. It requires an authorization token and specifies the user bank ID, the webhook URL for receiving notifications, and the type of notifications ('IN' for incoming transactions). ```bash curl -X POST https://api-partner.pay2s.vn/v1/webhooks \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ \ "user_bank_id": 25, \ "webhook_url": "https://merchant-domain.com/pay2s/handler", \ "type": "IN" \ }' ``` -------------------------------- ### Get Webhook History Source: https://docs.pay2s.vn/downloads/pay2s-partner This snippet shows how to retrieve the history of webhook events. This is useful for auditing and debugging purposes, allowing you to see past notifications sent to your webhook URLs. It is a GET request to the /v1/webhooks/history endpoint. ```http GET /v1/webhooks/history Host: {{domain}} Authorization: Bearer ``` -------------------------------- ### GET /v1/metrics/logs - Get API Activity Logs Source: https://docs.pay2s.vn/partner/analytics Retrieves a list of the most recent API calls made by the partner. This log includes details like endpoint, method, response time, status code, and timestamp. ```APIDOC ## GET /v1/metrics/logs ### Description Returns a list of the most recent API calls made by the partner (Partner API). ### Method GET ### Endpoint /v1/metrics/logs ### Query Parameters None ### Request Body None ### Request Example ```bash curl -X GET https://partner.pay2s.vn/v1/metrics/logs \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the request was successful. - **data** (array) - An array of API log entries: - **id** (integer) - The unique ID of the log entry. - **endpoint** (string) - The API path that was called. - **method** (string) - The HTTP method used. - **response_ms** (integer) - The response time in milliseconds. - **status_code** (integer) - The HTTP status code of the response. - **timestamp** (string) - The timestamp of the API call. - **ip** (string) - The IP address from which the call was made. #### Response Example ```json { "status": true, "data": [ { "id": 1001, "endpoint": "/v1/banks", "method": "GET", "response_ms": 132, "status_code": 200, "timestamp": "2025-10-14T13:12:03+07:00", "ip": "103.78.2.55" }, { "id": 1002, "endpoint": "/v1/webhooks", "method": "POST", "response_ms": 254, "status_code": 500, "timestamp": "2025-10-14T13:13:05+07:00", "ip": "103.78.2.55" } ] } ``` ``` -------------------------------- ### POST /v1/gateway/api/create Source: https://docs.pay2s.vn/api/collection-link Creates a payment collection link for initiating orders. This endpoint validates merchant data, generates a payment link containing a VietQR code, and returns the link for customer redirection to Pay2S checkout page. ```APIDOC ## POST /v1/gateway/api/create ### Description Creates a payment collection link to initialize an order from the merchant's website or application to the Pay2S payment system. The endpoint validates the request data and returns a payment link containing a VietQR code for the customer to scan and complete the payment transaction. ### Method POST ### Endpoint https://payment.pay2s.vn/v1/gateway/api/create ### Headers - **Content-Type** (string) - Required - application/json; charset=UTF-8 ### Request Body - **accessKey** (string) - Required - API access key for authentication - **partnerCode** (string) - Required - Unique identifier for each partner - **partnerName** (string) - Optional - Partner name - **requestId** (string, max 50 characters) - Required - Unique identifier for each request - **amount** (long) - Required - Payment amount in VND (Vietnamese Dong) - **orderId** (string) - Required - Merchant's order ID - **orderInfo** (string) - Required - Order information (10-32 characters, alphanumeric only, no hyphens or special characters) - **orderType** (string) - Required - Type of order/request (e.g., "pay2s") - **bankAccounts** (array) - Required - Array of bank accounts with account_number and bank_id - **account_number** (string) - Bank account number - **bank_id** (string) - Bank code identifier (e.g., "ACB") - **redirectUrl** (string) - Required - URL to redirect customer after payment completion - **ipnUrl** (string) - Required - Webhook URL to receive payment result notifications - **requestType** (string) - Required - Request type identifier (e.g., "pay2s") - **signature** (string) - Required - HMAC_SHA256 signature for transaction verification. Format: sort the following string and apply HMAC_SHA256: accessKey=$accessKey&amount=$amount&bankAccounts=Array&ipnUrl=$ipnUrl&orderId=$orderId&orderInfo=$orderInfo&partnerCode=$partnerCode&redirectUrl=$redirectUrl&requestId=$requestId&requestType=$requestType ### Request Example ```json { "accessKey": "66e862c89d4d4d1f34063dc1967fbd64dece4da3cba90af65167fbb8503b2eb3", "partnerCode": "PAY2S7EPF0SB1ZP27W71", "partnerName": "Test Payment Woocommerce", "requestId": "1751916562", "amount": 2000, "orderId": "1173", "orderInfo": "TT1173", "orderType": "pay2s", "bankAccounts": [ { "account_number": "99999999", "bank_id": "ACB" } ], "redirectUrl": "https://demo-payment.pay2s.vn/wp/thanh-toan/order-received/1173/?key=wc_order_qrJlIwVAwIEfl", "ipnUrl": "https://demo-payment.pay2s.vn/wp/wc-api/WC_Gateway_Pay2S/", "requestType": "pay2s", "signature": "40cb7802b7d16bd08b1fc8d2a9f08d9df5efd785c7e7a6e817d8c7c4f71f165e" } ``` ### Response #### Success Response (200) - **status** (string) - Transaction status - **orderId** (string) - Merchant's order ID - **paymentLinkId** (string) - Payment link identifier - **paymentLink** (string) - Complete payment link URL containing VietQR code for customer ### Processing Flow 1. Customer selects online payment (Napas 247) on merchant website/application 2. Merchant system calls create payment link API; Pay2S validates data and returns payment link 3. Merchant redirects customer to Pay2S checkout page using returned payment link 4. Customer scans VietQR code using their banking application 5. Upon successful bank transaction, Pay2S returns result to redirectUrl with status, orderId, and paymentLinkId 6. Simultaneously, Pay2S sends complete payment information to ipnUrl webhook for merchant to update order status ### Error Handling - Validate all required parameters before sending request - Ensure orderInfo contains only alphanumeric characters (10-32 characters) - Verify HMAC_SHA256 signature is correctly calculated - Handle redirect and IPN callbacks to update order status appropriately ``` -------------------------------- ### GET /v1/metrics/calls - Get Overall API Call Statistics Source: https://docs.pay2s.vn/partner/analytics Retrieves statistics on the number of API calls made by a partner per day. This endpoint provides a summary of total calls, successful calls, and errors. ```APIDOC ## GET /v1/metrics/calls ### Description Returns statistics on the number of API calls made by the partner per day. ### Method GET ### Endpoint /v1/metrics/calls ### Query Parameters None ### Request Body None ### Request Example ```bash curl -X GET https://partner.pay2s.vn/v1/metrics/calls \ -H "Authorization: Bearer " ``` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the request was successful. - **data** (object) - Contains the statistics: - **total_calls** (integer) - Total number of API calls. - **success_calls** (integer) - Number of successful responses (HTTP 200). - **error_calls** (integer) - Number of errors (HTTP 4xx/5xx). - **average_response_ms** (integer) - Average response time in milliseconds. - **last_updated** (string) - The timestamp of the last update. #### Response Example ```json { "status": true, "data": { "total_calls": 142, "success_calls": 136, "error_calls": 6, "average_response_ms": 215, "last_updated": "2025-10-14T13:20:00+07:00" } } ``` ``` -------------------------------- ### Create Webhook API Source: https://docs.pay2s.vn/webhook/create-hook This API endpoint allows you to create a new webhook subscription. You need to select an account, choose an event, and provide the webhook endpoint URL. The system generates a unique token for data verification. ```APIDOC ## POST /webhooks ### Description Creates a new webhook subscription to receive transaction data from Pay2S. ### Method POST ### Endpoint /webhooks ### Parameters #### Query Parameters - **account_id** (string) - Required - The ID of the account for which the webhook is being created. - **event_type** (string) - Required - The type of transaction event to trigger the webhook (e.g., 'all', 'deposit', 'transfer'). - **webhook_url** (string) - Required - The URL endpoint that will receive the transaction data. Use http or https based on your website's SSL configuration. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **token** (string) - The unique token generated for this webhook, used for data verification. This token is displayed only once upon creation. #### Response Example { "token": "YOUR_UNIQUE_TOKEN_HERE" } ### Error Handling - If the account is not linked, the webhook creation will fail. - Invalid event types or URLs may result in errors. ``` -------------------------------- ### GET /v1/metrics/endpoints - Get Detailed Endpoint Statistics Source: https://docs.pay2s.vn/partner/analytics Provides detailed statistics for each API endpoint, helping to identify performance bottlenecks or high-frequency usage points. Includes call counts, success/failure rates, and average response times per endpoint. ```APIDOC ## GET /v1/metrics/endpoints ### Description View details of each API endpoint to identify performance bottlenecks or high usage frequency. ### Method GET ### Endpoint /v1/metrics/endpoints ### Query Parameters None ### Request Body None ### Request Example Not provided, but similar to other GET requests: `curl -X GET https://partner.pay2s.vn/v1/metrics/endpoints -H "Authorization: Bearer "` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the request was successful. - **data** (array) - An array of endpoint statistics: - **endpoint** (string) - The API path. - **method** (string) - The HTTP method (GET, POST, DELETE, etc.). - **calls** (integer) - Total number of calls. - **success** (integer) - Number of successful calls. - **failed** (integer) - Number of failed calls. - **average_ms** (integer) - Average response time in milliseconds. #### Response Example ```json { "status": true, "data": [ { "endpoint": "/v1/banks", "method": "GET", "calls": 85, "success": 82, "failed": 3, "average_ms": 130 }, { "endpoint": "/v1/webhooks", "method": "POST", "calls": 15, "success": 14, "failed": 1, "average_ms": 210 } ] } ``` ``` -------------------------------- ### Payment Notification - Client Redirect Source: https://docs.pay2s.vn/api/payment-notification After the payment flow is completed, the customer is redirected to the `redirectUrl` provided by the partner in the `create` request. Several parameters will be appended to the URL. ```APIDOC ## POST /websites/pay2s_vn/payment/notification ### Description Handles the client-side redirect after a payment is completed. The customer is directed to a pre-defined `redirectUrl` with transaction details appended. ### Method POST ### Endpoint /websites/pay2s_vn/payment/notification ### Parameters #### Query Parameters - **redirectUrl** (string) - Required - The URL provided by the partner to redirect the client to after payment. - **transactionDetails** (object) - Required - An object containing details about the transaction, appended to the redirectUrl. - **status** (string) - Required - The status of the transaction (e.g., 'success', 'failed'). - **transactionId** (string) - Required - The unique identifier for the transaction. - **amount** (number) - Required - The amount of the transaction. - **currency** (string) - Required - The currency of the transaction. ### Request Example ```json { "redirectUrl": "https://partner.com/payment/callback", "transactionDetails": { "status": "success", "transactionId": "txn_12345abcde", "amount": 100.50, "currency": "VND" } } ``` ### Response This endpoint does not return a response body as it initiates a client-side redirect. ``` -------------------------------- ### Create Webhook Source: https://docs.pay2s.vn/downloads/pay2s-partner This snippet demonstrates how to create a new webhook using the Pay2S API. It requires a user bank ID, a webhook URL for receiving notifications, and the type of events to subscribe to. The request is a POST request to the /v1/webhooks endpoint. ```http POST /v1/webhooks Host: {{domain}} Content-Type: application/json Authorization: Bearer { "user_bank_id": 410, "webhook_url": "https://merchant-domain.com/pay2s/callback", "type": "ALL" } ``` -------------------------------- ### Create a New Webhook (POST) Source: https://docs.pay2s.vn/partner/webhook Use this endpoint to register a new webhook for receiving transaction notifications. You need to provide the bank account ID, your webhook URL, and the type of transactions to monitor. ```json { "user_bank_id": 25, "webhook_url": "https://merchant-domain.com/pay2s/handler", "type": "IN" } ``` -------------------------------- ### POST /v1/webhooks Source: https://docs.pay2s.vn/downloads/pay2s-partner Create a new webhook for receiving payment notifications. Requires authentication via Bearer token and supports different event types. ```APIDOC ## POST /v1/webhooks ### Description Create a new webhook endpoint to receive notifications for payment events from Pay2S. ### Method POST ### Endpoint https://{{domain}}/v1/webhooks ### Authentication - **Type**: Bearer Token (JWT) - **Token**: Obtained from Pay2S partner portal ### Request Body - **user_bank_id** (integer) - Required - Bank user identifier - **webhook_url** (string) - Required - Callback URL to receive webhook events (e.g., https://merchant-domain.com/pay2s/callback) - **type** (string) - Required - Event type filter: "ALL", "IN", "OUT", etc. ### Request Example { "user_bank_id": 410, "webhook_url": "https://merchant-domain.com/pay2s/callback", "type": "ALL" } ### Response #### Success Response (201) - **id** (integer) - Webhook identifier - **user_bank_id** (integer) - Associated bank user ID - **webhook_url** (string) - Registered callback URL - **type** (string) - Event type filter - **is_active** (boolean) - Webhook status - **created_at** (timestamp) - Creation timestamp ``` -------------------------------- ### Get Bank Account Summary Source: https://docs.pay2s.vn/partner/bank Retrieves a summary of linked bank accounts, including counts per bank name/short name and the total number of accounts. ```json { "status": true, "bankCounts": [ { "bankName": "Vietcombank", "shortBankName": "VCB", "count": 2 }, { "bankName": "BIDV", "shortBankName": "BIDV", "count": 1 } ], "total": 3 } ``` -------------------------------- ### Add Bank Account (OpenAPI - BIDV) Source: https://docs.pay2s.vn/partner/bank Adds a bank account using the OpenAPI specification for BIDV. Requires bank details and merchant ID. Systems will send an OTP to confirm. ```json { "type": "openapi", "bankShortName": "BIDV", "accountNumber": "8810281999", "cccd": "068095012120", "merchantId": "VYTEOO1", "accName": "NGUYEN TRONG VY", "accMobile": "0708077478", "accEmail": "trongvy.nguyen@gmail.com" } ``` -------------------------------- ### List Webhooks Source: https://docs.pay2s.vn/partner/webhook Retrieve a list of all configured webhooks for your account. This endpoint does not require any specific parameters in the request body. ```APIDOC ## GET /v1/webhooks ### Description Retrieve a list of all configured webhooks. ### Method GET ### Endpoint /v1/webhooks ### Response #### Success Response (200) - **webhooks** (array) - A list of webhook objects. - Each object contains: **id** (integer), **user_bank_id** (integer), **webhook_url** (string), **type** (string), **token** (string). #### Response Example ```json { "webhooks": [ { "id": 123, "user_bank_id": 25, "webhook_url": "https://merchant-domain.com/pay2s/handler", "type": "IN", "token": "wh_secret_token_abc123" }, { "id": 124, "user_bank_id": 26, "webhook_url": "https://another-merchant.com/pay2s/callback", "type": "OUT", "token": "wh_secret_token_def456" } ] } ``` ```