fix billplz checking unsuccessful payment
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Session;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use Billplz\Client;
|
||||
use Http\Client\Common\HttpMethodsClient;
|
||||
use Http\Adapter\Guzzle6\Client as GuzzleHttpClient;
|
||||
use Http\Message\MessageFactory\GuzzleMessageFactory;
|
||||
use Money\Money;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class updateUnsuccess extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'update:unsuccess';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if(config('app.env') != 'production'){
|
||||
$this->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']
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user