Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function index()
- {
- $json_string = file_get_contents('php://input');
- $json_array = json_decode($json_string, true);
- $publicKey = '-----BEGIN PUBLIC KEY-----
- MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHGK10J1oBbCD75Wy8P5rL8zzCz9
- lpHZ7OIHVaO4vlX0tjpKD887ldaTLl4Vdhc6I88OHscV/ijQ7OQ07IpWLAoSm7VK
- puiUDt9xUx9dCHAIrH6DDNOI95z2b6jxwh81ZTC+LCDsEb5b797dmxa7Kv8kABjo
- Nt8JR33E9p3d7uzrAgMBAAE=
- -----END PUBLIC KEY-----';
- $path = '/v1.0/transfer-va/payment';
- $timestamp = isset($_SERVER['HTTP_X_TIMESTAMP']) ? $_SERVER['HTTP_X_TIMESTAMP'] : '';
- $signature = isset($_SERVER['HTTP_X_SIGNATURE']) ? $_SERVER['HTTP_X_SIGNATURE'] : '';
- $httpMethod = 'POST';
- $partnerId = isset($_SERVER['HTTP_X_PARTNER_ID']) ? $_SERVER['HTTP_X_PARTNER_ID'] : '';
- $body = $json_array;
- $hashedBody = strtolower(bin2hex(hash('sha256', json_encode($body, JSON_UNESCAPED_SLASHES), true)));
- $stringToSignArr = [$httpMethod, $path, $hashedBody, $timestamp];
- $stringToSign = implode(':', $stringToSignArr);
- try {
- $publicKey = openssl_get_publickey($publicKey);
- $verify = openssl_verify($stringToSign, base64_decode($signature), $publicKey, OPENSSL_ALGO_SHA256);
- if ($verify !== 1) {
- $response = [
- 'responseCode' => '4012700',
- 'responseMessage' => 'Cannot verify signature',
- ];
- } else {
- // Update Payment
- $virtualAccountNo = $json_array["virtualAccountNo"];
- $trxId = $json_array["trxId"];
- $total = $json_array["paidAmount"]["value"];
- $channel = $json_array["additionalInfo"]["channel"];
- // Update Status
- $dataCallback = array(
- 'callback_api_nomor' => $trxId,
- 'callback_api_code' => $channel,
- 'callback_api_total' => $total,
- 'callback_api_update' => date('Y-m-d H:i:s'),
- );
- $this->db->insert('sid_callback_api', $dataCallback);
- // UpdateInvoice
- $checkData = $this->db->get_where('v_invoice', array('invoice_nomor' => trim($trxId)));
- $num_rows = $checkData->num_rows();
- if ($num_rows > 0) {
- $dtInvoice = $checkData->row();
- $invoice_id = $dtInvoice->invoice_id;
- $pelanggan_id = $dtInvoice->pelanggan_id;
- $invoice_total = $dtInvoice->invoice_total;
- $invoice_subtotal = $dtInvoice->invoice_subtotal;
- $invoice_status = $dtInvoice->invoice_status;
- $user_reseller = $dtInvoice->user_reseller;
- if ($invoice_status == 'U') {
- if ($total == $invoice_total) {
- // Cek Komisi
- if ($user_reseller != '') {
- $dataReseller = $this->db->get_where('sid_users', array('user_username' => $user_reseller))->row();
- $komisi = $dataReseller->user_komisi;
- $komisi_rp = round(($komisi * $invoice_subtotal) / 100);
- $netto = ($invoice_subtotal - $komisi_rp);
- // Insert ke Tabel Komisi
- $dataKomReseller = array(
- 'invoice_id' => $invoice_id,
- 'user_username' => $user_reseller,
- 'komisi_total' => $komisi_rp,
- 'komisi_update' => date('Y-m-d H:i:s'),
- );
- $this->db->insert('sid_komisi', $dataKomReseller);
- } else {
- $komisi_rp = 0;
- $netto = $invoice_subtotal;
- }
- $dataJenisBayar = $this->db->get_where('sid_jenis_bayar', array('jenis_bayar_code' => $channel))->row();
- $jenis_bayar_id = $dataJenisBayar->jenis_bayar_id;
- // Update Bayar Invoice
- $dataUpdate = array(
- 'jenis_bayar_id' => $jenis_bayar_id,
- 'invoice_status' => 'P',
- 'invoice_id_bayar' => $id_transaksi,
- 'invoice_komisi' => $komisi_rp,
- 'invoice_netto' => $netto,
- 'invoice_dibayar' => $invoice_total,
- 'invoice_sisa' => 0,
- 'invoice_tgl_bayar' => date('Y-m-d H:i:s'),
- 'invoice_update' => date('Y-m-d H:i:s'),
- );
- $this->db->where('invoice_id', $invoice_id);
- $this->db->update('sid_invoice', $dataUpdate);
- // Insert Notifikasi Teknisi
- $dataPelanggan = $this->db->get_where('v_invoice', array('invoice_id' => $invoice_id))->row();
- $dataNotifikasi = array(
- 'user_username' => 'admin',
- 'notifikasi_level' => 'Teknisi',
- 'notifikasi_tanggal' => date('Y-m-d H:i:s'),
- 'notifikasi_keterangan' => 'Pembayaran Invoice : ' . $dataPelanggan->pelanggan_nama . ', ID Pel. : ' . $dataPelanggan->pelanggan_nomor . '. Siap Pasang.',
- 'notifikasi_update' => date('Y-m-d H:i:s'),
- );
- $this->db->insert('sid_notifikasi', $dataNotifikasi);
- // Insert Notifikasi Finance
- $dataFinance = array(
- 'user_username' => 'admin',
- 'notifikasi_level' => 'Finance',
- 'notifikasi_tanggal' => date('Y-m-d H:i:s'),
- 'notifikasi_keterangan' => 'Pembayaran Invoice : ' . $dataPelanggan->pelanggan_nama . ', ID Pel. : ' . $dataPelanggan->pelanggan_nomor . '. Siap Pasang.',
- 'notifikasi_update' => date('Y-m-d H:i:s'),
- );
- $this->db->insert('sid_notifikasi', $dataFinance);
- // Kirim BOT Telegram
- $message = $this->pesan_bot($invoice_id);
- $this->kirimbot($message);
- // Sukses
- $response = [
- 'responseCode' => '2002500',
- 'responseMessage' => 'Successful',
- ];
- } else {
- // Beda Total
- $response = [
- 'responseCode' => '4042513',
- 'responseMessage' => 'Invalid Amount',
- ];
- }
- } else {
- // Pembayaran Dobel
- $response = [
- 'responseCode' => '4092500',
- 'responseMessage' => 'Duplicate paymentRequestId',
- ];
- }
- } else {
- $response = [
- 'responseCode' => '4042501',
- 'responseMessage' => 'Transaction Not Found',
- ];
- }
- }
- } catch (Exception $e) {
- $response = [
- 'responseCode' => '4012700',
- 'responseMessage' => 'Invalid signature {' . $e->getMessage() . '}',
- ];
- }
- echo json_encode($response);
- }
Add Comment
Please, Sign In to add comment