diff --git a/app/Http/Controllers/CinetpayController.php b/app/Http/Controllers/CinetpayController.php index c70c727..e532317 100644 --- a/app/Http/Controllers/CinetpayController.php +++ b/app/Http/Controllers/CinetpayController.php @@ -87,7 +87,7 @@ class CinetpayController extends Controller 'customer_address' => 'required|string', 'customer_city' => 'required_if:payment_method,CREDIT_CARD|string', 'customer_country' => 'required|string|size:2', - 'customer_state' => 'required_if:payment_method,CREDIT_CARD|string|size:2', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) + 'customer_state' => 'required_if:payment_method,CREDIT_CARD|string', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) 'customer_zip_code' => 'required_if:payment_method,CREDIT_CARD|string|size:5', 'reason' => 'required|string' ]); diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 7835c31..cde59c6 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -180,15 +180,17 @@ class PaymentController extends Controller } if(!empty($aggregator)){ - $rate = $aggregator->rates()->where(function ($q) use($countryCode) { - return $q->where('country', $countryCode)->orWhere('country','ALL'); - })->where('type', $paymentType) + $baseQuery = $aggregator->rates()->where('type', $paymentType) ->where('method', $paymentMethod) ->when($paymentChannel, function ($q) use($paymentChannel){ return $q->where('channel',$paymentChannel); - }) - ->latest() - ->first(); + }); + + $rate = (clone $baseQuery)->where('country', $countryCode)->first(); + if(empty($rate)){ + $rate = (clone $baseQuery)->where('country','ALL')->first(); + } + if(!empty($rate)){ if(!empty($rate->fixed_fees)){ diff --git a/app/Http/Controllers/StripeController.php b/app/Http/Controllers/StripeController.php index 710b33a..5354d63 100644 --- a/app/Http/Controllers/StripeController.php +++ b/app/Http/Controllers/StripeController.php @@ -73,7 +73,7 @@ class StripeController extends Controller 'customer_address' => 'required|string', 'customer_city' => 'required_if:payment_method,CARD|string', 'customer_country' => 'required|string|size:2', - 'customer_state' => 'required_if:payment_method,CARD|string|size:2', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) + 'customer_state' => 'required_if:payment_method,CARD|string', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) 'customer_zip_code' => 'required_if:payment_method,CARD|string|size:5', 'reason' => 'required|string' ]); @@ -251,8 +251,8 @@ class StripeController extends Controller 'customer_address' => 'required|string', 'customer_city' => 'required|string', 'customer_country' => 'required|string|size:2', - 'customer_state' => 'required_if:customer_country,US|string|size:2', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) - 'customer_zip_code' => 'required_if:customer_country,US|string|size:5', + 'customer_state' => 'nullable|string', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) + 'customer_zip_code' => 'nullable|string|size:5', 'reason' => 'required|string' ]); @@ -379,8 +379,8 @@ class StripeController extends Controller 'customer_address' => 'required|string', 'customer_city' => 'required|string', 'customer_country' => 'required|string|size:2', - 'customer_state' => 'required_if:customer_country,US|string|size:2', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) - 'customer_zip_code' => 'required_if:customer_country,US|string|size:5', + 'customer_state' => 'nullable|string', //Etat du pays dans lequel se trouve le client. Cette valeur est obligatoire si le client se trouve au États Unis d’Amérique (US) ou au Canada (CA) + 'customer_zip_code' => 'nullable|string|size:5', 'reason' => 'required|string' ]); diff --git a/database/migrations/2023_07_17_110454_update_customer_state_in_payment_transactions.php b/database/migrations/2023_07_17_110454_update_customer_state_in_payment_transactions.php new file mode 100644 index 0000000..7019847 --- /dev/null +++ b/database/migrations/2023_07_17_110454_update_customer_state_in_payment_transactions.php @@ -0,0 +1,32 @@ +string('customer_state')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('payment_transactions', function (Blueprint $table) { + $table->string('customer_state',2)->change(); + }); + } +};