NAV Navbar
Logo
php

Introduction

Welcome to duitku API, you can use this API to integrate with your website.

Request Transaction

<?php
    $merchantCode = 'YOUR_MERCHANT_CODE_HERE'; // from duitku
    $merchantKey = 'YOUR_MERCHANT_KEY_HERE'; // from duitku
    $paymentAmount = '40000';
    $paymentMethod = 'VC'; // WW = duitku wallet, VC = Credit Card, MY = Mandiri Clickpay, BK = BCA KlikPay
    $merchantOrderId = time(); // from merchant, unique
    $productDetails = 'Test Pay with duitku';
    $email = '[email protected]'; // your customer email
    $phoneNumber = '08123456789'; // your customer phone number (optional)
    $additionalParam = ''; // optional
    $merchantUserInfo = ''; // optional
    $customerVaName = 'John Doe'; // display name on bank confirmation display
    $callbackUrl = 'http://example.com/callback'; // url for callback
    $returnUrl = 'http://example.com/return'; // url for redirect
    $expiryPeriod = '10'; // set the expired time in minutes

    $signature = md5($merchantCode . $merchantOrderId . $paymentAmount . $merchantKey);

    $item1 = array(
        'name' => 'Test Item 1',
        'price' => 10000,
        'quantity' => 1);

    $item2 = array(
        'name' => 'Test Item 2',
        'price' => 30000,
        'quantity' => 3);

    $itemDetails = array(
        $item1, $item2
    );

    $params = array(
        'merchantCode' => $merchantCode,
        'paymentAmount' => $paymentAmount,
        'paymentMethod' => $paymentMethod,
        'merchantOrderId' => $merchantOrderId,
        'productDetails' => $productDetails,
        'additionalParam' => $additionalParam,
        'merchantUserInfo' => $merchantUserInfo,
        'customerVaName' => $customerVaName,
        'email' => $email,
        'phoneNumber' => $phoneNumber,
        'itemDetails' => $itemDetails,
        'callbackUrl' => $callbackUrl,
        'returnUrl' => $returnUrl,
        'signature' => $signature,
	'expiryPeriod' => $expiryPeriod
    );

    $params_string = json_encode($params);
    $url = 'https://sandbox.duitku.com/webapi/api/merchant/v2/inquiry'; // Sandbox
    // $url = 'https://passport.duitku.com/webapi/api/merchant/v2/inquiry'; // Production
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($params_string))                                                                       
    );   
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    //execute post
    $request = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if($httpCode == 200)
    {
        $result = json_decode($request, true);
        header('location: '. $result['paymentUrl']);
        echo "paymentUrl :". $result['paymentUrl'] . "<br />";
        echo "merchantCode :". $result['merchantCode'] . "<br />";
        echo "reference :". $result['reference'] . "<br />";
	echo "vaNumber :". $result['vaNumber'] . "<br />";
	echo "amount :". $result['amount'] . "<br />";
	echo "statusCode :". $result['statusCode'] . "<br />";
	echo "statusMessage :". $result['statusMessage'] . "<br />";
    }
    else
        echo $httpCode;
?>

The above command returns JSON structured like this:

{
  "merchantCode": "sample string 1",
  "reference": "sample string 2",
  "paymentUrl": "sample string 3",
  "vaNumber": "sample string 4",
  "amount": "sample string 6",
  "statusCode": "sample string 7",
  "statusMessage": "sample string 8"
}

You can create an inquiry transaction with this API.

HTTP Request

Method : HTTP POST

Type : application/json

Development : POST https://sandbox.duitku.com/webapi/api/merchant/v2/inquiry

Production : POST https://passport.duitku.com/webapi/api/merchant/v2/inquiry

Parameters

Parameter Type Required Description Example
merchantCode string(50) Y Merchant Code from duitku D0010
paymentAmount integer Y Payment Amount 150000
merchantOrderId string(50) Y Order Id from Merchant abcde12345
productDetails string(255) Y Product Detail Payment for A shop
email string{255} Y your customer email [email protected]
additionalParam string(255) N additional parameter(optional)
paymentMethod string(2) Y Payment Method BK / VC / BT
merchantUserInfo string(255) N Username or email customer (optional) [email protected]
customerVaName string(20) N The name that will appear on the bank's payment confirmation page John Doe
phoneNumber string(50) N customer phoneNumber (optional) 08123456789
itemDetails Object N Item Details (optional)
returnUrl string(255) Y Url for redirect when transaction is finish or canceled http://www.example.com/return
callbackUrl string(255) Y Url for transaction Callback http://www.example.com/callback
signature string(255) Y Signature Formula: MD5(merchantcode + orderId + amount + merchantKey)
expiryPeriod int N The validity period of the transaction before it expires 5, 10 or 60 (in minute)

Duitku uses merchantCode and merchantKey to allow access to the API. You can register a new merchantCode at our Merchant Portal.

For Fixed and open amount VA Documentation, you can download here download link.

Callback

<?php
$apiKey = 'YOUR_MERCHANT_KEY_HERE'; // Your api key
$merchantCode = isset($_POST['merchantCode']) ? $_POST['merchantCode'] : null; 
$amount = isset($_POST['amount']) ? $_POST['amount'] : null; 
$merchantOrderId = isset($_POST['merchantOrderId']) ? $_POST['merchantOrderId'] : null; 
$productDetail = isset($_POST['productDetail']) ? $_POST['productDetail'] : null; 
$additionalParam = isset($_POST['additionalParam']) ? $_POST['additionalParam'] : null; 
$paymentMethod = isset($_POST['paymentCode']) ? $_POST['paymentCode'] : null; 
$resultCode = isset($_POST['resultCode']) ? $_POST['resultCode'] : null; 
$merchantUserId = isset($_POST['merchantUserId']) ? $_POST['merchantUserId'] : null; 
$reference = isset($_POST['reference']) ? $_POST['reference'] : null; 
$signature = isset($_POST['signature']) ? $_POST['signature'] : null; 


if(!empty($merchantCode) && !empty($amount) && !empty($merchantOrderId) && !empty($signature))
{
    $params = $merchantCode . $amount . $merchantOrderId . $apiKey;
    $calcSignature = md5($params);

    if($signature == $calcSignature)
    {
        //Your code here
        
	if($resultCode == "00")
	{
	   echo "SUCCESS"; // Save to database
   	}
	else
        {
            echo "FAILED"; // Please update the status to FAILED in database
        }
    }
    else
    {
        throw new Exception('Bad Signature');
    }
}
else
{
    throw new Exception('Bad Parameter');
}
?>

Return values are returned as HTTP POST, Merchant will need to provide a call-back page to catch the result.

Parameters

Method : HTTP POST

Type : x-www-form-urlencoded

Parameter Description Example
merchantCode Merchant Code from duitku D0010
paymentAmount Payment Amount 150000
merchantOrderId Order Id from Merchant abcde12345
productDetail Product Detail Payment for A shop
additionalParam additional parameter(optional)
paymentCode Payment Method WW
resultCode Payment status 00 - Success
01 - Failed
merchantUserId User id from merchant [email protected]
reference Reference from duitku, Please save this to trace the transaction ABCEDE
signature Signature Formula: MD5(merchantcode + amount + merchantOrderId + merchantKey)

Redirect

After the transaction is finish or cancel, Duitku will redirect the customer back to merchant website with the following parameters.

Example

GET: http://www.merchantweb.com/redirect.php?merchantOrderId=xxx&resultCode=yyy&reference=zzz

Parameters

Parameter Description Example
merchantOrderId Order Id from merchant abcde12345
reference Reference from duitku d011111
resultCode Result Code 00 - Success
01 - Pending
02 - Canceled

Check Transaction

<?php
    $merchantCode = 'YOUR_MERCHANT_CODE_HERE'; // from duitku
    $merchantKey = 'YOUR_MERCHANT_KEY_HERE'; // from duitku
    $merchantOrderId = '1234'; // from merchant, unique

    $signature = md5($merchantCode . $merchantOrderId . $merchantKey);

    $params = array(
        'merchantCode' => $merchantCode,
        'merchantOrderId' => $merchantOrderId,
        'signature' => $signature
    );

    $params_string = json_encode($params);
    $url = 'http://sandbox.duitku.com/webapi/api/merchant/transactionStatus';
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($params_string))                                                                       
    );   
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    //execute post
    $request = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if($httpCode == 200)
    {
        $result = json_decode($request, true);
    }
    else
        echo $httpCode;
?>

The above command returns JSON structured like this:

{
  "merchantOrderId": "sample string 1",
  "reference": "sample string 2",
  "amount": "sample string 3",
  "statusCode": "sample string 4",
  "statusMessage": "sample string 5"
}

This API is for merchant to request for resending of transaction data in post back form.

This function will be optional to Merchant. This function may be used in any stage after performing the Transaction Request method.

HTTP Request

Development :

POST: http://sandbox.duitku.com/webapi/api/merchant/transactionStatus

Production :

POST: https://passport.duitku.com/webapi/api/merchant/transactionStatus

Parameters

Parameter Description Example
merchantCode Merchant Code from duitku D0010
merchantOrderId Order Id from Merchant abcde12345
signature Signature md5(merchantCode + merchantOrderId + merchantKey)

JSON Object

Collection of JSON objects.

Item Details

"itemDetails": [{
    "price": 50000,
    "quantity": 2,
    "name": "Apel",
  }]
Parameter Type Required Description Example
name string(50) Y Name of the item Item 1
quantity integer Y Quantity of the item bought 10
price integer Y Price of the Item Note: Don’t add decimal

Payment Method

Payment method available on duitku.

Payment Method Description
VC Credit Card (Visa / Master)
BK BCA KlikPay
M1 Mandiri Virtual Account
BT Permata Bank Virtual Account
B1 CIMB Niaga Virtual Account
A1 ATM Bersama
I1 BNI Virtual Account
VA Maybank Virtual Account
FT Ritel
OV OVO

Result Code

Collection of JSON objects.

Callback

Result Code Description
00 Success
01 Failed

Redirect

Result Code Description
00 Success
01 Pending / Failed
02 Canceled

Testing

Here is a list of dummy transaction credentials that can be used for transaction in the Sandbox Environment:

Credit Card

3D Secure Transaction

Card Type Credit Card Number Valid Thru CVV
VISA 4000 0000 0000 0044 02/22 123
MASTERCARD 5500 0000 0000 0004 02/22 123

Virtual Account

Demo transaction virtual account sandbox Link

Changelog

Version 2.0

Jan 2019

Version 1.0

php