From b32efe96e1984cc37ae10cc34e4362d860d6766d Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Fri, 14 Jul 2023 13:56:21 +0100 Subject: [PATCH] fix: improve where clause while fetch aggregator rates during fees calculation --- app/Enums/PaymentMethod.php | 11 +++++++++++ app/Http/Controllers/PaymentController.php | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 app/Enums/PaymentMethod.php diff --git a/app/Enums/PaymentMethod.php b/app/Enums/PaymentMethod.php new file mode 100644 index 0000000..dfc8163 --- /dev/null +++ b/app/Enums/PaymentMethod.php @@ -0,0 +1,11 @@ +code_country; - if($paymentMethod == 'CARD'){ + if($paymentMethod == PaymentMethod::CARD){ $aggregator = PaymentAggregator::where('name','like','%stripe%')->first(); } - if($paymentMethod == 'WALLET'){ + if($paymentMethod == PaymentMethod::WALLET){ $aggregator = PaymentAggregator::where('status',1)->first(); } if(!empty($aggregator)){ - $rate = $aggregator->rates()->where('country', $countryCode)->orWhere('country','ALL')->where('type', $paymentType) - ->where('method', $paymentMethod)->when($paymentChannel, function ($q) use($paymentChannel){ + $rate = $aggregator->rates()->where(function ($q) use($countryCode) { + return $q->where('country', $countryCode)->orWhere('country','ALL'); + })->where('type', $paymentType) + ->where('method', $paymentMethod) + ->when($paymentChannel, function ($q) use($paymentChannel){ return $q->where('channel',$paymentChannel); - })->first(); + }) + ->latest() + ->first(); if(!empty($rate)){ if(!empty($rate->fixed_fees)){