jamboljack

Receive Payment

Jan 7th, 2026
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. private function create_receive_payment_paid($invoice, $invoice_jurnal_id, $customer_jurnal_id)
  2.     {
  3.         try {
  4.             // Validasi dasar
  5.             if (empty($invoice_jurnal_id)) {
  6.                 return [
  7.                     'success' => false,
  8.                     'message' => 'Invoice Jurnal ID kosong'
  9.                 ];
  10.             }
  11.  
  12.             // Amount = total invoice (karena konsepnya selalu full paid)
  13.             $amount = (int) $invoice->invoice_total;
  14.             // Payload Receive Payment (SINGLE)
  15.             $payload = [
  16.                 'receive_payment' => [
  17.                     'transaction_date' => date('Y-m-d', strtotime($invoice->invoice_tgl_bayar)),
  18.                     'records_attributes' => [
  19.                         [
  20.                             // WAJIB: ID invoice dari Mekari
  21.                             'transaction_id' => (int) $invoice_jurnal_id,
  22.                             'amount'         => $amount
  23.                         ]
  24.                     ],
  25.                     'custom_id'           => 'RP-' . $invoice->invoice_nomor,
  26.                     'payment_method_name' => 'Cash',
  27.                     'deposit_to_name'     => 'BRI-341001000011566',
  28.                     'memo'                => 'Pelunasan Invoice ' . $invoice->invoice_nomor,
  29.                     'is_draft'            => false
  30.                 ]
  31.             ];
  32.  
  33.             // Call API Mekari
  34.             $response = $this->mekari_jurnal->request(
  35.                 'POST',
  36.                 '/public/jurnal/api/v1/receive_payments',
  37.                 $payload
  38.             );
  39.  
  40.             $httpCode = $response['http_code'] ?? 0;
  41.             if ($httpCode === 201 && isset($response['response']['receive_payment']['id'])) {
  42.                 $receivePayment = $response['response']['receive_payment'];
  43.                 // Update invoice lokal → PAID
  44.                 $this->db->where('invoice_id', $invoice->invoice_id)->update('sid_invoice', [
  45.                     'invoice_jurnal_paid_id'        => $receivePayment['id'],
  46.                     'invoice_jurnal_paid_at'        => date('Y-m-d H:i:s'),
  47.                     'invoice_jurnal_paid_status'    => 'paid',
  48.                     'invoice_update'                => date('Y-m-d H:i:s'),
  49.                     'invoice_jurnal_paid_resp'      => json_encode($receivePayment)
  50.                 ]);
  51.  
  52.                 return [
  53.                     'success' => true,
  54.                 ];
  55.             }
  56.  
  57.             // Jika gagal
  58.             return [
  59.                 'success' => false,
  60.                 'message' => 'Gagal set paid. HTTP Code: ' . $httpCode,
  61.                 'error'   => $response['response'] ?? []
  62.             ];
  63.  
  64.         } catch (Exception $e) {
  65.             return ['success' => false, 'message' => $e->getMessage()];
  66.         }
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment