diff --git a/app/Console/Commands/updateUnsuccess.php b/app/Console/Commands/updateUnsuccess.php new file mode 100644 index 0000000..3b7b791 --- /dev/null +++ b/app/Console/Commands/updateUnsuccess.php @@ -0,0 +1,93 @@ +api_key = 'abecfd0c-98d8-4635-abc2-2fcba8c60c11'; + $this->XSignature_Key = 'S-GWr7z03XjAhqPsFfu_H5nQ'; + $this->collection_id = 'z0r4kjhi'; + }else{ + $this->api_key = 'f3e82fe1-a422-4660-97f0-65cc59ff6c47'; + $this->XSignature_Key = 'S-alZUbzmD2_TF3vmrRqgehQ'; + } + } + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $http = new HttpMethodsClient( + new GuzzleHttpClient(), + new GuzzleMessageFactory() + ); + + $billplz = new Client($http, $this->api_key); + if(config('app.env') != 'production'){ + $billplz->useSandbox(); + } + $billplz->useVersion('v4'); + + $transaction = $billplz->bill(); + + $list_transaction = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/transaction/online/unsuccessful')->json(); + + if($list_transaction){ + foreach($list_transaction as $index=>$list){ + $show_transaction = $transaction->transaction($list['billplz_id']); + $data = $show_transaction->toArray(); + + if(!empty($data['transactions'])){ + if($data['transactions'][0]['status'] == 'completed'){ + Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/transaction/online/unsuccesfull/update',[ + 'billplz_id' => $data['bill_id'], + 'status' => 'PAID', + 'paid_at' => $data['transactions'][0]['completed_at'] + ]); + } + } + } + } + } +}