Skip to main content

Getting Started

Server SDK

Getting Started

Install the J-Pay Server SDK, initialize the API client, and start calling payment, payout, and agency APIs.

Language
jpay-api/php-sdk

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:

ParameterTypeDescription
apiKeystringMerchant API key for automatic MD5 request signing on Payments API calls.
environmentEnvironmentThe API environment. <br> Default: Environment.SANDBOX
timeoutintTimeout for API calls in seconds.<br>Default: 30
enableRetriesboolWhether to enable retries and backoff feature.<br>Default: false
numberOfRetriesintThe number of retries to make.<br>Default: 0
retryIntervalfloatThe retry time interval between the endpoint calls.<br>Default: 1
backOffFactorfloatExponential backoff factor to increase interval between retries.<br>Default: 2
maximumRetryWaitTimeintThe maximum wait time in seconds for overall retrying requests.<br>Default: 0
retryOnTimeoutboolWhether to retry on request timeout.<br>Default: true
httpStatusCodesToRetryarrayHttp 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
httpMethodsToRetryarrayHttp methods to retry against.<br>Default: 'GET', 'PUT', 'GET', 'PUT'
loggingConfigurationLoggingConfigurationBuilderRepresents the logging configurations for API calls
proxyConfigurationProxyConfigurationBuilderRepresents the proxy configurations for API calls
verifyPeerboolWhether to verify SSL certificates.<br>Default: true
verifyHostboolWhether 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

NameDescription
SANDBOXSandbox (Default)
PRODUCTIONProduction

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