From ddee84ae966fe3dff664d4dfc6eea5b2c102c564 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 18 Oct 2017 19:57:57 +0300 Subject: [PATCH] Support using GoCardless with other gateways #1373 --- app/Constants.php | 1 + app/Models/Account.php | 2 +- app/Models/Gateway.php | 2 ++ app/Ninja/PaymentDrivers/GoCardlessV2RedirectPaymentDriver.php | 2 +- database/seeds/GatewayTypesSeeder.php | 1 + database/seeds/PaymentTypesSeeder.php | 1 + resources/lang/en/texts.php | 2 ++ resources/views/accounts/partials/payment_credentials.blade.php | 1 + 8 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Constants.php b/app/Constants.php index 5868fee665..b5008b43bf 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -422,6 +422,7 @@ if (! defined('APP_NAME')) { define('GATEWAY_TYPE_ALIPAY', 7); define('GATEWAY_TYPE_SOFORT', 8); define('GATEWAY_TYPE_SEPA', 9); + define('GATEWAY_TYPE_GOCARDLESS', 10); define('GATEWAY_TYPE_TOKEN', 'token'); define('TEMPLATE_INVOICE', 'invoice'); diff --git a/app/Models/Account.php b/app/Models/Account.php index db5ec2968a..e59def9377 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -810,7 +810,7 @@ class Account extends Eloquent $available = true; foreach ($gatewayTypes as $type) { - if ($paymentDriver->handles($type)) { + if ($type != GATEWAY_TYPE_TOKEN && $paymentDriver->handles($type)) { $available = false; break; } diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 8215f135d7..e3b07061cf 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -32,6 +32,7 @@ class Gateway extends Eloquent GATEWAY_TYPE_BITCOIN, GATEWAY_TYPE_DWOLLA, GATEWAY_TYPE_TOKEN, + GATEWAY_TYPE_GOCARDLESS, ]; // these will appear in the primary gateway select @@ -58,6 +59,7 @@ class Gateway extends Eloquent */ public static $alternate = [ GATEWAY_PAYPAL_EXPRESS, + GATEWAY_GOCARDLESS, GATEWAY_BITPAY, GATEWAY_DWOLLA, GATEWAY_CUSTOM, diff --git a/app/Ninja/PaymentDrivers/GoCardlessV2RedirectPaymentDriver.php b/app/Ninja/PaymentDrivers/GoCardlessV2RedirectPaymentDriver.php index 9e233b986e..0fd71fa0d5 100644 --- a/app/Ninja/PaymentDrivers/GoCardlessV2RedirectPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/GoCardlessV2RedirectPaymentDriver.php @@ -12,7 +12,7 @@ class GoCardlessV2RedirectPaymentDriver extends BasePaymentDriver public function gatewayTypes() { $types = [ - GATEWAY_TYPE_BANK_TRANSFER, + GATEWAY_TYPE_GOCARDLESS, GATEWAY_TYPE_TOKEN, ]; diff --git a/database/seeds/GatewayTypesSeeder.php b/database/seeds/GatewayTypesSeeder.php index 22c9702111..c7a3075a4c 100644 --- a/database/seeds/GatewayTypesSeeder.php +++ b/database/seeds/GatewayTypesSeeder.php @@ -18,6 +18,7 @@ class GatewayTypesSeeder extends Seeder ['alias' => 'alipay', 'name' => 'Alipay'], ['alias' => 'sofort', 'name' => 'Sofort'], ['alias' => 'sepa', 'name' => 'SEPA'], + ['alias' => 'gocardless', 'name' => 'GoCardless'], ]; foreach ($gateway_types as $gateway_type) { diff --git a/database/seeds/PaymentTypesSeeder.php b/database/seeds/PaymentTypesSeeder.php index 0e56db05b7..f140514805 100644 --- a/database/seeds/PaymentTypesSeeder.php +++ b/database/seeds/PaymentTypesSeeder.php @@ -39,6 +39,7 @@ class PaymentTypesSeeder extends Seeder ['name' => 'Alipay', 'gateway_type_id' => GATEWAY_TYPE_ALIPAY], ['name' => 'Sofort', 'gateway_type_id' => GATEWAY_TYPE_SOFORT], ['name' => 'SEPA', 'gateway_type_id' => GATEWAY_TYPE_SEPA], + ['name' => 'GoCardless', 'gateway_type_id' => GATEWAY_TYPE_GOCARDLESS], ]; foreach ($paymentTypes as $paymentType) { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 285ad68320..43fb7e45a4 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -506,6 +506,7 @@ $LANG = array( 'payment_type_credit_card' => 'Credit Card', 'payment_type_paypal' => 'PayPal', 'payment_type_bitcoin' => 'Bitcoin', + 'payment_type_gocardless' => 'GoCardless', 'knowledge_base' => 'Knowledge Base', 'partial' => 'Partial/Deposit', 'partial_remaining' => ':partial of :balance', @@ -1369,6 +1370,7 @@ $LANG = array( 'use_bank_on_file' => 'Use Bank on File', 'auto_bill_email_message' => 'This invoice will automatically be billed to the payment method on file on the due date.', 'bitcoin' => 'Bitcoin', + 'gocardless' => 'GoCardless', 'added_on' => 'Added :date', 'failed_remove_payment_method' => 'Failed to remove the payment method', 'gateway_exists' => 'This gateway already exists', diff --git a/resources/views/accounts/partials/payment_credentials.blade.php b/resources/views/accounts/partials/payment_credentials.blade.php index 696c0318bc..ee1a931375 100644 --- a/resources/views/accounts/partials/payment_credentials.blade.php +++ b/resources/views/accounts/partials/payment_credentials.blade.php @@ -50,4 +50,5 @@ {!! Former::populateField(GATEWAY_GOCARDLESS . '_accessToken', env('GOCARDLESS_TEST_TOKEN')) !!} +{!! Former::populateField(GATEWAY_GOCARDLESS . '_webhookSecret', env('GOCARDLESS_TEST_WEBHOOK_SECRET')) !!} {!! Former::populateField(GATEWAY_GOCARDLESS . '_testMode', 1) !!}