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)->whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get(); $totalTransactions = count($transactions); $counter = 1; $totalAmount = 0; foreach ($transactions as $transaction){ $response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference); if($response->successful()){ $data = $response->json(); if($data['paid']){ $totalAmount += $transaction->amount; $invoiceStatus = null; switch($transaction->owner->status) { case 3: $invoiceStatus = 'Payment Completed'; break; case 5: $invoiceStatus = 'Dispute in progress'; break; case 6: $invoiceStatus = 'Cancelled Invoice'; break; default: $invoiceStatus = 'Pending Payment'; } $order = $transaction->owner->owner->owner; if(!$order instanceof Order) { $this->info("Error transaction id:" . $transaction->id . 'Type: ' . get_class($order)); } else { $this->info($counter . ' of ' . $totalTransactions . '. Order: '. $order->reference . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount . '. Status: ' . $approvalStatusArray[$transaction->status] . '. Invoice Status: ' . $invoiceStatus); } } else { // $totalAmount += $transaction->amount; // $this->appendToOutput($counter . ' of ' . $totalTransactions . '. Order: '. $transaction->owner->owner->owner->reference . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount); } }else{ $this->info("billplz error
"); } $counter++; } $end = new Carbon(); $elapsedTime = $start->diff($end)->format('%H:%I:%S'); $this->info(Carbon::now() . ' : Done Billplz Failled Callback. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount); } }