From 662aa3aed1a39ed170a90a290169a72d10f41beb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Sep 2019 21:03:25 +1000 Subject: [PATCH] Working on credit card auth response --- .../ClientPortal/PaymentMethodController.php | 4 ++ app/PaymentDrivers/BasePaymentDriver.php | 7 +- app/PaymentDrivers/StripePaymentDriver.php | 71 ++++++++++++++++++- .../gateways/stripe/create_customer.blade.php | 9 +++ 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index ddc2b5a93c09..0a22797b82c2 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -54,6 +54,10 @@ class PaymentMethodController extends Controller public function store(Request $request) { + $gateway = auth()->user()->client->getCreditCardGateway(); + + return $gateway->driver(auth()->user()->client)->authorizeCreditCardResponse($request); + } /** diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 67ab74648254..71dbabc8d1fa 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -109,10 +109,11 @@ class BasePaymentDriver * Refunds a given payment * @return void */ - public function refundPayment() - { + public function refundPayment() {} - } + public function authorizeCreditCardView($data) {} + + public function authorizeCreditCardResponse($request) {} /************************************* Omnipay ****************************************** authorize($options) - authorize an amount on the customer's card diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 5bd6e8eaaf30..ba1d4fd93ab5 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -115,10 +115,77 @@ class StripePaymentDriver extends BasePaymentDriver { $intent['intent'] = $this->getSetupIntent(); - - return view('portal.default.gateways.stripe.create_customer', array_merge($data, $intent)); + } + + public function authorizeCreditCardResponse($request) + { + /** + * { + "id": "seti_1FJHmuKmol8YQE9DdhDgFXhT", + "object": "setup_intent", + "cancellation_reason": null, + "client_secret": "seti_1FJHmuKmol8YQE9DdhDgFXhT_secret_FoveetSB7RewVngU7H6IcrH9dlM1BXd", + "created": 1568631032, + "description": null, + "last_setup_error": null, + "livemode": false, + "next_action": null, + "payment_method": "pm_1FJHvQKmol8YQE9DV19fPXXk", + "payment_method_types": [ + "card" + ], + "status": "succeeded", + "usage": "off_session" + + } + + +\Stripe\Stripe::setApiKey('sk_test_faU9gVB7Hx19fCTo0e5ggZ0x'); + +\Stripe\PaymentMethod::retrieve('pm_1EUmzw2xToAoV8choYUtciXR'); + + +{ + "id": "pm_1EUmzw2xToAoV8choYUtciXR", + "object": "payment_method", + "card": { + "brand": "visa", + "checks": { + "address_line1_check": null, + "address_postal_code_check": null, + "cvc_check": null + }, + "country": "US", + "exp_month": 8, + "exp_year": 2020, + "fingerprint": "sStRRZt3Xlw0Ec6B", + "funding": "credit", + "generated_from": null, + "last4": "4242", + "three_d_secure_usage": { + "supported": true + }, + "wallet": null + }, + "created": 1556596276, + "customer": "cus_3fAHf0I56s1QFx", + "livemode": false, + "metadata": {}, + "type": "card" +} + + */ + + + //get the customer or create a new one. + //get the payment method + //attached payment method to customer + //store meta data + + + } /** 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 7584b82dfd74..ec2c0cdbfe20 100644 --- a/resources/views/portal/default/gateways/stripe/create_customer.blade.php +++ b/resources/views/portal/default/gateways/stripe/create_customer.blade.php @@ -73,6 +73,15 @@ $("#card-button").attr("disabled", true); }); + + var form = $(document.createElement('form')); + $(form).attr("action", "{{ route('client.payment_methods.store') }}"); + $(form).attr("method", "POST"); + + var input = $("").attr("type", "hidden").attr("name", "mydata").val("bla"); + $(form).append($(input)); + $(form).submit(); + @endpush