jamboljack

VA Winpay

May 24th, 2026
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.93 KB | None | 0 0
  1. // WINPAY VA
  2.             $httpMethod  = 'POST';
  3.             $endpointUrl = $jenis_bayar_pk1;
  4.             $timestamp   = date(DateTime::RFC3339);
  5.             $dateTime    = new DateTime($timestamp);
  6.             $dateTime->modify('+1 hours');
  7.             $expiredDate = $dateTime->format(DateTime::RFC3339);
  8.             $totalAmount = array(
  9.                 'value'    => number_format($detail->invoice_total, 2, '.', ''),
  10.                 'currency' => "IDR",
  11.             );
  12.             $additionalInfo = array(
  13.                 'channel' => $jenis_bayar_code,
  14.             );
  15.             $payload = array(
  16.                 "customerNo"            => $detail->pelanggan_nomor,
  17.                 "virtualAccountName"    => substr(preg_replace("/[.,'-]/", '', $detail->pelanggan_nama), 0, 24),
  18.                 "trxId"                 => $detail->invoice_nomor,
  19.                 "totalAmount"           => $totalAmount,
  20.                 "virtualAccountTrxType" => 'c',
  21.                 "expiredDate"           => $expiredDate,
  22.                 "additionalInfo"        => $additionalInfo,
  23.             );
  24.             $body                  = json_encode($payload);
  25.             $hashedBody            = strtolower(bin2hex(hash('sha256', json_encode($payload, JSON_UNESCAPED_SLASHES), true)));
  26.             $signature             = $this->generateSignatureRequest($httpMethod, $endpointUrl, $hashedBody, $timestamp);
  27.             $requestHeadersRequest = array(
  28.                 'Content-Type: application/json',
  29.                 'Accept: application/json',
  30.                 'X-TIMESTAMP: ' . $timestamp,
  31.                 'X-SIGNATURE: ' . $signature,
  32.                 'X-PARTNER-ID: ' . $jenis_bayar_mk,
  33.                 'X-EXTERNAL-ID: ' . uniqid(),
  34.                 'CHANNEL-ID: WEB',
  35.             );
  36.  
  37.             $urlAPI         = $jenis_bayar_url;
  38.             $urlPostrequest = $urlAPI . $jenis_bayar_pk1;
  39.             $curl           = curl_init();
  40.             curl_setopt_array($curl, array(
  41.                 CURLOPT_URL            => $urlPostrequest,
  42.                 CURLOPT_RETURNTRANSFER => true,
  43.                 CURLOPT_ENCODING       => '',
  44.                 CURLOPT_MAXREDIRS      => 10,
  45.                 CURLOPT_TIMEOUT        => 0,
  46.                 CURLOPT_FOLLOWLOCATION => true,
  47.                 CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
  48.                 CURLOPT_CUSTOMREQUEST  => 'POST',
  49.                 CURLOPT_POSTFIELDS     => $body,
  50.                 CURLOPT_HTTPHEADER     => $requestHeadersRequest,
  51.             ));
  52.  
  53.             $Respx = curl_exec($curl);
  54.             curl_close($curl);
  55.             $rsp     = json_decode($Respx, true);
  56.             $Code    = $rsp['responseCode'];
  57.             $message = $rsp['responseMessage'];
  58.             if ($Code == '2002700') {
  59.                 $virtualAccountNo = $rsp['virtualAccountData']['virtualAccountNo'];
  60.                 $partnerServiceId = $rsp['virtualAccountData']['partnerServiceId'];
  61.                 // Update Payment Code
  62.                 $invoice_id  = $detail->invoice_id;
  63.                 $dataPayment = array(
  64.                     'jenis_bayar_id'        => $jenis_bayar_id,
  65.                     'winpay_data'           => $Respx,
  66.                     'reff_id'               => trim($partnerServiceId),
  67.                     'payment_code'          => trim($virtualAccountNo),
  68.                     'invoice_start_payment' => $timestamp,
  69.                     'invoice_end_payment'   => $expiredDate,
  70.                 );
  71.  
  72.                 $this->db->where('invoice_id', $invoice_id);
  73.                 $this->db->update('sid_invoice', $dataPayment);
  74.  
  75.                 $invoice_id_enc = $this->secure->encrypt_url($invoice_id);
  76.                 $response       = ['status' => 'success', 'url_payment' => site_url('umum/invoice/payment/' . strtolower($jenis_bayar_code) . '/' . $invoice_id_enc)];
  77.             } else {
  78.                 $response = ['status' => 'error', 'status_message' => $message];
  79.             }
Advertisement
Add Comment
Please, Sign In to add comment