Try adding -vvv to the command to see if you can get the stack trace and see what line causes the error.
Sep 23, 2021
6
Level 1
Method does not exist In Macroable.php line 96
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Models\Payment;
class TransactionQuery extends Command
{
use DispatchesJobs;
/**
* The name and signature of the console command.
* @var string
* YEE HAO: How to write command signature
*
*/
protected $signature = 'richmart:transaction-query
{type=all : Check all transaction base on transaction type (FPX) Value: fpx, (Online Banking) Value: visamaster, (Check All) Value: all}
{--pay_id=* : Check specified transaction base on payment id (optional)}
{--ref_num=* : Check specified transaction base on reference number (optional)}
{--user=* : Check all transaction base on user_id (optional)}
{--date=* : Check all transaction base on date start with format:YYYYMMDD (optional)}
';
// php artisan transactionQuery:check all --user=0 --date=20200101
/**
* The console command description.
*
* @var string
*/
protected $description = 'Transaction query check and update status';
protected $type = [
'all',
'fpx',
'visamaster'
];
// Create a new cURL resource
protected $curl;
protected $gateway;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @param SiteCountService $service
* @return mixed
*/
public function handle()
{
$type = 'all';
$user = false;
$date = false;
$query = new Payment;
$status = [0];
if ($this->argument('type')) {
$key = array_search(strtolower($this->argument('type')), $this->type);
if($key){
$query = $query->where('gatewayname', $this->type[$key]);
if($this->type[$key] == 'fpx' || $this->type[$key] == 'all'){
$status[] = 1;
$status[] = 5;
}
if($this->type[$key] == 'visamaster' || $this->type[$key] == 'all'){
$status[] = 'N';
}
$query = $query->whereIn('payment_status', $status); // set this for intitial
}
}
if ($this->option('user')) {
$user_id = (int)$this->option('user')[0];
if($user_id > 0){
$query = $query->where('user_id', $user_id);
}
}
if ($this->option('pay_id')) {
// get the result based on payment id
$query->whereIn('id', $this->option('pay_id'));
}
if ($this->option('ref_num')) {
// get the result based on refence number
$query->whereIn('reference_number', $this->option('ref_num'));
}
if ($this->option('date')) {
// check is valid or not
$datetime = Carbon::createFromFormat('Ymd', $this->option('date')[0]);
$query->where('created_at', '>=', $datetime->timestamp);
}
// do the Query range
// dd($query->toSql());
$data = $query->get();
if($data->count() > 0){
$this->curl = curl_init();
if (!$this->curl) {
dd("Couldn't initialize a cURL handle");
}
// split the data into queue
// batch queue run
foreach ($data as $value) {
$gatewayname = $value->gatewayname;
$this->$gatewayname($value);
}
// close cURL resource to free up system resources
curl_close($this->curl);
}
}
private function fpx($data)
{
// cUrl
// https://catswhocode.com/php-curl-example/
// https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code
// Array to Http Query
// https://www.php.net/manual/en/function.http-build-query.php
$type = 1;
$api_key = env('CLIENT_API_key') ? env('CLIENT_API_key') : 'RICH';
$seller_id = env('FPX_seller_ID') ? env('FPX_seller_ID') : 'SE00011833';
$total = str_replace(".", "", $data->amount); // request amount
$signature = hash('sha256', $api_key . $seller_id . $data->reference_number . $total);
$this->gateway = 'fpx';
$data = [
'seller_id' => $seller_id,
'seller_code' => "476292",
'gateway_txn_ref' => $data->gateway_txn_ref,
'seller_order_no' => $data->reference_number,
'txn_amount' => $data->amount,
'signature' => $signature,
];
$data = http_build_query($data, '&');
$server_output = $this->run_curl($data);
if($server_output === false)
{
echo 'Curl error: ' . curl_error($this->curl);
}
else
{
echo 'Operation completed without any errors, you have the response';
}
// if ($server_output == "OK") {
// } else {
// if(!$server_output){
// dd('Missing input url or data cuz');
// }else{
// dd($server_output);
// }
// }
}
private function visamaster($data)
{
// cUrl
// https://catswhocode.com/php-curl-example/
// https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code
// Array to Http Query
// https://www.php.net/manual/en/function.http-build-query.php
$type = 1;
$total = str_replace(".", "", $data->amount);
$signature = hash('sha256', $type . env('VISAMASTER_ACC_NO') . $data->reference_number . $total);
$this->gateway = 'visamaster';
$data = [
'AMOUNT' => $data->amount,
'MERCHANT_ACC_NO' => env('VISAMASTER_ACC_NO') ? env('VISAMASTER_ACC_NO') : "00000901053679748228147",
'MERCHANT_TRANID' => $data->reference_number,
'PASSWORD' => env('VISAMASTER_PASS') ? env('VISAMASTER_PASS') : "PwpMijHM",
'TRANSACTION_TYPE' => $type,
'SIGNATURE' => $signature,
'RETURN_URL' => route('respond.query.visamaster'),
];
$data = http_build_query($data, '&');
$server_output = run_curl($data);
if ($server_output == "OK") {
} else {
if(!$server_output){
dd('Missing input url or data cuz');
}else{
dd($server_output);
}
}
}
private function run_curl($data){
if($data){
$url = config('pay.' . $this->gateway . '.' . env('APP_ENV') . '.' . 'TransactionQueryRequest');
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_HEADER, 0);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $data);
// CURLOPT_CONNECTTIMEOUT - The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
// CURLOPT_TIMEOUT - The maximum number of seconds to allow cURL functions to execute.
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($this->curl, CURLOPT_TIMEOUT, 400); // timeout in seconds
$server_output = curl_exec($this->curl);
return $server_output;
// return $this->curl;
}else{
return false;
}
}
}
This my current code. When I run the job I get the output like this
php artisan richmart:transaction-query
Operation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the responseOperation completed without any errors, you have the response
In Macroable.php line 96:
Method does not exist.
I have no idea how to solve this.please helo
Level 102
Yup.. You are trying to call a method stored in the data.. So my guess is that you are getting a method name that does not exist
Try adding this and see what names it is trying to work with..
$gatewayname = $value->gatewayname;
$this->info($gatewayname);
$this->$gatewayname($value); // this line throws the error
Please or to participate in this conversation.