fix: improve where clause while fetch aggregator rates during fees calculation

This commit is contained in:
Djery-Tom 2023-07-14 13:56:21 +01:00
parent 81796c15bb
commit b32efe96e1
2 changed files with 22 additions and 5 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace App\Enums;
abstract class PaymentMethod
{
const CARD = 'CARD'; // Les remboursements ou recharges vers des clients
const WALLET = 'WALLET'; // Les paiements effectués par les clients
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Enums\PaymentMethod;
use App\Enums\PaymentTransactionStatus;
use App\Models\Country;
use App\Models\PaymentAggregator;
@ -170,19 +171,24 @@ class PaymentController extends Controller
$countryCode = $country->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)){