jamboljack

Callback Winpay

Feb 5th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.34 KB | None | 0 0
  1. public function index()
  2.     {
  3.         $json_string = file_get_contents('php://input');
  4.         $json_array  = json_decode($json_string, true);
  5.         $publicKey   = '-----BEGIN PUBLIC KEY-----
  6. MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHGK10J1oBbCD75Wy8P5rL8zzCz9
  7. lpHZ7OIHVaO4vlX0tjpKD887ldaTLl4Vdhc6I88OHscV/ijQ7OQ07IpWLAoSm7VK
  8. puiUDt9xUx9dCHAIrH6DDNOI95z2b6jxwh81ZTC+LCDsEb5b797dmxa7Kv8kABjo
  9. Nt8JR33E9p3d7uzrAgMBAAE=
  10. -----END PUBLIC KEY-----';
  11.  
  12.         $path            = '/v1.0/transfer-va/payment';
  13.         $timestamp       = isset($_SERVER['HTTP_X_TIMESTAMP']) ? $_SERVER['HTTP_X_TIMESTAMP'] : '';
  14.         $signature       = isset($_SERVER['HTTP_X_SIGNATURE']) ? $_SERVER['HTTP_X_SIGNATURE'] : '';
  15.         $httpMethod      = 'POST';
  16.         $partnerId       = isset($_SERVER['HTTP_X_PARTNER_ID']) ? $_SERVER['HTTP_X_PARTNER_ID'] : '';
  17.         $body            = $json_array;
  18.         $hashedBody      = strtolower(bin2hex(hash('sha256', json_encode($body, JSON_UNESCAPED_SLASHES), true)));
  19.         $stringToSignArr = [$httpMethod, $path, $hashedBody, $timestamp];
  20.         $stringToSign    = implode(':', $stringToSignArr);
  21.  
  22.         try {
  23.             $publicKey = openssl_get_publickey($publicKey);
  24.             $verify    = openssl_verify($stringToSign, base64_decode($signature), $publicKey, OPENSSL_ALGO_SHA256);
  25.             if ($verify !== 1) {
  26.                 $response = [
  27.                     'responseCode'    => '4012700',
  28.                     'responseMessage' => 'Cannot verify signature',
  29.                 ];
  30.             } else {
  31.                 // Update Payment
  32.                 $virtualAccountNo = $json_array["virtualAccountNo"];
  33.                 $trxId            = $json_array["trxId"];
  34.                 $total            = $json_array["paidAmount"]["value"];
  35.                 $channel          = $json_array["additionalInfo"]["channel"];
  36.  
  37.                 // Update Status
  38.                 $dataCallback = array(
  39.                     'callback_api_nomor'  => $trxId,
  40.                     'callback_api_code'   => $channel,
  41.                     'callback_api_total'  => $total,
  42.                     'callback_api_update' => date('Y-m-d H:i:s'),
  43.                 );
  44.  
  45.                 $this->db->insert('sid_callback_api', $dataCallback);
  46.  
  47.                 // UpdateInvoice
  48.                 $checkData = $this->db->get_where('v_invoice', array('invoice_nomor' => trim($trxId)));
  49.                 $num_rows  = $checkData->num_rows();
  50.                 if ($num_rows > 0) {
  51.                     $dtInvoice        = $checkData->row();
  52.                     $invoice_id       = $dtInvoice->invoice_id;
  53.                     $pelanggan_id     = $dtInvoice->pelanggan_id;
  54.                     $invoice_total    = $dtInvoice->invoice_total;
  55.                     $invoice_subtotal = $dtInvoice->invoice_subtotal;
  56.                     $invoice_status   = $dtInvoice->invoice_status;
  57.                     $user_reseller    = $dtInvoice->user_reseller;
  58.                     if ($invoice_status == 'U') {
  59.                         if ($total == $invoice_total) {
  60.                             // Cek Komisi
  61.                             if ($user_reseller != '') {
  62.                                 $dataReseller = $this->db->get_where('sid_users', array('user_username' => $user_reseller))->row();
  63.                                 $komisi       = $dataReseller->user_komisi;
  64.                                 $komisi_rp    = round(($komisi * $invoice_subtotal) / 100);
  65.                                 $netto        = ($invoice_subtotal - $komisi_rp);
  66.  
  67.                                 // Insert ke Tabel Komisi
  68.                                 $dataKomReseller = array(
  69.                                     'invoice_id'    => $invoice_id,
  70.                                     'user_username' => $user_reseller,
  71.                                     'komisi_total'  => $komisi_rp,
  72.                                     'komisi_update' => date('Y-m-d H:i:s'),
  73.                                 );
  74.  
  75.                                 $this->db->insert('sid_komisi', $dataKomReseller);
  76.                             } else {
  77.                                 $komisi_rp = 0;
  78.                                 $netto     = $invoice_subtotal;
  79.                             }
  80.  
  81.                             $dataJenisBayar = $this->db->get_where('sid_jenis_bayar', array('jenis_bayar_code' => $channel))->row();
  82.                             $jenis_bayar_id = $dataJenisBayar->jenis_bayar_id;
  83.                             // Update Bayar Invoice
  84.                             $dataUpdate = array(
  85.                                 'jenis_bayar_id'    => $jenis_bayar_id,
  86.                                 'invoice_status'    => 'P',
  87.                                 'invoice_id_bayar'  => $id_transaksi,
  88.                                 'invoice_komisi'    => $komisi_rp,
  89.                                 'invoice_netto'     => $netto,
  90.                                 'invoice_dibayar'   => $invoice_total,
  91.                                 'invoice_sisa'      => 0,
  92.                                 'invoice_tgl_bayar' => date('Y-m-d H:i:s'),
  93.                                 'invoice_update'    => date('Y-m-d H:i:s'),
  94.                             );
  95.  
  96.                             $this->db->where('invoice_id', $invoice_id);
  97.                             $this->db->update('sid_invoice', $dataUpdate);
  98.  
  99.                             // Insert Notifikasi Teknisi
  100.                             $dataPelanggan  = $this->db->get_where('v_invoice', array('invoice_id' => $invoice_id))->row();
  101.                             $dataNotifikasi = array(
  102.                                 'user_username'         => 'admin',
  103.                                 'notifikasi_level'      => 'Teknisi',
  104.                                 'notifikasi_tanggal'    => date('Y-m-d H:i:s'),
  105.                                 'notifikasi_keterangan' => 'Pembayaran Invoice : ' . $dataPelanggan->pelanggan_nama . ', ID Pel. : ' . $dataPelanggan->pelanggan_nomor . '. Siap Pasang.',
  106.                                 'notifikasi_update'     => date('Y-m-d H:i:s'),
  107.                             );
  108.  
  109.                             $this->db->insert('sid_notifikasi', $dataNotifikasi);
  110.                             // Insert Notifikasi Finance
  111.                             $dataFinance = array(
  112.                                 'user_username'         => 'admin',
  113.                                 'notifikasi_level'      => 'Finance',
  114.                                 'notifikasi_tanggal'    => date('Y-m-d H:i:s'),
  115.                                 'notifikasi_keterangan' => 'Pembayaran Invoice : ' . $dataPelanggan->pelanggan_nama . ', ID Pel. : ' . $dataPelanggan->pelanggan_nomor . '. Siap Pasang.',
  116.                                 'notifikasi_update'     => date('Y-m-d H:i:s'),
  117.                             );
  118.  
  119.                             $this->db->insert('sid_notifikasi', $dataFinance);
  120.  
  121.                             // Kirim BOT Telegram
  122.                             $message = $this->pesan_bot($invoice_id);
  123.                             $this->kirimbot($message);
  124.  
  125.                             // Sukses
  126.                             $response = [
  127.                                 'responseCode'    => '2002500',
  128.                                 'responseMessage' => 'Successful',
  129.                             ];
  130.                         } else {
  131.                             // Beda Total
  132.                             $response = [
  133.                                 'responseCode'    => '4042513',
  134.                                 'responseMessage' => 'Invalid Amount',
  135.                             ];
  136.                         }
  137.                     } else {
  138.                         // Pembayaran Dobel
  139.                         $response = [
  140.                             'responseCode'    => '4092500',
  141.                             'responseMessage' => 'Duplicate paymentRequestId',
  142.                         ];
  143.                     }
  144.                 } else {
  145.                     $response = [
  146.                         'responseCode'    => '4042501',
  147.                         'responseMessage' => 'Transaction Not Found',
  148.                     ];
  149.                 }
  150.             }
  151.         } catch (Exception $e) {
  152.             $response = [
  153.                 'responseCode'    => '4012700',
  154.                 'responseMessage' => 'Invalid signature {' . $e->getMessage() . '}',
  155.             ];
  156.         }
  157.  
  158.         echo json_encode($response);
  159.     }
Add Comment
Please, Sign In to add comment