From 92d91904d2489dde70656b6e354daaa513b7f851 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Aug 2021 14:05:45 +1000 Subject: [PATCH] Sepa --- app/PaymentDrivers/Stripe/SEPA.php | 109 +++++++++++++++++++++++++++++ composer.json | 1 + composer.lock | 59 +++++++++++++++- 3 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 app/PaymentDrivers/Stripe/SEPA.php diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php new file mode 100644 index 000000000000..d78d0c065b88 --- /dev/null +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -0,0 +1,109 @@ +stripe_driver = $stripe_driver; + } + + public function authorizeView(array $data) + { + $customer = $this->stripe_driver->findOrCreateCustomer(); + + $setup_intent = \Stripe\SetupIntent::create([ + 'payment_method_types' => ['sepa_debit'], + 'customer' => $customer->id, + ], $this->stripe_driver->stripe_connect_auth); + + $client_secret = $setup_intent->client_secret + // Pass the client secret to the client + + + $data['gateway'] = $this->stripe; + + return render('gateways.stripe.sepa.authorize', array_merge($data)); + } + + + public function paymentResponse(PaymentResponseRequest $request) + { + + // $this->stripe_driver->init(); + + // $state = [ + // 'server_response' => json_decode($request->gateway_response), + // 'payment_hash' => $request->payment_hash, + // ]; + + // $state['payment_intent'] = \Stripe\PaymentIntent::retrieve($state['server_response']->id, $this->stripe_driver->stripe_connect_auth); + + // $state['customer'] = $state['payment_intent']->customer; + + // $this->stripe_driver->payment_hash->data = array_merge((array) $this->stripe_driver->payment_hash->data, $state); + // $this->stripe_driver->payment_hash->save(); + + // $server_response = $this->stripe_driver->payment_hash->data->server_response; + + // $response_handler = new CreditCard($this->stripe_driver); + + // if ($server_response->status == 'succeeded') { + + // $this->stripe_driver->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe_driver->payment_hash], SystemLog::TYPE_STRIPE); + + // return $response_handler->processSuccessfulPayment(); + // } + + // return $response_handler->processUnsuccessfulPayment($server_response); + + + } + + /* Searches for a stripe customer by email + otherwise searches by gateway tokens in StripePaymentdriver + finally creates a new customer if none found + */ + private function getCustomer() + { + $searchResults = \Stripe\Customer::all([ + "email" => $this->stripe_driver->client->present()->email(), + "limit" => 1, + "starting_after" => null + ], $this->stripe_driver->stripe_connect_auth); + + + if(count($searchResults) >= 1) + return $searchResults[0]; + + return $this->stripe_driver->findOrCreateCustomer(); + + } +} + diff --git a/composer.json b/composer.json index 8595adacbbc3..1a43c7a250be 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "fakerphp/faker": "^1.14", "fideloper/proxy": "^4.2", "fruitcake/laravel-cors": "^2.0", + "gocardless/gocardless-pro": "^4.12", "google/apiclient": "^2.7", "guzzlehttp/guzzle": "^7.0.1", "hashids/hashids": "^4.0", diff --git a/composer.lock b/composer.lock index 89eea29d9e7b..a031a9c51a07 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "275a9dd3910b6ec79607b098406dc6c7", + "content-hash": "bcd9405b1978cef268d732794883e91d", "packages": [ { "name": "asm/php-ansible", @@ -2221,6 +2221,61 @@ ], "time": "2021-04-26T11:24:25+00:00" }, + { + "name": "gocardless/gocardless-pro", + "version": "4.12.0", + "source": { + "type": "git", + "url": "https://github.com/gocardless/gocardless-pro-php.git", + "reference": "e63b97b215c27179023dd2e911133ee75e543fbd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gocardless/gocardless-pro-php/zipball/e63b97b215c27179023dd2e911133ee75e543fbd", + "reference": "e63b97b215c27179023dd2e911133ee75e543fbd", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "guzzlehttp/guzzle": "^6.0 | ^7.0", + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "GoCardlessPro\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "GoCardless and contributors", + "homepage": "https://github.com/gocardless/gocardless-pro-php/contributors" + } + ], + "description": "GoCardless Pro PHP Client Library", + "homepage": "https://gocardless.com/", + "keywords": [ + "api", + "direct debit", + "gocardless" + ], + "support": { + "issues": "https://github.com/gocardless/gocardless-pro-php/issues", + "source": "https://github.com/gocardless/gocardless-pro-php/tree/v4.12.0" + }, + "time": "2021-08-12T15:41:16+00:00" + }, { "name": "google/apiclient", "version": "v2.10.1", @@ -14972,5 +15027,5 @@ "platform-dev": { "php": "^7.3|^7.4|^8.0" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.0.0" }