From 401db9143757389cfd9dffcc34f997ce54e9ba83 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 1 Apr 2023 18:20:22 +0800 Subject: [PATCH] final-duplicated-invoice-debug --- ...ssUpdatePaymentStatusButFailedCallback.php | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 app/Console/Commands/SuccessUpdatePaymentStatusButFailedCallback.php diff --git a/app/Console/Commands/SuccessUpdatePaymentStatusButFailedCallback.php b/app/Console/Commands/SuccessUpdatePaymentStatusButFailedCallback.php new file mode 100644 index 00000000..de66327e --- /dev/null +++ b/app/Console/Commands/SuccessUpdatePaymentStatusButFailedCallback.php @@ -0,0 +1,123 @@ +getBillplzBill = $getBillplzBill; + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; + $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; + } + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + ini_set('memory_limit', '-1'); + + $this->info(Carbon::now() . ' : Billplz Failled Callback cron started.'); + $this->outputArray = []; + $start = new Carbon(); + + $approvalStatusArray = ApprovalStatus::APPROVAL_STATUS_ID; + + $transactions = Transaction::where('type', TransactionType::PAYMENT) + ->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY) + ->get(); + + foreach ($transactions as $payment) { + $invoice = $payment->owner; + $packingList = $invoice->owner; + $order = $packingList->owner; + + if ($invoice->status == ApprovalStatus::APPROVED) { + + $totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount'); + + if(($invoice->amount - $totalPaidAmount) < 0.01) { + $this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); + + $packingList->status = ApprovalStatus::APPROVED; + $packingList->save(); + + if(app()->environment('production')){ + $this->updateDoFromVTPortalProcessor->execute($packingList); + $this->updateDoFromYDPortalProcessor->execute($packingList); + } + + $this->info('Updated invoice ' . $invoice->ID . '. Order: '. $order->reference); + } else { + $this->info('Failed Update invoice ' . $invoice->ID . '. Order: '. $order->reference); + } + } + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->info(Carbon::now() . ' : Done Billplz Failled Callback. ElapsedTime: ' . $elapsedTime ); + } +}