Kembali ke Landing
Kembali
API Dokumentasi
API Dokumentasi
Pilih endpoint, copy URL/cURL/response, dan gunakan mode Live atau Sandbox.
SDK
PHP Library
AcePayment SDK
Integrasi paling cepat memakai library PHP resmi AcePayment. Library ini sudah menangani endpoint, header Authorization, dan verifikasi callback (HMAC-SHA256) secara otomatis.
AcePayment.php
<?php
namespace App\Libraries;
class AcePayment
{
protected $merchantCode, $apiKey, $privateKey;
protected $baseApiUrl = 'BASE_API_URL';
protected $params = [];
public $lastError = null;
public function __construct($baseApiUrl = null, $merchantCode = null, $apiKey = null, $privateKey = null)
{
$this->baseApiUrl = $baseApiUrl;
$this->merchantCode = $merchantCode;
$this->apiKey = $apiKey;
$this->privateKey = $privateKey;
return $this;
}
protected function makeRequest($endpoint, $method = 'GET', array $payload = [], array $headers = [])
{
$ch = curl_init();
$url = rtrim($this->baseApiUrl, '/') . '/' . ltrim($endpoint, '/');
if ($method === 'GET') {
$url .= (count($payload) ? '?' . http_build_query($payload) : '');
} else {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
}
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_FAILONERROR => false,
]);
$result = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
if ($errno) {
return json_encode(['success' => false, 'message' => $error]);
}
return $result;
}
public function set_param($name, $value) { $this->params[$name] = $value; return $this; }
public function set_params(array $value) { $this->params = $value; return $this; }
public function createTransaction()
{
return $this->makeRequest('/transaction/create', 'POST', $this->params, ['Authorization: Bearer ' . $this->apiKey]);
}
public function getTransaction($reference)
{
return $this->makeRequest('/transaction/detail', 'POST', ['reference' => $reference], ['Authorization: Bearer ' . $this->apiKey]);
}
public function getChannels($providerCode = null)
{
return $this->makeRequest('/payment-channel', 'GET', ['provider_code' => $providerCode], ['Authorization: Bearer ' . $this->apiKey]);
}
public function verifyCallback($verify = 0)
{
$json = file_get_contents("php://input");
$signature = hash_hmac('sha256', $json, $this->privateKey);
$callbackSignature = $_SERVER['HTTP_X_CALLBACK_SIGNATURE'] ?? '';
if (! hash_equals($signature, $callbackSignature)) {
$this->lastError = 'Invalid signature';
return false;
}
if ($verify == 1) {
$callback = json_decode($json);
if (! isset($callback->reference)) { $this->lastError = 'Invalid callback data'; return false; }
$cek = json_decode($this->getTransaction($callback->reference));
if ($cek->success === true) {
return $cek->data->reference == $callback->reference
&& $cek->data->merchant_reff == $callback->merchant_ref
&& $cek->data->amount == $callback->total_amount
&& $cek->data->payment_method == $callback->payment_method_code
&& $cek->data->status == $callback->status;
}
$this->lastError = $cek->message ?? 'Invalid callback data';
return false;
}
return true;
}
}
Contoh Penggunaan
<?php
// 1) Buat transaksi
$ace = new AcePayment(
'https://your-domain/api', // LIVE, atau .../api-sandbox untuk sandbox
'ACP0000000001', // kode merchant
'API_KEY_MERCHANT', // api key (live / sandbox)
'PRIVATE_KEY_MERCHANT' // private key (live / sandbox)
);
$result = $ace
->set_param('kodemerchant', 'ACP0000000001')
->set_param('merchantreff', 'INV-0001')
->set_param('providercode', 'BRIVA')
->set_param('amount', 10000)
->set_param('customer_name', 'Budi')
->set_param('customer_email', 'budi@mail.com')
->set_param('customer_phone', '081234567890')
->set_param('signature', hash_hmac('sha256', 'ACP0000000001INV-0001BRIVA10000', 'PRIVATE_KEY_MERCHANT'))
->createTransaction();
// 2) Cek detail / status
$detail = $ace->getTransaction('T0000000001');
// 3) List channel
$channels = $ace->getChannels(); // semua
$channels = $ace->getChannels('BRIVA'); // filter provider_code
// 4) Verifikasi callback (di endpoint callback merchant)
if ($ace->verifyCallback(1)) {
// callback valid, proses order
} else {
echo $ace->lastError;
}