Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function create_receive_payment_paid($invoice, $invoice_jurnal_id, $customer_jurnal_id)
- {
- try {
- // Validasi dasar
- if (empty($invoice_jurnal_id)) {
- return [
- 'success' => false,
- 'message' => 'Invoice Jurnal ID kosong'
- ];
- }
- // Amount = total invoice (karena konsepnya selalu full paid)
- $amount = (int) $invoice->invoice_total;
- // Payload Receive Payment (SINGLE)
- $payload = [
- 'receive_payment' => [
- 'transaction_date' => date('Y-m-d', strtotime($invoice->invoice_tgl_bayar)),
- 'records_attributes' => [
- [
- // WAJIB: ID invoice dari Mekari
- 'transaction_id' => (int) $invoice_jurnal_id,
- 'amount' => $amount
- ]
- ],
- 'custom_id' => 'RP-' . $invoice->invoice_nomor,
- 'payment_method_name' => 'Cash',
- 'deposit_to_name' => 'BRI-341001000011566',
- 'memo' => 'Pelunasan Invoice ' . $invoice->invoice_nomor,
- 'is_draft' => false
- ]
- ];
- // Call API Mekari
- $response = $this->mekari_jurnal->request(
- 'POST',
- '/public/jurnal/api/v1/receive_payments',
- $payload
- );
- $httpCode = $response['http_code'] ?? 0;
- if ($httpCode === 201 && isset($response['response']['receive_payment']['id'])) {
- $receivePayment = $response['response']['receive_payment'];
- // Update invoice lokal → PAID
- $this->db->where('invoice_id', $invoice->invoice_id)->update('sid_invoice', [
- 'invoice_jurnal_paid_id' => $receivePayment['id'],
- 'invoice_jurnal_paid_at' => date('Y-m-d H:i:s'),
- 'invoice_jurnal_paid_status' => 'paid',
- 'invoice_update' => date('Y-m-d H:i:s'),
- 'invoice_jurnal_paid_resp' => json_encode($receivePayment)
- ]);
- return [
- 'success' => true,
- ];
- }
- // Jika gagal
- return [
- 'success' => false,
- 'message' => 'Gagal set paid. HTTP Code: ' . $httpCode,
- 'error' => $response['response'] ?? []
- ];
- } catch (Exception $e) {
- return ['success' => false, 'message' => $e->getMessage()];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment