Welcome to Duitku PHP Example Project Implementation Page, Integrate this Duitku PHP to start transaction using Duitku in your Web or Application.
Go To Demo Duitku-PopGo To Demo Duitku-Api
Go To Duitku Docs Duitku-PopGo To Duitku Docs Duitku-Api
Install duitku-php with composer by following command:
composer require duitkupg/duitku-php:dev-master
or add it manually in your composer.json
file.
"duitkupg/duitku-php": "dev-master"
$duitkuConfig = new \Duitku\Config("YOUR_MERCHANT_KEY", "YOUR_MERCHANT_CODE");
// false for production mode
// true for sandbox mode
$duitkuConfig->setSandboxMode(false);
// set sanitizer (default : true)
$duitkuConfig->setSanitizedMode(false);
// set log parameter (default : true)
$duitkuConfig->setDuitkuLogs(false);
Parameter paymentMethod is optional,
You can put payment method('paymentMethod') on parameter createInvoice, as a step to set direct payment to specific payment. Customers will be directed to wanted payment without necessary to pick a payment.
// $paymentMethod = ""; // PaymentMethod list => https://docs.duitku.com/pop/id/#payment-method
$paymentAmount = 10000; // Amount
$email = "customer@gmail.com"; // your customer email
$phoneNumber = "081234567890"; // your customer phone number (optional)
$productDetails = "Test Payment";
$merchantOrderId = time(); // from merchant, unique
$additionalParam = ''; // optional
$merchantUserInfo = ''; // optional
$customerVaName = 'John Doe'; // display name on bank confirmation display
$callbackUrl = 'http://YOUR_SERVER/callback'; // url for callback
$returnUrl = 'http://YOUR_SERVER/return'; // url for redirect
$expiryPeriod = 60; // set the expired time in minutes
// Customer Detail
$firstName = "John";
$lastName = "Doe";
// Address
$alamat = "Jl. Kembangan Raya";
$city = "Jakarta";
$postalCode = "11530";
$countryCode = "ID";
$address = array(
'firstName' => $firstName,
'lastName' => $lastName,
'address' => $alamat,
'city' => $city,
'postalCode' => $postalCode,
'phone' => $phoneNumber,
'countryCode' => $countryCode
);
$customerDetail = array(
'firstName' => $firstName,
'lastName' => $lastName,
'email' => $email,
'phoneNumber' => $phoneNumber,
'billingAddress' => $address,
'shippingAddress' => $address
);
// Item Details
$item1 = array(
'name' => $productDetails,
'price' => $paymentAmount,
'quantity' => 1
);
$itemDetails = array(
$item1
);
$params = array(
'paymentAmount' => $paymentAmount,
'merchantOrderId' => $merchantOrderId,
'productDetails' => $productDetails,
'additionalParam' => $additionalParam,
'merchantUserInfo' => $merchantUserInfo,
'customerVaName' => $customerVaName,
'email' => $email,
'phoneNumber' => $phoneNumber,
'itemDetails' => $itemDetails,
'customerDetail' => $customerDetail,
'callbackUrl' => $callbackUrl,
'returnUrl' => $returnUrl,
'expiryPeriod' => $expiryPeriod
);
try {
// createInvoice Request
$responseDuitkuPop = \Duitku\Pop::createInvoice($params, $duitkuConfig);
header('Content-Type: application/json');
echo $responseDuitkuPop;
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$merchantOrderId = "YOUR_MERCHANTORDERID";
$transactionList = \Duitku\Pop::transactionStatus($merchantOrderId, $duitkuConfig);
header('Content-Type: application/json');
$transaction = json_decode($transactionList);
// var_dump($transactionList);
if ($transaction->statusCode == "00") {
// Action Success
} else if ($transaction->statusCode == "01") {
// Action Pending
} else {
// Action Failed Or Expired
}
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$callback = \Duitku\Pop::callback($duitkuConfig);
header('Content-Type: application/json');
$notif = json_decode($callback);
// var_dump($callback);
if ($notif->resultCode == "00") {
// Action Success
} else if ($notif->resultCode == "01") {
// Action Failed
}
} catch (Exception $e) {
http_response_code(400);
echo $e->getMessage();
}
try {
$paymentAmount = "10000"; //"YOUR_AMOUNT";
$paymentMethodList = \Duitku\Pop::getPaymentMethod($paymentAmount, $duitkuConfig);
header('Content-Type: application/json');
echo $paymentMethodList;
} catch (Exception $e) {
echo $e->getMessage();
}
$.ajax({
type: "POST",
data:{
// paymentMethod: '',
paymentAmount: amount,
productDetail: productDetail,
email: email,
phoneNumber: phoneNumber
},
url: 'http://domain.com/createInvoice.php',
dataType: "json",
cache: false,
success: function (result) {
console.log(result.reference);
console.log(result);
checkout.process(result.reference, {
successEvent: function(result){
// Add Your Action
console.log('success');
console.log(result);
alert('Payment Success');
},
pendingEvent: function(result){
// Add Your Action
console.log('pending');
console.log(result);
alert('Payment Pending');
},
errorEvent: function(result){
// Add Your Action
console.log('error');
console.log(result);
alert('Payment Error');
},
closeEvent: function(result){
// Add Your Action
console.log('customer closed the popup without finishing the payment');
console.log(result);
alert('customer closed the popup without finishing the payment');
}
});
}
});
$paymentAmount = 10000; // Amount
$paymentMethod = "BT"; // Permata Bank Virtual Account
$email = "customer@gmail.com"; // your customer email
$phoneNumber = "081234567890"; // your customer phone number (optional)
$productDetails = "Test Payment";
$merchantOrderId = time(); // from merchant, unique
$additionalParam = ''; // optional
$merchantUserInfo = ''; // optional
$customerVaName = 'John Doe'; // display name on bank confirmation display
$callbackUrl = 'http://YOUR_SERVER/callback'; // url for callback
$returnUrl = 'http://YOUR_SERVER/return'; // url for redirect
$expiryPeriod = 60; // set the expired time in minutes
// Customer Detail
$firstName = "John";
$lastName = "Doe";
// Address
$alamat = "Jl. Kembangan Raya";
$city = "Jakarta";
$postalCode = "11530";
$countryCode = "ID";
$address = array(
'firstName' => $firstName,
'lastName' => $lastName,
'address' => $alamat,
'city' => $city,
'postalCode' => $postalCode,
'phone' => $phoneNumber,
'countryCode' => $countryCode
);
$customerDetail = array(
'firstName' => $firstName,
'lastName' => $lastName,
'email' => $email,
'phoneNumber' => $phoneNumber,
'billingAddress' => $address,
'shippingAddress' => $address
);
// Item Details
$item1 = array(
'name' => $productDetails,
'price' => $paymentAmount,
'quantity' => 1
);
$itemDetails = array(
$item1
);
$params = array(
'paymentAmount' => $paymentAmount,
'paymentMethod' => $paymentMethod,
'merchantOrderId' => $merchantOrderId,
'productDetails' => $productDetails,
'additionalParam' => $additionalParam,
'merchantUserInfo' => $merchantUserInfo,
'customerVaName' => $customerVaName,
'email' => $email,
'phoneNumber' => $phoneNumber,
'itemDetails' => $itemDetails,
'customerDetail' => $customerDetail,
'callbackUrl' => $callbackUrl,
'returnUrl' => $returnUrl,
'expiryPeriod' => $expiryPeriod
);
try {
// createInvoice Request
$responseDuitkuApi = \Duitku\Api::createInvoice($params, $duitkuConfig);
header('Content-Type: application/json');
echo $responseDuitkuApi;
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$merchantOrderId = "YOUR_MERCHANTORDERID";
$transactionList = \Duitku\Api::transactionStatus($merchantOrderId, $duitkuConfig);
header('Content-Type: application/json');
$transaction = json_decode($transactionList);
// var_dump($transactionList);
if ($transaction->statusCode == "00") {
// Action Success
} else if ($transaction->statusCode == "01") {
// Action Pending
} else {
// Action Failed Or Expired
}
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$callback = \Duitku\Api::callback($duitkuConfig);
header('Content-Type: application/json');
$notif = json_decode($callback);
// var_dump($callback);
if ($notif->resultCode == "00") {
// Action Success
} else if ($notif->resultCode == "01") {
// Action Failed
}
} catch (Exception $e) {
http_response_code(400);
echo $e->getMessage();
}
try {
$paymentAmount = "10000"; //"YOUR_AMOUNT";
$paymentMethodList = \Duitku\Api::getPaymentMethod($paymentAmount, $duitkuConfig);
header('Content-Type: application/json');
echo $paymentMethodList;
} catch (Exception $e) {
echo $e->getMessage();
}
php vendor\bin\phpunit tests\CreateInvoiceTest.php
php vendor\bin\phpunit tests\TransactionStatusTest.php
php vendor\bin\phpunit tests\CallbackTest.php
php vendor\bin\phpunit tests\CreateInvoiceApiTest.php
php vendor\bin\phpunit tests\TransactionStatusApiTest.php
php vendor\bin\phpunit tests\CallbackApiTest.php