PAYLINK API

PayLink API Documentation

Dokumentasi PayLink Payment Gateway API — Staging & Production.

⚠️ Perbaikan dokumentasi (21 Okt 2026). Versi sebelumnya menuliskan payload create-invoice dengan camelCase (amount, productDetails, customerName, itemDetails, merchantOrderId, callbackUrl) dan respons yang dibungkus data. Itu tidak sesuai dengan implementasi. API ini memakai snake_case dan responsnya flat. Lihat bagian Perubahan Penting. Dokumen ini sekarang mengikuti kode, bukan sebaliknya.

📋 Daftar Isi

  1. Overview
  2. Alur Pembayaran
  3. Authentication
  4. Environment
  5. Daftar Endpoint
  6. 1. Get Payment Methods
  7. 2. Create Invoice
  8. 3. Payment Direct
  9. 4. Check Transaction Status
  10. Withdrawal API
  11. Response Format
  12. Status Codes & Error Handling
  13. Webhook Callback ke Merchant
  14. Contoh Implementasi
  15. Testing Checklist
  16. Perubahan Penting

Overview

PayLink API adalah payment gateway yang membungkus Duitku. Merchant cukup bicara ke PayLink — jangan memanggil Duitku secara langsung. Semua credential Duitku (merchant code & key) dipegang PayLink.

  • 200+ Payment Methods melalui Duitku
  • Create Invoice dengan payment method pilihan merchant (menghasilkan paymentUrl)
  • Payment Direct (pilih metode di halaman Duitku)
  • Transaction Tracking per merchant_order_id
  • Webhook callback ke URL merchant saat pembayaran selesai
  • Withdrawal API untuk penarikan saldo merchant

Alur Pembayaran

Merchant App
    │  1. POST /get-payment            (opsional: lihat metode + fee)
    │  2. POST /create-invoice         (pilih metode, kirim callback_url & return_url)
    ▼
PayLink API  ──3. teruskan ke──▶  Duitku
    ▲                                 │
    │  4. Duitku mengirim callback ───┘
    │     ke PayLink (/api/callback)
    │
    │  5. PayLink update status transaksi + saldo merchant
    │     lalu meneruskan callback ke callback_url merchant
    ▼
Merchant App  →  tandai order SUCCESS, beri layanan

Penting: callback_url yang Anda kirim saat create-invoice disimpan dan dipakai PayLink di langkah 5. Jadi status order di sisi Anda tetap update meskipun pengguna tidak kembali ke aplikasi.


Authentication

Semua endpoint /api/v1/* memerlukan:

X-Code-User: <code_user>
X-API-Key:   <api_key>
Content-Type: application/json

Credential diambil dari Dashboard PayLink → Settings → API Keys (Code User dan API Key).

Boleh juga dikirim di body sebagai code_user dan api_key, tetapi header lebih disarankan.

Jika credential salah/kosong, responsnya:

HTTP/1.1 401 Unauthorized
{"statusCode":"02","statusMessage":"User not found or invalid credentials"}

Catatan: kegagalan autentikasi memakai HTTP 401 (bukan 403), dengan statusCode "02".


Environment

Env Base URL Keterangan
Staging https://<domain>/api/v1/staging Uji coba (Duitku sandbox)
Production https://<domain>/api/v1/production Transaksi uang nyata

Ganti environment hanya pada path URL. Credential boleh sama, tetapi environment Duitku yang dipakai berbeda — kalau credential hanya terdaftar di production, panggilan ke /api/v1/staging akan ditolak.


Daftar Endpoint

POST /api/v1/staging/get-payment
POST /api/v1/staging/create-invoice
POST /api/v1/staging/payment-direct
GET  /api/v1/staging/check-transaction/{merchantOrderId}

POST /api/v1/production/get-payment
POST /api/v1/production/create-invoice
POST /api/v1/production/payment-direct
GET  /api/v1/production/check-transaction/{merchantOrderId}

POST /api/v1/withdrawal/create
GET  /api/v1/withdrawal/history
GET  /api/v1/withdrawal/balance

Semua contoh di bawah memakai /api/v1/production; untuk staging tinggal ganti path-nya.


1. Get Payment Methods

Melihat metode pembayaran yang tersedia beserta fee-nya untuk nominal tertentu.

Request

curl -X POST https://<domain>/api/v1/production/get-payment \
  -H "X-Code-User: MERCHANT_CODE" \
  -H "X-API-Key: ***" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 50000 }'
Parameter Type Required Keterangan
amount integer Yes Nominal (minimal 1000)

Response (200 OK) — hasil diteruskan apa adanya dari Duitku, diurutkan berdasarkan totalFee:

{
  "paymentFee": [
    {
      "paymentMethod": "SP",
      "paymentName": "ShopeePay",
      "paymentImage": "https://...",
      "totalFee": 500
    },
    {
      "paymentMethod": "VC",
      "paymentName": "Credit Card",
      "paymentImage": "https://...",
      "totalFee": 2500
    }
  ]
}

Ambil paymentMethod dari daftar ini untuk dipakai sebagai payment_method di create-invoice.

Kode metode QRIS

Kode Keterangan
SP ShopeePay (QRIS)
NQ QRIS (Nobu/issuer QRIS)
GQ QRIS alternatif
QR / QRIS alias QRIS

Daftar final tetap ikut hasil get-payment di akun Anda.


2. Create Invoice

Membuat invoice + paymentUrl yang bisa ditampilkan sebagai QRIS / link pembayaran.

Request

curl -X POST https://<domain>/api/v1/production/create-invoice \
  -H "X-Code-User: MERCHANT_CODE" \
  -H "X-API-Key: ***" \
  -H "Content-Type: application/json" \
  -d '{
    "payment_method": "SP",
    "payment_amount": 50000,
    "product_details": "Sawer Live @streamer",
    "email": "donor@example.com",
    "phone": "08123456789",
    "name": "John Doe",
    "items": [
      { "name": "Sawer Live", "price": 50000, "quantity": 1 }
    ],
    "merchant_order_id": "ORDER_001",
    "callback_url": "https://merchant.com/api/paylink/callback",
    "return_url": "https://merchant.com/success",
    "expiry_period": 1440
  }'

Parameter

Parameter Type Required Keterangan
payment_method string Yes Kode metode dari get-payment (mis. SP, NQ, VC)
payment_amount integer Yes Nominal dasar, minimal 1000
product_details string Yes Deskripsi produk/order
email string (email) Yes Email customer (untuk notifikasi)
phone string Yes Nomor HP customer
name string Yes Nama customer
items array No [{ name, price, quantity }]. Jika kosong, dibuat otomatis dari product_details
merchant_order_id string No ID order unik milik merchant. Jika kosong PayLink generate STAG_<timestamp>_<rand>
callback_url string (URL) No URL webhook yang menerima notifikasi status
return_url string (URL) No URL redirect setelah pembayaran. localhost otomatis diganti
first_name, last_name, address, city, postal_code, country_code string No Detail customer tambahan
additional_param string No Data bebas, dikembalikan pada callback Duitku
merchant_user_info string No Info user merchant
expiry_period integer No Masa berlaku invoice dalam menit (default 1440 = 24 jam)

Yang perlu diingat:

  • PayLink menambahkan fee admin ke nominal Duitku: paymentAmount = payment_amount + fee_admin, dan menambahkan satu baris item "Fee Transfer" ke itemDetails. Jadi nominal yang dibayar customer bisa lebih besar dari payment_amount.
  • Nomor telepon wajib bertipe string, contoh "08123456789" (jangan kirim sebagai angka mutlak tanpa tanda kutip).

Response (200 OK) — FLAT, bukan di dalam data

{
  "statusCode": "00",
  "statusMessage": "success",
  "merchantOrderId": "ORDER_001",
  "reference": "REF123456789",
  "paymentUrl": "https://app.duitku.com/pay/REF123456789",
  "transactionId": 99
}
Field Keterangan
statusCode "00" = invoice berhasil dibuat
merchantOrderId Sama dengan yang Anda kirim (atau yang digenerate PayLink)
reference Reference Duitku — dipakai juga pada callback (reference_code)
paymentUrl URL pembayaran / halaman QRIS yang ditampilkan ke customer
transactionId ID transaksi internal PayLink

paymentUrl ada di level atas. Jangan membaca data.paymentUrl.

Response gagal (contoh: metode tidak valid)

{ "statusCode": "02", "statusMessage": "Payment method XX is not available" }

Response gagal validasi — perhatikan, ini keluar sebagai HTTP 500 (exception tertangkap), bukan 422:

HTTP/1.1 500
{"statusCode":"02","statusMessage":"The payment method field is required."}

Kalau Anda menerima pesan The ... field is required., artinya payload Anda belum memakai snake_case/kontrak di atas.


3. Payment Direct

Sama seperti create invoice, tetapi metode pembayaran dipilih customer di halaman Duitku (merchant tidak mengirim payment_method).

POST /api/v1/production/payment-direct

Field wajib: payment_amount, product_details, email, phone, name. Field opsionalnya sama dengan Create Invoice. Format respons juga sama (flat).


4. Check Transaction Status

Cek status transaksi dari database PayLink.

GET /api/v1/production/check-transaction/{merchantOrderId}
curl -X GET "https://<domain>/api/v1/production/check-transaction/ORDER_001" \
  -H "X-Code-User: MERCHANT_CODE" \
  -H "X-API-Key: ***"

Response (200 OK)

{
  "merchantOrderId": "ORDER_001",
  "status": "success",
  "reference": "REF123456789"
}

status bernilai pending / success / failed. Jika order tidak dikenal:

HTTP/1.1 404
{"statusCode":"02","statusMessage":"Transaction not found in database"}

Withdrawal API

POST /api/v1/withdrawal/create
GET  /api/v1/withdrawal/history
GET  /api/v1/withdrawal/balance

Semua memakai header autentikasi yang sama (X-Code-User, X-API-Key).


Response Format

Sukses

{ "statusCode": "00", "statusMessage": "success", "...": "field spesifik endpoint" }

Error

{ "statusCode": "02", "statusMessage": "penjelasan error" }

Field data berada di level atas objek JSON — tidak ada pembungkus data.


Status Codes & Error Handling

Code Arti HTTP yang biasa muncul
00 Success 200
01 Unauthorized 401
02 Bad Request / Error (termasuk gagal autentikasi & validasi) 400/401/404/500
03 Forbidden 403
04 Not Found 404
99 Server Error 500

Error yang sering terjadi

Kasus Respons
Credential salah 401 {"statusCode":"02","statusMessage":"User not found or invalid credentials"}
Field wajib kurang 500 {"statusCode":"02","statusMessage":"The amount field is required."}
amount di bawah minimum 500 {"statusCode":"02","statusMessage":"The payment amount must be at least 1000."}
merchant_order_id duplikat {"statusCode":"02","statusMessage":"Merchant Order ID already exists"}
Metode tidak tersedia {"statusCode":"02","statusMessage":"Payment method XX is not available"}

Tips debugging: selalu log statusCode + statusMessage dari PayLink. 401 = kredensial, 404 = URL/endpoint salah, 500 + pesan field is required = payload belum sesuai kontrak, 500 + pesan lain = cek payment_method / config Duitku di sisi PayLink.


Webhook Callback ke Merchant

PayLink mengirim POST JSON ke callback_url yang Anda kirim saat create-invoice (header Content-Type: application/json, tanpa signature tambahan dari PayLink — verifikasi signature Duitku dilakukan di sisi PayLink).

Payload

{
  "merchant_order_id": "ORDER_001",
  "payment_method": "SP",
  "payment_amount": 50000,
  "reference_code": "REF123456789",
  "status": "success",
  "fee_potongan_admin": 49200,
  "fee_admin": 800
}
Field Keterangan
merchant_order_id ID order Anda
payment_method Kode metode yang dipakai
payment_amount Nominal dasar yang Anda minta (tanpa fee)
reference_code Reference Duitku
status huruf kecil: success / pending / failed
fee_admin Fee yang dipotong PayLink
fee_potongan_admin payment_amount - fee_admin → nominal bersih yang masuk saldo merchant

Nilai status

Status Arti Yang harus merchant lakukan
success Pembayaran berhasil Tandai order sukses, beri layanan
pending Belum dibayar / menunggu Jangan tandai gagal — tunggu callback berikutnya
failed Gagal / kedaluwarsa / dibatalkan Tandai order gagal

Yang wajib Anda lakukan di endpoint callback

  1. Cari order berdasarkan merchant_order_id.
  2. Idempoten: kalau order sudah success, jangan proses ulang (jangan tambah saldo/entitlement dua kali).
  3. Verifikasi nominal: payment_amount harus sama dengan nilai order Anda.
  4. Simpan reference_code sebagai jejak transaksi.
  5. Balas HTTP 200 (body apa pun, mis. OK). Selama respons bukan 2xx, PayLink menganggap pengiriman gagal.

Contoh (PHP/Laravel):

Route::post('/api/paylink/callback', function (Request $request) {
    $order = Order::where('merchant_order_id', $request->merchant_order_id)->firstOrFail();

    if ($order->status === 'success') {
        return response('OK', 200);           // idempoten
    }

    if ($request->payment_amount != $order->amount) {
        Log::warning('nominal tidak cocok', $request->all());
        return response('IGNORED', 200);
    }

    if ($request->status === 'success') {
        $order->update([
            'status' => 'success',
            'paid_at' => now(),
            'reference_code' => $request->reference_code,
        ]);
    } elseif ($request->status === 'failed') {
        $order->update(['status' => 'failed']);
    }
    // 'pending' -> tidak mengubah status order

    return response('OK', 200);
});

Contoh (Node.js/Express):

app.post('/api/paylink/callback', express.json(), async (req, res) => {
  const { merchant_order_id, payment_amount, status, reference_code } = req.body;
  const order = await Order.findOne({ merchant_order_id });

  if (!order) return res.status(200).send('IGNORED');
  if (order.status === 'success') return res.status(200).send('OK');

  if (Number(payment_amount) !== Number(order.amount)) {
    console.warn('nominal tidak cocok', req.body);
    return res.status(200).send('IGNORED');
  }

  if (status === 'success') {
    await order.update({ status: 'success', reference_code, paid_at: new Date() });
  } else if (status === 'failed') {
    await order.update({ status: 'failed' });
  }

  res.status(200).send('OK');
});

Contoh Implementasi

cURL lengkap (create invoice)

curl -X POST https://<domain>/api/v1/production/create-invoice \
  -H "X-Code-User: MERCHANT_CODE" \
  -H "X-API-Key: ***" \
  -H "Content-Type: application/json" \
  -d '{
    "payment_method": "SP",
    "payment_amount": 25000,
    "product_details": "Sawer Live @streamer: semangat!",
    "email": "donor@example.com",
    "phone": "08123456789",
    "name": "Budi Santoso",
    "items": [{ "name": "Sawer Live", "price": 25000, "quantity": 1 }],
    "merchant_order_id": "SAWER_1_1712345678_abcd",
    "callback_url": "https://app.example.com/api/paylink/callback",
    "return_url": "https://app.example.com/sawer/streamer?status=success"
  }'

PHP

$response = Http::withHeaders([
    'X-Code-User' => config('services.paylink.code_user'),
    'X-API-Key'   => config('services.paylink.api_key'),
    'Content-Type' => 'application/json',
])->timeout(15)->post(config('services.paylink.base_url').'/create-invoice', [
    'payment_method'    => 'SP',
    'payment_amount'    => 25000,
    'product_details'   => 'Sawer Live @streamer',
    'email'             => 'donor@example.com',
    'phone'             => '08123456789',
    'name'              => 'Budi Santoso',
    'items'             => [['name' => 'Sawer Live', 'price' => 25000, 'quantity' => 1]],
    'merchant_order_id' => $orderId,
    'callback_url'      => route('paylink.callback'),
    'return_url'        => route('sawer.show', $streamer) . '?status=success',
]);

$body = $response->json();

if ($response->successful() && ($body['statusCode'] ?? '') === '00' && !empty($body['paymentUrl'])) {
    return redirect($body['paymentUrl']);   // atau render QR dari paymentUrl
}

// Jangan telan alasan penolakannya!
Log::warning('PayLink menolak create-invoice', [
    'http' => $response->status(),
    'statusCode' => $body['statusCode'] ?? null,
    'statusMessage' => $body['statusMessage'] ?? null,
    'request' => ['payment_method' => 'SP', 'payment_amount' => 25000],
]);

JavaScript / Node.js

const res = await fetch(`${BASE_URL}/create-invoice`, {
  method: 'POST',
  headers: {
    'X-Code-User': process.env.PAYLINK_CODE_USER,
    'X-API-Key': process.env.PAYLINK_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    payment_method: 'SP',
    payment_amount: 25000,
    product_details: 'Sawer Live @streamer',
    email: 'donor@example.com',
    phone: '08123456789',
    name: 'Budi Santoso',
    items: [{ name: 'Sawer Live', price: 25000, quantity: 1 }],
    merchant_order_id: orderId,
    callback_url: 'https://app.example.com/api/paylink/callback',
    return_url: 'https://app.example.com/sawer/streamer?status=success',
  }),
});

const body = await res.json();
if (!res.ok || body.statusCode !== '00' || !body.paymentUrl) {
  console.error('PayLink gagal:', res.status, body);
  throw new Error(body.statusMessage || 'Gagal membuat invoice');
}
console.log('Bayar di:', body.paymentUrl);

Testing Checklist

  • X-Code-User + X-API-Key benar untuk environment yang dipakai
  • Nominal ≥ 1000
  • payment_method diambil dari hasil get-payment (bukan diketik asal)
  • email, phone, name, product_details terisi
  • merchant_order_id unik (duplikat akan ditolak)
  • callback_url bisa diakses publik dari internet (bukan localhost)
  • Endpoint callback idempoten + memverifikasi payment_amount
  • Endpoint callback membalas HTTP 200
  • Semua request memakai timeout dan hasilnya di-log (termasuk statusCode/statusMessage)

Perubahan Penting (breaking change pada dokumentasi)

Versi dokumen sebelumnya (camelCase) tidak pernah cocok dengan implementasi. Ringkasan perubahannya:

Hal Dokumen lama (❌) Yang benar (✅)
Gaya field amount, productDetails, customerName payment_amount, product_details, name
Metode bayar tidak disebut payment_method wajib (kode dari get-payment)
Item itemDetails[{name,price,quantity}] items[{name,price,quantity}]
Order ID / redirect merchantOrderId, callbackUrl, returnUrl merchant_order_id, callback_url, return_url
Email / telepon customerEmail, customerPhone email, phone
Respons create-invoice { data: { paymentUrl } } flat: { statusCode, paymentUrl, reference, ... }
Payload webhook camelCase + resultCode merchant_order_id, payment_amount, reference_code, status (huruf kecil)
status webhook — success / pending / failed
Path env /api/v1/sandbox /api/v1/staging

Kalau integrasi Anda masih memakai bentuk lama, ubah request create-invoice ke snake_case dan baca paymentUrl dari level atas — dua perubahan itu biasanya cukup.

📑 Daftar Isi