From 0856fc2dfd166586f953532074f9a770f5aaf540 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 8 Sep 2019 22:13:55 +1000 Subject: [PATCH] Working on gateway payment flow --- app/DataMapper/ClientSettings.php | 2 + app/DataMapper/CompanySettings.php | 4 +- .../ClientPortal/PaymentMethodController.php | 2 +- app/Http/Kernel.php | 1 + app/Models/Client.php | 10 ++++- app/Models/GatewayType.php | 17 +++++++ app/Models/PaymentType.php | 1 - app/PaymentDrivers/BasePaymentDriver.php | 37 +++++++++++++++- app/PaymentDrivers/StripePaymentDriver.php | 44 ++++++++++++++++--- .../portal/default/dashboard/index.blade.php | 2 +- 10 files changed, 106 insertions(+), 14 deletions(-) diff --git a/app/DataMapper/ClientSettings.php b/app/DataMapper/ClientSettings.php index aafe44213761..e4d04f59ba73 100644 --- a/app/DataMapper/ClientSettings.php +++ b/app/DataMapper/ClientSettings.php @@ -90,6 +90,8 @@ class ClientSettings extends BaseSettings public $size_id; public $design; + + public $default_company_gateway_id; /** * Cast object values and return entire class * prevents missing properties from not being returned diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 11bfa5c33797..26518c671867 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -112,6 +112,8 @@ class CompanySettings extends BaseSettings public $counter_padding; public $design; + + public $default_company_gateway_id; /** * Cast object values and return entire class * prevents missing properties from not being returned @@ -166,7 +168,7 @@ class CompanySettings extends BaseSettings 'client_number_prefix' => '', 'auto_archive_invoice' => 'FALSE', 'design' => 'views/pdf/design1.blade.php', - + 'translations' => (object) [], ]; } diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index ae556d59d058..f879b8c74966 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -35,7 +35,7 @@ class PaymentMethodController extends Controller */ public function create() { - // + echo 'hello'; } /** diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 5ca9eb1dc96c..976ceb81325b 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -104,5 +104,6 @@ class Kernel extends HttpKernel 'contact_token_auth' => \App\Http\Middleware\ContactTokenAuth::class, 'contact_db' => \App\Http\Middleware\ContactSetDb::class, 'domain_db' => \App\Http\Middleware\SetDomainNameDb::class, + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, ]; } diff --git a/app/Models/Client.php b/app/Models/Client.php index 1c1011c17772..0216509fa790 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -154,7 +154,15 @@ class Client extends BaseModel public function getPaymentMethods() { - + $settings = $this->getMergedSettings(); + + /* If we have a single default gateway - pass this back now.*/ + if($settings->default_company_gateway_id); + return $settings->default_company_gateway_id; + + /* If there is no default, then we pass back the Collection of gateways */ + + $gateways = $this->company->company_gateways; } diff --git a/app/Models/GatewayType.php b/app/Models/GatewayType.php index 6f5000e2935c..9a0a0dc0247f 100644 --- a/app/Models/GatewayType.php +++ b/app/Models/GatewayType.php @@ -16,12 +16,29 @@ use Illuminate\Database\Eloquent\Model; class GatewayType extends Model { + public $timestamps = false; + const CREDIT_CARD = 1; + const BANK_TRANSFER = 2; + const PAYPAL = 3; + const BITCOIN = 4; + const DWOLLA = 5; + const CUSTOM1 = 6; + const ALIPAY = 7; + const SOFORT = 8; + const SEPA = 9; + const GOCARDLESS = 10; + const APPLE_PAY = 11; + const CUSTOM2 = 12; + const CUSTOM3 = 13; + const TOKEN = 'token'); + public function gateway() { return $this->belongsTo(Gateway::class); } + } diff --git a/app/Models/PaymentType.php b/app/Models/PaymentType.php index 100d939184fb..801f579c2868 100644 --- a/app/Models/PaymentType.php +++ b/app/Models/PaymentType.php @@ -15,5 +15,4 @@ use Illuminate\Database\Eloquent\Model; class PaymentType extends Model { - // } diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index b50f1e2ffad8..dbae4625d889 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -12,6 +12,7 @@ namespace App\PaymentDrivers; use App\Models\CompanyGateway; +use App\Models\GatewayType; use Omnipay\Omnipay; @@ -27,14 +28,17 @@ class BasePaymentDriver /* The Omnipay payment driver instance*/ protected $gateway; + /* The Invitation */ + protected $invitation; + /* Member variables */ protected $refundable = false; protected $token_billing = false; - public function __construct(CompanyGateway $company_gateway) + public function __construct(CompanyGateway $company_gateway, $invitation = false) { $this->company_gateway = $company_gateway; - //$this->invitation = $invitation; + $this->invitation = $invitation; //$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0]; } @@ -67,6 +71,35 @@ class BasePaymentDriver } + public function invoice() + { + return $this->invitation->invoice; + } + + public function contact() + { + return $this->invitation->contact; + } + + public function client() + { + return $this->contact()->client; + } + + public function company() + { + return $this->invitation->company; + } + + /** + * Returns the default gateway type + */ + public function gatewayTypes() + { + return [ + GatewayType::CREDIT_CARD, + ]; + } public function setRefundable($value) { diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 4d8d913a0d94..25122935314f 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -11,6 +11,7 @@ namespace App\PaymentDrivers; +use App\Models\GatewayType; use Stripe\Stripe; class StripePaymentDriver extends BasePaymentDriver @@ -21,6 +22,7 @@ class StripePaymentDriver extends BasePaymentDriver protected $customer_reference = 'customerReferenceParam'; + public function boot() { $this->setRefundable($this->refundable); @@ -37,9 +39,44 @@ class StripePaymentDriver extends BasePaymentDriver * other gateways and therefore * relies on direct calls to the API */ + /************************************** Stripe API methods **********************************************************/ + public function init($api_key) + { + Stripe::setApiKey($api_key); + } + /** + * Returns the gateway types + */ + public function gatewayTypes() :array + { + $types = [ + GatewayType::CREDIT_CARD, + GatewayType::TOKEN, + ]; + + if($this->company_gateway->getSofortEnabled() && $this->invitation && $this->client() && isset($this->client()->country) && in_array($this->client()->country, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP'])) + $types[] = GatewayType::SOFORT; + if($this->company_gateway->getAchEnabled()) + $types[] = GatewayType::BANK_TRANSFER; + if ($this->company_gateway->getSepaEnabled()) + $types[] = GatewayType::SEPA; + + if ($this->company_gateway->getBitcoinEnabled()) + $types[] = GatewayType::BITCOIN; + + if ($this->company_gateway->getAlipayEnabled()) + $types[] = GatewayType::ALIPAY; + + if ($this->company_gateway->getApplePayEnabled()) + $types[] = GatewayType::APPLE_PAY; + + + return $types; + + } /************************************** Omnipay API methods **********************************************************/ @@ -48,11 +85,4 @@ class StripePaymentDriver extends BasePaymentDriver - /************************************** Stripe API methods **********************************************************/ - - public function init($api_key) - { - Stripe::setApiKey($api_key); - } - } \ No newline at end of file diff --git a/resources/views/portal/default/dashboard/index.blade.php b/resources/views/portal/default/dashboard/index.blade.php index 333f12ebe8fc..90da2f594a71 100644 --- a/resources/views/portal/default/dashboard/index.blade.php +++ b/resources/views/portal/default/dashboard/index.blade.php @@ -95,7 +95,7 @@
- + {{ ctrans('texts.add_payment_method')}}