Anda di halaman 1dari 28

Daftar Isi

Setting Environment Xendit

Eksperimen penggunaan chanel virtual account Xendit dengan invoice

Eksperimen penggunaan chanel virtual account Xendit tanpa invoice

Eksperimen penggunaan chanel retail Xendit tanpa invoice

Eksperimen penggunaan chanel Qris Xendit tanpa invoice

Eksperimen penggunaan chanel EWalet Xendit tanpa invoice

Eksperimen penggunaan chanel Credit Card Xendit tanpa invoice

Eksperimen penggunaan chanel Direct Debit Xendit tanpa invoice


Setting Environment Xendit

1. Membuat struktur folder

2. Membuat API Key


3. Setting URL Callback
Eksperimen Penggunaan Chanel Virtual Account Xendit dengan invoice

1. Membuat kode program Virtual Account dengan invoice

<?php

/**
* VirtualAccountExample.php
* php version 7.2.0
*
* @category Example
* @package Xendit/Examples
* @author Ellen <ellen@xendit.co>
* @license https://opensource.org/licenses/MIT MIT License
* @link https://api.xendit.co
*/

use Xendit\Xendit;

require '../vendor/autoload.php';

Xendit::setApiKey('secret_key');
$response = [];

//1. tampilkan daftar metode pembayaran (transfer bank)


$getVABanks = \Xendit\VirtualAccounts::getVABanks();
$response['available_bank'] = $getVABanks;

//2. membuat VA sesuai bank yang dipilih


$v_channel = 'VA';
$v_bankcode = 'BCA'; // pilihan metode pembayaran transfer
$v_externalid = "ID1001"; // id user
$v_namamahasiswa = "Mahasiswa 1001";
$v_deskripsi = "Pembayaran uang kuliah";
$v_payeremail = "mahasiswa1001@gmail.com";
$v_uangkuliah = 60000;

//cek apakah sudah pernah membuat VA


$conn = mysqli_connect("localhost", "dbusername", “dbpassword", "dbname");
$result = mysqli_query($conn, "SELECT * FROM virtual_account WHERE bank_code='BCA' AND external_id =
'$v_externalid'");
if($row = mysqli_fetch_assoc($result))
{
$ada = 1;
}
else
{
$ada = 0;
}
mysqli_close($conn);

//2a. jika sudah pernah membuat VA


if($ada == 1)
{
//tidak perlu membuat VA
$response['virtual_account'] = $row;
$callback_virtual_account_id = $row['id'];
}
//2b. jika belum pernah membuat VA
if($ada == 0)
{
$params["external_id"] = $v_externalid;//external_id: Seringkali ID itu unik seperti nomor telepon, email or ID
transaction. Panjang maksimum yang diperbolehkan adalah 950 karakter.
$params["bank_code"] = $v_bankcode;
$params["name"] = $v_namamahasiswa;
$params["virtual_account_number"] = "9999001001";
$params["is_closed"] = true;
$params["expected_amount"] = $v_uangkuliah;

$createVA = \Xendit\VirtualAccounts::create($params);
$response['virtual_account'] = $createVA;
$callback_virtual_account_id = $createVA['id'];
$responseVa = $createVA;

//insert ke database table virtual_account


//…..dilaksanakan saat callback
}

//3. membuat invoice


if (isset($callback_virtual_account_id))
{
$params2['external_id'] = $v_externalid;
$params2['payer_email'] = $v_payeremail;
$params2['description'] = $v_deskripsi;
$params2['amount'] = $v_uangkuliah;
$params2['fixed_va'] = true;
$params2['callback_virtual_account_id'] = $callback_virtual_account_id; // menggunakan VA yang sudah
di buat
$createInvoice = \Xendit\Invoice::create($params2);
$response['invoice'] = $createInvoice;

//insert ke database table invoice


$v_id = $createInvoice['id'];
$v_externalid = $createInvoice['external_id'];
$v_userid = $createInvoice['user_id'];
$v_status = $createInvoice['status'];
$v_merchantname = $createInvoice['merchant_name'];
$v_merchantprofilepictureurl = $createInvoice['merchant_profile_picture_url'];
$v_amount = $createInvoice['amount'];
$v_payeremail = $createInvoice['payer_email'];
$v_description = $createInvoice['description'];
$v_expirydate = $createInvoice['expiry_date'];
$v_invoiceurl = $createInvoice['invoice_url'];
$v_chanelname = "";
$v_chanelnumber = "";
if($v_channel=="VA") //jika VA
{
$v_availablebank = end($createInvoice['available_banks']);
$v_chanelname = "VA " . $v_availablebank['bank_code'];
$v_chanelaccountnumber = $v_availablebank['bank_account_number'];
}
$v_created = $createInvoice['created'];
$v_updated = $createInvoice['updated'];
$v_currency = $createInvoice['currency'];
$v_fixedva = $createInvoice['fixed_va'];
$conn = mysqli_connect("localhost", "dbusername", “dbpassword", "dbname");
mysqli_query($conn, "INSERT INTO
invoice(id,external_id,user_id,status,merchant_name,merchant_profile_picture_url,amount,payer_email,description,ex
piry_date,invoice_url,chanel_name,chanel_accountnumber,created,updated,currency,fixed_va)VALUES ('".$v_id."','".
$v_externalid."','".$v_userid."','".$v_status."','".$v_merchantname."','".$v_merchantprofilepictureurl."','".
$v_amount."','".$v_payeremail."','".$v_description."','".$v_expirydate."','".$v_invoiceurl."','".$v_chanelname."','".
$v_chanelaccountnumber."','".$v_created."','".$v_updated."','".$v_currency."','".$v_fixedva."')");
mysqli_close($conn);
}

header('Content-Type: application/json; charset=utf-8');


echo json_encode($response, JSON_PRETTY_PRINT);

2. Membuat kode program callback pembuatan virtual account

<?php
$rawData = file_get_contents("php://input");
$v_data = json_decode($rawData,true);
$v_isclosed = $v_data["is_closed"];
$v_status = $v_data["status"];
$v_currency = $v_data["currency"];
$v_ownerid = $v_data["owner_id"];
$v_externalid = $v_data["external_id"];
$v_accountnumber = $v_data["account_number"];
$v_bankcode = $v_data["bank_code"];
$v_merchantcode = $v_data["merchant_code"];
$v_name = $v_data["name"];
$v_expectedamount = $v_data["expected_amount"];
$v_expirationdate = $v_data["expiration_date"];
$v_issingleuse = $v_data["is_single_use"];
$v_created = $v_data["created"];
$v_updated = $v_data["updated"];
$v_id = $v_data["id"];

$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);


mysqli_query($conn, "INSERT INTO
virtual_account(id,name,merchant_code,bank_code,account_number,external_id,owner_id,currency,status,expiration_
date,is_closed,expected_amount,is_single_use,created,updated)VALUES ('".$v_id."','".$v_name."','".
$v_merchantcode."','".$v_bankcode."','".$v_accountnumber."','".$v_externalid."','".$v_ownerid."','".$v_currency."','".
$v_status."','".$v_expirationdate."','".$v_isclosed."','".$v_expectedamount."','".$v_issingleuse."','".$v_created."','".
$v_updated."')");
mysqli_close($conn);

?>

3. Membuat kode program callback pembayaran invoice

<?php
$rawData = file_get_contents("php://input");
/*
{
"id":"61629ac2cda9a65e74c98324","external_id":"ID1001","user_id":"614983e75b5db919255a2dd1","is_high":false,
"payment_method":"BANK_TRANSFER","status":"PAID","merchant_name":"Politeknik ",
"amount":60000,"paid_amount":60000,"bank_code":"BCA","paid_at":"2021-10-10T07:50:16.932Z",
"payer_email":"mahasiswa1001@gmail.com","description":"Pembayaran uang
kuliah","adjusted_received_amount":60000,
"fees_paid_amount":0,"created":"2021-10-10T07:48:19.649Z","updated":"2021-10-
10T07:50:18.191Z","currency":"IDR",
"payment_channel":"BCA","payment_destination":"107669999000784"
}
*/

$v_data = json_decode($rawData,true);
$v_id = $v_data['id'];
$v_externalid = $v_data['external_id'];
$v_user = $v_data['user_id'];
$v_paymentmethod = $v_data['payment_method'];
$v_status = $v_data['status'];
$v_merchantname = $v_data['merchant_name'];
$v_amount = $v_data['amount'];
$v_paidamount = $v_data['paid_amount'];
$v_bankcode = $v_data['bank_code'];
$v_paidat = $v_data['paid_at'];
$v_payeremail = $v_data['payer_email'];
$v_description = $v_data['description'];
$v_adjustedreceivedamount = $v_data['adjusted_received_amount'];
$v_feespaidamount = $v_data['fees_paid_amount'];
$v_created = $v_data['created'];
$v_updated = $v_data['updated'];
$v_currency = $v_data['currency'];
$v_paymentchannel = $v_data['payment_channel'];
$v_paymentdestination = $v_data['payment_destination'];

$conn = mysqli_connect("localhost", "dbusername", “dbpassword", "dbname");


mysqli_query($conn, "UPDATE invoice SET status='PAID' WHERE id='".$v_id."'");
mysqli_close($conn);
?>

4. Mentesting kode program Virtual Account dengan invoice


5. Melaksanakan simulasi pembayaran melalui postman

Note: isu pembayaran VA tidak sesuai nominal VA yang diminta hanya ada pada mode sandbox
6. Mengecek hasil pelaksanaan simulasi pembayaran
Eksperimen penggunaan chanel virtual account Xendit tanpa invoice

1. Membuat kode program Virtual Account tanpa invoice

<?php
/**
* VirtualAccountExample.php
* php version 7.2.0
*
* @category Example
* @package Xendit/Examples
* @author Ellen <ellen@xendit.co>
* @license https://opensource.org/licenses/MIT MIT License
* @link https://api.xendit.co
*/

use Xendit\Xendit;

require '../vendor/autoload.php';

Xendit::setApiKey('secret_key');
$response = [];

//1. tampilkan daftar metode pembayaran (transfer bank)


$getVABanks = \Xendit\VirtualAccounts::getVABanks();
$response['available_bank'] = $getVABanks;

//2. membuat VA sesuai bank yang dipilih


$v_channel = 'VA';
$v_bankcode = 'BCA'; // pilihan metode pembayaran transfer
$v_externalid = "ID1005"; // is user
$v_namamahasiswa = "Mahasiswa 1005";
$v_virtualaccountnumber = "9999001005";
$v_deskripsi = "Pembayaran uang kuliah";
$v_payeremail = "mahasiswa1005@gmail.com";
$v_uangkuliah = 60000;

$params["external_id"] = $v_externalid;//external_id: Seringkali ID itu unik seperti nomor telepon, email or ID


transaction. Panjang maksimum yang diperbolehkan adalah 950 karakter.
$params["bank_code"] = $v_bankcode;
$params["name"] = $v_namamahasiswa;
$params["virtual_account_number"] = $v_virtualaccountnumber;
$params["is_closed"] = true;
$params["expected_amount"] = $v_uangkuliah;

$createVA = \Xendit\VirtualAccounts::create($params);
$response['virtual_account'] = $createVA;
$callback_virtual_account_id = $createVA['id'];
$responseVa = $createVA;
//insert ke database table virtual_account
//...dilaksanakan pada saat callback

header('Content-Type: application/json; charset=utf-8');


echo json_encode($response, JSON_PRETTY_PRINT);

2. Membuat kode program callback pembuatan virtual account

<?php
$rawData = file_get_contents("php://input");
$v_data = json_decode($rawData,true);
$v_isclosed = $v_data["is_closed"];
$v_status = $v_data["status"];
$v_currency = $v_data["currency"];
$v_ownerid = $v_data["owner_id"];
$v_externalid = $v_data["external_id"];
$v_accountnumber = $v_data["account_number"];
$v_bankcode = $v_data["bank_code"];
$v_merchantcode = $v_data["merchant_code"];
$v_name = $v_data["name"];
$v_expectedamount = $v_data["expected_amount"];
$v_expirationdate = $v_data["expiration_date"];
$v_issingleuse = $v_data["is_single_use"];
$v_created = $v_data["created"];
$v_updated = $v_data["updated"];
$v_id = $v_data["id"];

$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);


mysqli_query($conn, "INSERT INTO
virtual_account(id,name,merchant_code,bank_code,account_number,external_id,owner_id,currency,status,expiration_
date,is_closed,expected_amount,is_single_use,created,updated)VALUES ('".$v_id."','".$v_name."','".
$v_merchantcode."','".$v_bankcode."','".$v_accountnumber."','".$v_externalid."','".$v_ownerid."','".$v_currency."','".
$v_status."','".$v_expirationdate."','".$v_isclosed."','".$v_expectedamount."','".$v_issingleuse."','".$v_created."','".
$v_updated."')");
mysqli_close($conn);

?>
3. Membuat kode program callback pembayaran virtual account

<?php
$rawData = file_get_contents("php://input");
/*
{

"amount":60000,"callback_virtual_account_id":"6163b8635bb2309ef7539959","payment_id":"1633926283063","exter
nal_id":"ID1003",
"account_number":"9999001003","merchant_code":"10766","bank_code":"BCA","transaction_timestamp":"2021-10-
11T04:24:43.063Z",
"currency":"IDR","created":"2021-10-11T04:24:43.281Z","updated":"2021-10-11T04:24:43.435Z",
"id":"6163bc8be7e9da746b31f339","owner_id":"614983e75b5db919255a2dd1"
}
*/

$v_data = json_decode($rawData,true);
$v_currency = $v_data["currency"];
$v_ownerid = $v_data["owner_id"];
$v_externalid = $v_data["external_id"];
$v_accountnumber = $v_data["account_number"];
$v_bankcode = $v_data["bank_code"];
$v_merchantcode = $v_data["merchant_code"];
$v_created = $v_data["created"];
$v_updated = $v_data["updated"];
$v_id = $v_data["id"];
//--callback payment (additional field)
$v_amount = $v_data["amount"];
$v_callbackvirtualaccountid = $v_data["callback_virtual_account_id"];
$v_paymentid = $v_data["payment_id"];
$v_transactiontimestamp = $v_data["transaction_timestamp"];

$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);


mysqli_query($conn, "UPDATE virtual_account SET amount='".$v_amount."',payment_id='".
$v_paymentid."',transaction_timestamp='".$v_transactiontimestamp."' WHERE id ='".$v_callbackvirtualaccountid."'");
mysqli_close($conn);
?>

4. Mentesting kode program pembuatan Virtual Account tanpa invoice


5. Mensimulasikan pembayaran virtual account
Note: isu pembayaran VA tidak sesuai nominal VA yang diminta hanya ada pada mode sandbox

7. Mengecek hasil pelaksanaan simulasi pembayaran


Eksperimen penggunaan chanel retail Xendit tanpa invoice

1. Membuat kode program retail tanpa invoice

<?php
require '../vendor/autoload.php';
use Xendit\Xendit;

Xendit::setApiKey('secret_key');

$v_channel = 'Retail';
$v_externalid = 'ID92222'; // id user
$v_retailoutletname = 'ALFAMART'; // pilihan: ALFAMART, INDOMARET
$v_namamahasiswa = 'Mahasiswa 92222';
$v_uangkuliah = 60000;
$v_paymentcode = '92222';

$params['external_id'] = $v_externalid;
$params['retail_outlet_name'] = $v_retailoutletname;
$params['name'] = $v_namamahasiswa;
$params['expected_amount'] = $v_uangkuliah;
$params['payment_code'] = $v_paymentcode;
$params['is_single_use'] = true;

$createFPC = \Xendit\Retail::create($params);
$v_id = $createFPC['id'];
$v_name = $createFPC['name'];
$v_retailoutletname = $createFPC['retail_outlet_name'];
$v_prefix = $createFPC['prefix'];
$v_paymentcode = $createFPC['payment_code'];
$v_externalid = $createFPC['external_id'];
$v_ownerid = $createFPC['owner_id'];
$v_status = $createFPC['status'];
$v_expirationdate = $createFPC['expiration_date'];
$v_expectedamount = $createFPC['expected_amount'];
$v_issingleuse = $createFPC['is_single_use'];
$v_type = $createFPC['type'];

//insert ke database table retail


$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);
mysqli_query($conn, "INSERT INTO
retail(id,name,retail_outlet_name,prefix,payment_code,external_id,owner_id,status,expiration_date,expected_amount,
is_single_use,type)VALUES ('".$v_id."','".$v_name."','".$v_retailoutletname."','".$v_prefix."','".$v_paymentcode."','".
$v_externalid."','".$v_ownerid."','".$v_status."','".$v_expirationdate."','".$v_expectedamount."','".$v_issingleuse."','".
$v_type."')");
mysqli_close($conn);
?>
2. Membuat kode program callback pembayaran retail

<?php
$rawData = file_get_contents("php://input");
/*
//callback
{
"status":"COMPLETED","fixed_payment_code_payment_id":"61643b56f1abeb7d2aecb3dd","fixed_payment_co
de_id":"61643b4b8f8caaffaff55075",
"amount":60000,"name":"Mahasiswa 91112","prefix":"TEST","payment_code":"TEST91112",
"payment_id":"1633958742680","external_id":"ID91112","retail_outlet_name":"ALFAMART",
"transaction_timestamp":"2021-10-
11T13:25:42.680Z","id":"61643b5684c1aee350a3ab85","owner_id":"614983e75b5db919255a2dd1"
}
*/

$v_data = json_decode($rawData,true);
$v_status = $v_data["status"];
$v_fixedpaymentcodeid = $v_data["fixed_payment_code_id"];
$v_name = $v_data["name"];
$v_prefix = $v_data["prefix"];
$v_paymentcode = $v_data["payment_code"];
$v_externalid = $v_data["external_id"];
$v_retailoutletname = $v_data["retail_outlet_name"];
$v_id = $v_data["id"];//?
$v_ownerid = $v_data["owner_id"];
//--callback payment (additional field)
$v_fixedpaymentcodepaymentid = $v_data["fixed_payment_code_payment_id"];
$v_amount = $v_data["amount"];
$v_paymentid = $v_data["payment_id"];
$v_transactiontimestamp = $v_data["transaction_timestamp"];

$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);


mysqli_query($conn, "UPDATE retail SET fixed_payment_code_payment_id='".
$v_fixedpaymentcodepaymentid."',amount='".$v_amount."',payment_id='".$v_paymentid."',transaction_timestamp='".
$v_transactiontimestamp."' WHERE id ='".$v_fixedpaymentcodeid."'");
mysqli_close($conn);

?>
3. Mentesting kode program pembuatan retail tanpa invoice

4. Mensimulasikan pembayaran retail

Note: isu pembayaran retail tidak sesuai nominal retail yang diminta hanya ada pada mode sandbox
5. Mengecek hasil pelaksanaan simulasi pembayaran
Eksperimen penggunaan chanel Qris Xendit tanpa invoice

1. Membuat kode program Qris tanpa invoice

<?php

/**
* QRCodeExample.php
* php version 7.2.0
*
* @category Example
* @package Xendit/Examples
* @author Dave <kevindave@xendit.co>
* @license https://opensource.org/licenses/MIT MIT License
* @link https://api.xendit.co
*/

use Xendit\Xendit;
require '../vendor/autoload.php';

Xendit::setApiKey('secret_key');

$v_channel = 'Qris';
$v_type = 'DYNAMIC';
$v_externalid = 'ID310010'; // id user
$v_uangkuliah = 60000;

$params['external_id'] = $v_externalid;
$params['type'] = $v_type;
$params['callback_url'] = 'https://xendit.politeknik.ac.id/qris_callbacks/qris_paid.php';
$params['amount'] = $v_uangkuliah;

$created_qr_code = \Xendit\QRCode::create($params);
$v_id = $created_qr_code["id"];
$v_externalid = $created_qr_code["external_id"];
$v_amount = $created_qr_code["amount"];
$v_description = $created_qr_code["description"];
$v_qrstring = $created_qr_code["qr_string"];
$v_callbackurl = $created_qr_code["callback_url"];
$v_type = $created_qr_code["type"];
$v_status = $created_qr_code["status"];
$v_created = $created_qr_code["created"];
$v_updated = $created_qr_code["updated"];
$v_metadata = $created_qr_code["metadata"];

//insert ke database table qris


$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);
mysqli_query($conn, "INSERT INTO
qris(id,external_id,amount,description,qr_string,callback_url,type,status,created,updated,metadata)VALUES ('".
$v_id."','".$v_externalid."','".$v_amount."','".$v_description."','".$v_qrstring."','".$v_callbackurl."','".$v_type."','".
$v_status."','".$v_created."','".$v_updated."','".$v_metadata."')");
mysqli_close($conn);

echo '<img src="qris_generator.php?qr_string='.$v_qrstring.'" />';

2. Membuat kode program QRCODE generator

<?php
require '../phpqrcode/qrlib.php';

$param = strip_tags($_GET['qr_string']); // remember to sanitize that - it is user input!

QRcode::png($param);
?>

3. Membuat kode program callback pembayaran qris

<?php
$rawData = file_get_contents("php://input");
/*
{
"id":"qrpy_80f0ae71-60eb-449b-b551-24633edc4a35",///
"event":"qr.payment",///
"amount":60000,///
"status":"COMPLETED",
"created":"2021-10-12T02:37:16.290Z",
"qr_code":{
"id":"qr_035f2f82-9a68-4cad-9530-e05c63da6372",
"type":"DYNAMIC",
"metadata":null,
"qr_string":"mock-QR-string-use-simulate-payment-to-test-flow",
"external_id":"ID310007"
},
"payment_details":{
"source":null,///
"receipt_id":null///
}
}
*/

$v_data = json_decode($rawData,true);
$v_status = $v_data["status"];
$v_qrcode = $v_data["qr_code"];
$v_qrcode_id = $v_qrcode["id"];
$v_qrcode_type = $v_qrcode["type"];
$v_qrcode_metadata = $v_qrcode["metadata"];
$v_qrcode_qrstring = $v_qrcode["qr_string"];
$v_qrcode_externalid = $v_qrcode["external_id"];
//--callback payment (additional field)
$v_paymentid = $v_data["id"];
$v_event = $v_data["event"];
$v_paymentamount = $v_data["amount"];
$v_transactiontimestamp = $v_data["created"];
$v_paymentdetails = $v_data["payment_details"];
$v_paymentdetails_source = $v_paymentdetails["source"];
$v_paymentdetails_receiptid = $v_paymentdetails["receipt_id"];

$conn = mysqli_connect(“localhost”, “dbusername”, “dbpassword”, “dbname”);


mysqli_query($conn, "UPDATE qris SET payment_id='".$v_paymentid."',event='".$v_event."',payment_amount='".
$v_paymentamount."',transaction_timestamp='".$v_transactiontimestamp."',source='".
$v_paymentdetails_source."',receipt_id='".$v_paymentdetails_receiptid."' WHERE id ='".$v_qrcode_id."'");
mysqli_close($conn);

?>

4. Mentesting kode program pembuatan qris tanpa invoice


5. Mensimulasikan pembayaran qris

Note: isu pembayaran Qris tidak sesuai nominal Qris yang diminta hanya ada pada mode sandbox

6. Mengecek hasil pelaksanaan simulasi pembayaran


Eksperimen penggunaan chanel EWalet Xendit tanpa invoice

Anda mungkin juga menyukai