diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index ee24a565dbd8..4ecc39cb0cf6 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -48,7 +48,10 @@ class PaymentMethodController extends Controller 'token' => false, ]; - return $gateway->driver(auth()->user()->client)->authorizeCreditCardView($data); + return $gateway + ->driver(auth()->user()->client) + ->setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard') + ->authorizeView($data); } /** diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php new file mode 100644 index 000000000000..deaa654e651e --- /dev/null +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -0,0 +1,40 @@ +stripe = $stripe; + } + + /** + * Authorises a credit card for future use. + * + * @param array $data Array of variables needed for the view. + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function authorizeView(array $data) + { + $intent['intent'] = $this->stripe->getSetupIntent(); + + return render('gateways.stripe.add_credit_card', array_merge($data, $intent)); + } +} \ No newline at end of file diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index f53f34e1154a..d221cada8e92 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -40,6 +40,8 @@ class StripePaymentDriver extends BasePaymentDriver protected $customer_reference = 'customerReferenceParam'; + protected $payment_method; + /** * Methods in this class are divided into * two separate streams @@ -62,6 +64,21 @@ class StripePaymentDriver extends BasePaymentDriver Stripe::setApiKey($this->company_gateway->getConfigField('apiKey')); } + /** + * Return payment method type. + * + * @param string $method + * @return $this + */ + public function setPaymentMethod(string $method) + { + // Example: setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard'); + + $this->payment_method = new $method($this); + + return $this; + } + /** * Returns the gateway types */ @@ -128,16 +145,15 @@ class StripePaymentDriver extends BasePaymentDriver } /** - * Authorises a credit card for future use. - * - * @param array $data Array of variables needed for the view + * Proxy method to pass the data into payment method authorizeView(). + * + * @param array $data + * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function authorizeCreditCardView(array $data) + public function authorizeView(array $data) { - $intent['intent'] = $this->getSetupIntent(); - - return render('gateways.stripe.add_credit_card', array_merge($data, $intent)); + return $this->payment_method->authorizeView($data); } /** @@ -400,12 +416,12 @@ class StripePaymentDriver extends BasePaymentDriver return $payment; } - private function convertFromStripeAmount($amount, $precision) + public function convertFromStripeAmount($amount, $precision) { return $amount / pow(10, $precision); } - private function convertToStripeAmount($amount, $precision) + public function convertToStripeAmount($amount, $precision) { return $amount * pow(10, $precision); }