diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 150a3230549d..f7878e767f8e 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -14,7 +14,7 @@ namespace App\Http\Controllers\ClientPortal; use App\Events\Payment\Methods\MethodDeleted; use App\Http\Controllers\Controller; -use App\Http\Requests\ClientPortal\CreatePaymentMethodRequest; +use App\Http\Requests\ClientPortal\PaymentMethod\CreatePaymentMethodRequest; use App\Http\Requests\Request; use App\Models\ClientGatewayToken; use App\Models\GatewayType; @@ -52,7 +52,7 @@ class PaymentMethodController extends Controller $data['gateway'] = $gateway; $data['client'] = auth()->user()->client; - + return $gateway ->driver(auth()->user()->client) ->setPaymentMethod($request->query('method')) @@ -93,7 +93,7 @@ class PaymentMethodController extends Controller public function verify(ClientGatewayToken $payment_method) { // $gateway = $this->getClientGateway(); - + return $payment_method->gateway ->driver(auth()->user()->client) ->setPaymentMethod(request()->query('method')) diff --git a/app/Http/Requests/ClientPortal/CreatePaymentMethodRequest.php b/app/Http/Requests/ClientPortal/CreatePaymentMethodRequest.php deleted file mode 100644 index 7997eb9efa69..000000000000 --- a/app/Http/Requests/ClientPortal/CreatePaymentMethodRequest.php +++ /dev/null @@ -1,31 +0,0 @@ -user()->client->getCreditCardGateway() ? true : false; - } - - /** - * Get the validation rules that apply to the request. - * - * @return array - */ - public function rules() - { - return [ - // - ]; - } -} diff --git a/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php b/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php new file mode 100644 index 000000000000..d90438ac8c52 --- /dev/null +++ b/app/Http/Requests/ClientPortal/PaymentMethod/CreatePaymentMethodRequest.php @@ -0,0 +1,48 @@ +user()->client; + + $available_methods = []; + + collect($client->service()->getPaymentMethods(1)) + ->filter(function ($method) use (&$available_methods) { + $available_methods[] = $method['gateway_type_id']; + }); + + if (in_array($this->query('method'), $available_methods)) { + return true; + } + + return false; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // + ]; + } +} diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index c0a4e1fbf1ab..76874570c106 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -54,11 +54,13 @@ class AuthorizePaymentDriver extends BaseDriver /** * Returns the gateway types. */ - public function gatewayTypes() :array + public function gatewayTypes(): array { - $types = [ - GatewayType::CREDIT_CARD, - ]; + $types = []; + + if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) { + $types[] = GatewayType::CREDIT_CARD; + } return $types; } diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index 9ff335b2b02e..2fb1c391b3ff 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -25,6 +25,8 @@ use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\Braintree\CreditCard; use App\PaymentDrivers\Braintree\PayPal; +use Braintree\Gateway; +use Exception; use Illuminate\Http\Request; class BraintreePaymentDriver extends BaseDriver @@ -36,7 +38,7 @@ class BraintreePaymentDriver extends BaseDriver public $can_authorise_credit_card = true; /** - * @var \Braintree\Gateway; + * @var Gateway; */ public $gateway; @@ -49,7 +51,7 @@ class BraintreePaymentDriver extends BaseDriver public function init(): void { - $this->gateway = new \Braintree\Gateway([ + $this->gateway = new Gateway([ 'environment' => $this->company_gateway->getConfigField('testMode') ? 'sandbox' : 'production', 'merchantId' => $this->company_gateway->getConfigField('merchantId'), 'publicKey' => $this->company_gateway->getConfigField('publicKey'), @@ -68,10 +70,15 @@ class BraintreePaymentDriver extends BaseDriver public function gatewayTypes(): array { - return [ - GatewayType::CREDIT_CARD, + $types = [ GatewayType::PAYPAL, ]; + + if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) { + $types[] = GatewayType::CREDIT_CARD; + } + + return $types; } public function authorizeView($data) @@ -126,11 +133,11 @@ class BraintreePaymentDriver extends BaseDriver return [ 'transaction_reference' => $response->id, 'transaction_response' => json_encode($response), - 'success' => (bool) $response->success, + 'success' => (bool)$response->success, 'description' => $response->status, 'code' => 0, ]; - } catch (\Exception $e) { + } catch (Exception $e) { return [ 'transaction_reference' => null, 'transaction_response' => json_encode($e->getMessage()), @@ -174,7 +181,7 @@ class BraintreePaymentDriver extends BaseDriver 'gateway_type_id' => GatewayType::CREDIT_CARD, ]; - $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + $payment = $this->createPayment($data, Payment::STATUS_COMPLETED); SystemLogger::dispatch( ['response' => $result, 'data' => $data], diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 1036c556b7b0..9b681f1eb1cc 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -72,11 +72,15 @@ class CheckoutComPaymentDriver extends BaseDriver /** * Returns the default gateway type. */ - public function gatewayTypes() + public function gatewayTypes(): array { - return [ - GatewayType::CREDIT_CARD, - ]; + $types = []; + + if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) { + $types[] = GatewayType::CREDIT_CARD; + } + + return $types; } /** @@ -232,7 +236,7 @@ class CheckoutComPaymentDriver extends BaseDriver 'transaction_reference' => $response->id, ]; - $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + $payment = $this->createPayment($data, Payment::STATUS_COMPLETED); SystemLogger::dispatch( ['response' => $response, 'data' => $data], @@ -269,11 +273,11 @@ class CheckoutComPaymentDriver extends BaseDriver return false; } - } catch (\Exception | CheckoutHttpException $e) { + } catch (Exception | CheckoutHttpException $e) { $this->unWindGatewayFees($payment_hash); $message = $e instanceof CheckoutHttpException - ? $e->getBody() - : $e->getMessage(); + ? $e->getBody() + : $e->getMessage(); $data = [ 'status' => '', diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 21e4577b1d2c..700a4c6a97d2 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -32,7 +32,9 @@ use App\PaymentDrivers\Stripe\UpdatePaymentMethods; use App\PaymentDrivers\Stripe\Utilities; use App\Utils\Traits\MakesHash; use Exception; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Carbon; +use Laracasts\Presenter\Exceptions\PresenterException; use Stripe\Account; use Stripe\Customer; use Stripe\Exception\ApiErrorException; @@ -52,7 +54,7 @@ class StripePaymentDriver extends BaseDriver public $can_authorise_credit_card = true; - /** @var \Stripe\StripeClient */ + /** @var StripeClient */ public $stripe; protected $customer_reference = 'customerReferenceParam'; @@ -112,12 +114,13 @@ class StripePaymentDriver extends BaseDriver public function gatewayTypes(): array { $types = [ - GatewayType::CREDIT_CARD, GatewayType::CRYPTO, -// GatewayType::SEPA, // TODO: Missing implementation -// GatewayType::APPLE_PAY, // TODO:: Missing implementation ]; + if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) { + $types[] = GatewayType::CREDIT_CARD; + } + if ($this->client && isset($this->client->country) && in_array($this->client->country->iso_3166_3, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP'])) { @@ -126,7 +129,8 @@ class StripePaymentDriver extends BaseDriver if ($this->client && isset($this->client->country) - && in_array($this->client->country->iso_3166_3, ['USA'])) { + && in_array($this->client->country->iso_3166_3, ['USA']) + && $this->company_gateway->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled) { $types[] = GatewayType::BANK_TRANSFER; } @@ -193,7 +197,7 @@ class StripePaymentDriver extends BaseDriver $fields[] = ['name' => 'client_state', 'label' => ctrans('texts.state'), 'type' => 'text', 'validation' => 'required']; $fields[] = ['name' => 'client_country_id', 'label' => ctrans('texts.country'), 'type' => 'text', 'validation' => 'required']; } - + $fields[] = ['name' => 'client_postal_code', 'label' => ctrans('texts.postal_code'), 'type' => 'text', 'validation' => 'required']; if ($this->company_gateway->require_shipping_address) { @@ -213,7 +217,7 @@ class StripePaymentDriver extends BaseDriver * Proxy method to pass the data into payment method authorizeView(). * * @param array $data - * @return \Illuminate\Http\RedirectResponse|mixed + * @return RedirectResponse|mixed */ public function authorizeView(array $data) { @@ -224,7 +228,7 @@ class StripePaymentDriver extends BaseDriver * Processes the gateway response for credit card authorization. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\RedirectResponse|mixed + * @return RedirectResponse|mixed */ public function authorizeResponse($request) { @@ -235,7 +239,7 @@ class StripePaymentDriver extends BaseDriver * Process the payment with gateway. * * @param array $data - * @return \Illuminate\Http\RedirectResponse|mixed + * @return RedirectResponse|mixed */ public function processPaymentView(array $data) { @@ -293,7 +297,7 @@ class StripePaymentDriver extends BaseDriver * Finds or creates a Stripe Customer object. * * @return null|Customer A Stripe customer object - * @throws \Laracasts\Presenter\Exceptions\PresenterException + * @throws PresenterException * @throws ApiErrorException */ public function findOrCreateCustomer(): ?Customer