Callback adalah metode pengiriman notifikasi transaksi dari server MauPedia ke server penguna. Pada saat status transaksi sukses atau gagal, maka sistem MauPedia akan memberikan notifikasi yang berisi data transaksi yang kemudian dapat dikelola lebih lanjut oleh sistem pengguna.
Delivery headers
Header | Contoh Nilai | Keterangan |
---|---|---|
content-type | application/json | Data dikirim menggunakan format JSON |
x-maupedia-signature | 867ad7a69fb35 | Sebuah HMAC hex yang berasal dari response body dan API Signature |
x-maupedia-event | update |
|
x-maupedia-type | prabayar |
|
x-maupedia-mode | production |
|
Contoh Isi / Content yang dikirim
PRABAYAR
{
"trxid": "2232259873",
"kode": "TSEL1",
"produk": "Telkomsel 1.000",
"target": "08226541XXXX",
"note": "0255020000131SUCCESS",
"harga": 1200,
"status": "success",
"trxfrom": "API,36.81.9.115",
"trxtype": "prabayar",
"saldo_awal": 5000,
"saldo_akhir": 3800,
"created_at": "2021-12-25 05:29:48",
"updated_at": "2021-12-25 06:50:03"
}
PASCABAYAR
{
"trxid": "2232259873",
"kode": "PPLN",
"produk": "Pln Pascabayar",
"target": "5353XXXX",
"note": "0255020000131SUCCESS",
"harga": 9938,
"status": "success",
"trxfrom": "API,36.81.9.115",
"trxtype": "pascabayar",
"saldo_awal": 10000,
"saldo_akhir": 62,
"created_at": "2021-12-25 05:29:48",
"updated_at": "2021-12-25 06:50:03"
}
TOPUP GAME
{
"trxid": "2232259873",
"kode": "ML28",
"produk": "MOBILELEGEND - 28 Diamond",
"target": "123456",
"zone": "1122",
"note": "S22232991341\/25 Diamonds 3 Bonus\/ML.",
"harga": 8354,
"status": "success",
"trxfrom": "WEB,36.81.9.115",
"trxtype": "game",
"saldo_awal": 10000,
"saldo_akhir": 1646,
"created_at": "2021-12-25 05:29:48",
"updated_at": "2021-12-25 06:50:03"
}
SOSIAL MEDIA
{
"trxid": "2232259873123",
"produk": "Instagram Likes Server 8",
"target": "username",
"note": "-",
"custom_comments": "",
"custom_link": "",
"jumlah_order": 132,
"harga": 200,
"jumlah_awal": 324,
"jumlah_kurang": 0,
"status": "success",
"trxfrom": "WEB,36.81.9.115",
"trxtype": "socmed",
"saldo_awal": 10000,
"saldo_akhir": 9800,
"created_at": "2021-12-25 05:29:48",
"updated_at": "2021-12-25 06:50:03"
}
DEPOSIT
{
"trxid": "2232259873123",
"method": "qris",
"name": "QRIS Nobu (Fee 0.7%)",
"sender": "",
"amount": 1000,
"get_amount": 960,
"pay_ref": "D74222DSOPOUI",
"pay_amount": 1000,
"status": "paid",
"trxtype": "deposit",
"saldo_awal": 4516,
"saldo_akhir": 5496,
"created_at": "2022-06-10 03:37:58",
"updated_at": "2022-06-10 04:37:58",
"expired_at": "2022-06-10 04:37:58"
}
Contoh Handle Callback
Contoh Full Script PHP
<?php
// Include file koneksi database
require('db_connection.php');
// Ambil data JSON
$get = file_get_contents('php://input');
// Ambil data Header
$headers = getallheaders();
// Ambil MauPedia signature
$callbackSignature = isset($headers['x-maupedia-signature']) ? $headers['x-maupedia-signature'] : '';
// Isi dengan API Signature anda
$privateKey = 'API_Signature_anda';
// Generate signature untuk dicocokkan dengan x-maupedia-signature
$signature = hash_hmac('sha256', $get, $privateKey);
// Validasi signature
if ($callbackSignature !== $signature) {
exit('Invalid signature');
}
$data = json_decode($get, true);
$json = json_encode($data);
// Hentikan proses jika callback event-nya bukan update/create
if ('update' !== $headers['x-maupedia-event']) {
exit('Invalid callback event, no action was taken');
}
//Ubah data status sesuai database anda
function MPStatus($x)
{
if ($x == 'waiting') $str = 'Pending';
if ($x == 'error') $str = 'Error';
if ($x == 'success') $str = 'Success';
return (!$str) ? 'Pending' : $str;
}
if ($headers['x-maupedia-type'] == 'prabayar') {
/*
|--------------------------------------------------------------------------
| Proses Transaksi Prabayar
|--------------------------------------------------------------------------
*/
$trxid = $data['trxid'];
$status = MPStatus($data['status']);
$data_pesanan = $conn->query("SELECT * FROM pembelian_pulsa WHERE oid = '$trxid' AND status IN ('Pending', '')");
if ($data_pesanan->num_rows == 0) {
exit('data tidak ditemukan: ' . $trxid);
} else {
while ($cek_pesanan = $data_pesanan->fetch_assoc()) {
$trxid = $cek_pesanan['trxid'];
$code = $cek_pesanan['code'];
$note = $cek_pesanan['note'];
$updated_at = $cek_pesanan['updated_at'];
if ($conn->query("SELECT * FROM pembelian_pulsa WHERE oid = '$trxid' AND status = 'Pending'")->num_rows == 1) {
$conn->query("UPDATE pembelian_pulsa SET status = '$status', date_up = '$updated_at', keterangan = '$note' WHERE oid = '$trxid'");
if ($status == "Success") {
//Lakukan Aksi Lainnya
// Berikan response ke MauPedia.
exit(json_encode(['status' => true]));
}
}
}
}
} else if ($headers['x-maupedia-type'] == 'pascabayar') {
/*
|--------------------------------------------------------------------------
| Proses Transaksi pascabayar
|--------------------------------------------------------------------------
*/
//Lakukan Aksi Lainnya
// Berikan response ke MauPedia.
exit(json_encode(['status' => true]));
} else if ($headers['x-maupedia-type'] == 'socmed') {
/*
|--------------------------------------------------------------------------
| Proses Transaksi socmed
|--------------------------------------------------------------------------
*/
//Lakukan Aksi Lainnya
// Berikan response ke MauPedia.
exit(json_encode(['status' => true]));
} else if ($headers['x-maupedia-type'] == 'game') {
/*
|--------------------------------------------------------------------------
| Proses Transaksi game
|--------------------------------------------------------------------------
*/
//Lakukan Aksi Lainnya
// Berikan response ke MauPedia.
exit(json_encode(['status' => true]));
} else if ($headers['x-maupedia-type'] == 'deposit') {
/*
|--------------------------------------------------------------------------
| Proses Transaksi deposit
|--------------------------------------------------------------------------
*/
//Lakukan Aksi Lainnya
// Berikan response ke MauPedia.
exit(json_encode(['status' => true]));
}