From 0f9f418e7e7a3a6cf100195aa57c8529a2677dfc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 17 Sep 2019 21:54:14 +1000 Subject: [PATCH] Add Credit card to client portal --- app/PaymentDrivers/StripePaymentDriver.php | 37 +++++++++++++++---- .../gateways/stripe/create_customer.blade.php | 7 ++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 3763f08efa47..1dba45bd22f1 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -145,7 +145,7 @@ class StripePaymentDriver extends BasePaymentDriver $gateway_id = $request->input('gateway_id'); $gateway_type_id = $request->input('payment_method_id'); - $is_default = $request->input('is_default') ?: 0; + $is_default = $request->input('is_default'); $payment_method = $server_response->payment_method; @@ -166,7 +166,7 @@ class StripePaymentDriver extends BasePaymentDriver $cgt->save(); - if($is_default) + if($is_default == 'true') { $this->client->gateway_tokens()->update(['is_default'=>0]); @@ -179,31 +179,51 @@ class StripePaymentDriver extends BasePaymentDriver /** * Creates a new String Payment Intent + * * @param array $data The data array to be passed to Stripe * @return PaymentIntent The Stripe payment intent object */ - public function createIntent($data) + public function createIntent($data) :?\Stripe\PaymentIntent { + $this->init(); + return PaymentIntent::create($data); + } /** - * Returns a setup intent that allows the user to enter card details without initiating a transaction. + * Returns a setup intent that allows the user + * to enter card details without initiating a transaction. * * @return \Stripe\SetupIntent */ - public function getSetupIntent() + public function getSetupIntent() :\Stripe\SetupIntent { + $this->init(); + return SetupIntent::create(); + } - public function getPublishableKey() + + /** + * Returns the Stripe publishable key + * @return NULL|string The stripe publishable key + */ + public function getPublishableKey() :?string { + return $this->company_gateway->getPublishableKey(); + } + /** + * Finds or creates a Stripe Customer object + * + * @return NULL|\Stripe\Customer A Stripe customer object + */ public function findOrCreateCustomer() :?\Stripe\Customer { @@ -213,8 +233,11 @@ class StripePaymentDriver extends BasePaymentDriver $client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)->whereCompanyGatewayId($this->company_gateway->id)->first(); - if($client_gateway_token && $client_gateway_token->gateway_customer_reference) + if($client_gateway_token && $client_gateway_token->gateway_customer_reference){ + $customer = \Stripe\Customer::retrieve($client_gateway_token->gateway_customer_reference); + + } else{ $data['name'] = $this->client->present()->name(); diff --git a/resources/views/portal/default/gateways/stripe/create_customer.blade.php b/resources/views/portal/default/gateways/stripe/create_customer.blade.php index f211791b4fd1..49e34df48c2a 100644 --- a/resources/views/portal/default/gateways/stripe/create_customer.blade.php +++ b/resources/views/portal/default/gateways/stripe/create_customer.blade.php @@ -28,7 +28,7 @@
- +
@@ -75,6 +75,7 @@ $("#card-errors").empty(); $("#card-errors").append("" + result.error.message + ""); + $("#card-button").removeAttr("disabled"); } else { // The setup has succeeded. Display a success message. @@ -97,9 +98,9 @@ { $("#gateway_response").val(JSON.stringify(result.setupIntent)); - $("#is_default").val($("#proxy_is_default").val()); + $("#is_default").val($('#proxy_is_default').is(":checked")); + $("#card-button").attr("disabled", true); $('#server_response').submit(); - }