fix error when getting transaction from shipping portal due to mistake in filters string

This commit is contained in:
JiaSheng
2023-09-14 15:01:30 +08:00
parent c374e46834
commit a8a22ca1c3
@@ -49,7 +49,7 @@ class CreateBankStatementTransactionOwnersProcessor
// Shipping Portal Sales
$creditTransactions = $this->getTransactionsFromShippingPortal($transaction->amount, $this->getDateRange($transaction->posting_date), 2);
$creditTransactions = $this->getTransactionsFromShippingPortal($transaction->amount, $this->getDateRange($transaction->posting_date), 2, PaymentMethodType::WALLET);
foreach ($creditTransactions as $creditTransaction) {
if($creditTransaction['owner_type'] === Wallet::class) continue;
$transaction->owners()->firstOrCreate([
@@ -73,7 +73,7 @@ class CreateBankStatementTransactionOwnersProcessor
]);
}
$creditTransactions = $this->getTransactionsFromShippingPortal($transaction->amount, $this->getDateRange($transaction->posting_date), 5);
$creditTransactions = $this->getTransactionsFromShippingPortal($transaction->amount, $this->getDateRange($transaction->posting_date), 5, null);
foreach ($creditTransactions as $creditTransaction) {
$transaction->owners()->firstOrCreate([
'type' => StatementTransactionOwnerType::WALLET_TOP_UP,
@@ -247,21 +247,25 @@ class CreateBankStatementTransactionOwnersProcessor
}
}
private function getTransactionsFromShippingPortal($amount, $dateRange, $type){
private function getTransactionsFromShippingPortal($amount, $dateRange, $type, $paymentMethod){
$url = 'https://izyim.cief-malaysia.com/public/api/v1/transactions/mappable/query';
return $this->getFromShippingPortal($amount, $dateRange, $url, $type);
return $this->getFromShippingPortal($amount, $dateRange, $url, $type, $paymentMethod);
}
private function getGroupsFromShippingPortal($amount, $dateRange, $type){
private function getGroupsFromShippingPortal($amount, $dateRange, $type, $paymentMethod){
$url = 'https://izyim.cief-malaysia.com/public/api/v1/groups/query';
return $this->getFromShippingPortal($amount, $dateRange, $url, $type);
return $this->getFromShippingPortal($amount, $dateRange, $url, $type, $paymentMethod);
}
private function getFromShippingPortal($amount, $dateRange, $url, $type){
private function getFromShippingPortal($amount, $dateRange, $url, $type, $paymentMethod){
$paymentMethodFilter = "";
if ($paymentMethod) {
$paymentMethodFilter = ',"payment_method_not_in":['.$paymentMethod.']';
}
try{
$client = new \GuzzleHttp\Client(['verify' => false]);
$response = $client->request('GET', $url.'?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"order_by":{"column":"id","DESC":true},"status_in":[2],"type":2,"created_after":"'.$dateRange['start_date'].'","created_before":"'.$dateRange['end_date'].'","amount_exceed":'.($amount - 0.01).',"amount_short":'.($amount + 0.01).',"type_in:"['.$type.']}');
$response = $client->request('GET', $url.'?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"order_by":{"column":"id","DESC":true},"status_in":[2]'.$paymentMethodFilter.',"created_after":"'.$dateRange['start_date'].'","created_before":"'.$dateRange['end_date'].'","amount_exceed":'.($amount - 0.01).',"amount_short":'.($amount + 0.01).',"type_in":['.$type.']}');
$body = $response->getBody();
$data = json_decode($body, true);
$payload = $data['payload'];