Authentication
To access the MyPay API, you must first authenticate your requests using an Access Token.
Required Credentials
Obtain the following from the Merchant Dashboard before you start:
| Credential | Description |
|---|---|
| Client ID | Unique identifier for your application |
| Client Secret | Secret key for the client (keep confidential) |
| Base URL | API URL for the environment you are using (see Introduction) |
Getting an Access Token
Use this endpoint to obtain a valid bearer token for a specific period.
Endpoint: POST /authentication/token
Headers:
Content-Type: application/json
Request Body:
{
"client_id": "your_client_id_here",
"secret_id": "your_client_secret_here"
}
Success Response (200 OK)
{
"message": {
"code": 200,
"success": ["SUCCESS"]
},
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"expire_time": 600
},
"type": "success"
}
[!NOTE] Each
access_tokenis tied to one payment session (one call toPOST /payment/create). It is valid for 10 minutes (600 seconds). For a new order, request a new token viaPOST /authentication/token. Do not reuse a token across different orders.
Recommended Flow
- Call
POST /authentication/tokento obtain anaccess_token. - Call
POST /payment/createonce with that token. - Redirect the customer to the
payment_urlfrom the response. - For the next order, start again from step 1 with a new token.
Error Response (400 Bad Request)
{
"message": {
"code": 400,
"error": ["Invalid client ID"]
},
"data": {},
"type": "error"
}
Using the Token
After obtaining the Token, you must send it in the Authorization header with every subsequent API request:
Authorization: Bearer <your_access_token>