diff --git a/app/Console/Commands/BillplzFailedCallbackPayment.php b/app/Console/Commands/BillplzFailedCallbackPayment.php new file mode 100644 index 00000000..e2b69858 --- /dev/null +++ b/app/Console/Commands/BillplzFailedCallbackPayment.php @@ -0,0 +1,98 @@ +appendToOutput(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)->whereIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::PENDING_VERIFICATION])->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; + $this->appendToOutput($counter . ' of ' . $totalTransactions . '. Order: '. $transaction->owner->owner->owner->reference . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount . '. Status: ' . $approvalStatusArray[$transaction->status]); + } 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->appendToOutput("billplz error
"); + } + $counter++; + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->appendToOutput(Carbon::now() . ' : Done Billplz Failled Callback. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount); + + $this->output = json_encode($this->outputArray); + } + + public function appendToOutput($string) { + $this->outputArray[] = $string; + $this->info($string); + } + + public function getOutput() + { + return $this->output; + } +} diff --git a/database/seeders/SegmentConstantsTableSeeder.php b/database/seeders/SegmentConstantsTableSeeder.php index ca1e0939..89b45700 100644 --- a/database/seeders/SegmentConstantsTableSeeder.php +++ b/database/seeders/SegmentConstantsTableSeeder.php @@ -38,7 +38,7 @@ class SegmentConstantsTableSeeder extends Seeder Segmentconstant::create( [ 'segment_id'=>1, 'reference'=>'STATE_RATE', - 'value'=>'[{"state_id":1,"center":"10.00","outstation":"2.00"},{"center":"10.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"50.00","outstation":"0.00"},{"center":"0.00","outstation":"0.00"},{"center":"345.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"10.00","outstation":"0.00"},{"center":"0.00","outstation":"0.00"},{"center":"185.00","outstation":"0.00"},{"center":"185.00","outstation":"0.00"},{"center":"0.00","outstation":"0.00"},{"center":"50.00","outstation":"0.00"}]', + 'value'=>'[{"state_id":1,"center":"10.00","outstation":"2.00"},{"center":"10.00","outstation":"10.00"},{"center":"10.00","outstation":"10.00"},{"center":"50.00","outstation":"50.00"},{"center":"12.00","outstation":"12.00"},{"center":"345.00","outstation":"345.00"},{"center":"10.00","outstation":"10.00"},{"center":"10.00","outstation":"10.00"},{"center":"10.00","outstation":"30.00"},{"center":"10.00","outstation":"20.00"},{"center":"10.00","outstation":"10.00"},{"center":"10.00","outstation":"10.00"},{"center":"15.00","outstation":"15.00"},{"center":"185.00","outstation":"23.00"},{"center":"185.00","outstation":"185.00"},{"center":"30.00","outstation":"30.00"},{"center":"50.00","outstation":"50.00"}]', 'deleted_at'=>NULL, 'created_at'=>NULL, 'updated_at'=>'2022-09-27 01:18:15'