Getting Started
Getting Started
Install the J-Pay Server SDK, initialize the API client, and start calling payment, payout, and agency APIs.
Getting Started with J-Pay API
Introduction
Php API SDK for J-Pay payment gateway
Installation
With Composer
composer require jpay-api/php-sdk
{
"require": {
"jpay-api/php-sdk": "~1.0"
}
}
Initialize the API Client
Note: Documentation for the client can be found here.
The following parameters are configurable for the API Client:
| Parameter | Type | Description |
|---|---|---|
| apiKey | string | Merchant API key for automatic MD5 request signing on Payments API calls. |
| environment | Environment | The API environment. <br> Default: Environment.SANDBOX |
| timeout | int | Timeout for API calls in seconds.<br>Default: 30 |
| enableRetries | bool | Whether to enable retries and backoff feature.<br>Default: false |
| numberOfRetries | int | The number of retries to make.<br>Default: 0 |
| retryInterval | float | The retry time interval between the endpoint calls.<br>Default: 1 |
| backOffFactor | float | Exponential backoff factor to increase interval between retries.<br>Default: 2 |
| maximumRetryWaitTime | int | The maximum wait time in seconds for overall retrying requests.<br>Default: 0 |
| retryOnTimeout | bool | Whether to retry on request timeout.<br>Default: true |
| httpStatusCodesToRetry | array | Http status codes to retry against.<br>Default: 408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524 |
| httpMethodsToRetry | array | Http methods to retry against.<br>Default: 'GET', 'PUT', 'GET', 'PUT' |
| loggingConfiguration | LoggingConfigurationBuilder | Represents the logging configurations for API calls |
| proxyConfiguration | ProxyConfigurationBuilder | Represents the proxy configurations for API calls |
| verifyPeer | bool | Whether to verify SSL certificates.<br>Default: true |
| verifyHost | bool | Whether to verify SSL host names.<br>Default: true |
The API client can be initialized as follows:
use JPayApiLib\Logging\LoggingConfigurationBuilder;
use JPayApiLib\Logging\RequestLoggingConfigurationBuilder;
use JPayApiLib\Logging\ResponseLoggingConfigurationBuilder;
use Psr\Log\LogLevel;
use JPayApiLib\Environment;
use JPayApiLib\JPayApiClientBuilder;
$client = JPayApiClientBuilder::init()
->apiKey('your-merchant-api-key')
->environment(Environment::SANDBOX)
->loggingConfiguration(
LoggingConfigurationBuilder::init()
->level(LogLevel::INFO)
->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true))
->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true))
)
->build();
Environments
The SDK can be configured to use a different environment for making API calls. Available environments are:
Fields
| Name | Description |
|---|---|
| SANDBOX | Sandbox (Default) |
| PRODUCTION | Production |
Request Models & Builders
Each API endpoint supports typed request models with fluent builders aligned to the OpenAPI spec. All parameters use string types as defined in the API.
use JPayApiLib\Models\Requests\Builders\CreatePayoutRequestBuilder;
$request = CreatePayoutRequestBuilder::init()
->orderType('BANK')
->memberid('10153')
->outTradeNo('PO20260101001')
->amount('100.00')
->currency('USD')
->notifyurl('https://example.com/payout/notify')
->remark('Salary payout')
->firstname('John')
->payeeCountry('US')
->payeeaccount('1234567890')
->bankcode('001')
->bankname('Test Bank')
->build();
$response = $client->getPayoutsApi()->createFromRequest($request);
/** @var \JPayApiLib\Models\ApiV1PaymentCreateOrderResponse $result */
$result = $response->getResult();
Response models are automatically deserialized (e.g. PayTradeQueryResponse, PaymentResponse).
Automatic Request Signing
When apiKey is configured, PaymentsApi automatically generates the MD5 signature (pay_md5sign) before sending outbound requests. You do not need to set payMd5Sign manually unless you want to override the computed value.
Signing follows the J-Pay signature algorithm: non-empty sign fields are sorted by name, joined as key=value&..., appended with &key={apiKey}, then MD5-hashed in uppercase.
For card payment creation (POST /pay_index), the signed fields are: pay_memberid, pay_orderid, pay_applydate, pay_bankcode, pay_notifyurl, pay_callbackurl, pay_amount.
List of APIs
SDK Infrastructure
Configuration
- ProxyConfigurationBuilder
- LoggingConfigurationBuilder
- RequestLoggingConfigurationBuilder
- ResponseLoggingConfigurationBuilder
HTTP
- HttpRequest
Utilities
- FileWrapper
- ApiResponse