From 5c5dd7a27ea862b2aaa6a61659cdca6405bdbc46 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 7 Mar 2018 17:23:25 +0200 Subject: [PATCH] Added Paymill --- app/Constants.php | 1 + app/Http/Controllers/AccountController.php | 2 +- .../Controllers/AccountGatewayController.php | 2 + app/Listeners/HandleUserLoggedIn.php | 2 +- app/Models/AccountGateway.php | 19 +- .../PaymentDrivers/PaymillPaymentDriver.php | 27 +++ .../PaymentDrivers/StripePaymentDriver.php | 2 +- composer.json | 2 +- composer.lock | 63 ++++- database/seeds/PaymentLibrariesSeeder.php | 1 + .../views/accounts/account_gateway.blade.php | 13 +- resources/views/invoices/view.blade.php | 2 +- resources/views/payments/apple_pay.blade.php | 2 +- .../views/payments/credit_card.blade.php | 229 +++++++++--------- .../payments/paymill/credit_card.blade.php | 83 +++++++ .../payments/stripe/bank_transfer.blade.php | 2 +- .../payments/stripe/credit_card.blade.php | 4 +- .../views/payments/stripe/sepa.blade.php | 2 +- 18 files changed, 318 insertions(+), 140 deletions(-) create mode 100644 app/Ninja/PaymentDrivers/PaymillPaymentDriver.php create mode 100644 resources/views/payments/paymill/credit_card.blade.php diff --git a/app/Constants.php b/app/Constants.php index 8cc43497c799..3f57bbdc697d 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -301,6 +301,7 @@ if (! defined('APP_NAME')) { define('GATEWAY_BRAINTREE', 61); define('GATEWAY_CUSTOM', 62); define('GATEWAY_GOCARDLESS', 64); + define('GATEWAY_PAYMILL', 66); // The customer exists, but only as a local concept // The remote gateway doesn't understand the concept of customers diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 9361976f37ea..f4eec6c9fd33 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -473,7 +473,7 @@ class AccountController extends BaseController $trashedCount = AccountGateway::scope()->withTrashed()->count(); if ($accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) { - if (! $accountGateway->getPublishableStripeKey()) { + if (! $accountGateway->getPublishableKey()) { Session::now('warning', trans('texts.missing_publishable_key')); } } diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 5a112b9baae7..8c022828120a 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -183,6 +183,8 @@ class AccountGatewayController extends BaseController if ($gatewayId == GATEWAY_DWOLLA) { $optional = array_merge($optional, ['key', 'secret']); + } elseif ($gatewayId == GATEWAY_PAYMILL) { + $rules['publishable_key'] = 'required'; } elseif ($gatewayId == GATEWAY_STRIPE) { if (Utils::isNinjaDev()) { // do nothing - we're unable to acceptance test with StripeJS diff --git a/app/Listeners/HandleUserLoggedIn.php b/app/Listeners/HandleUserLoggedIn.php index 3fd5380f4e04..4e85abe2fc0d 100644 --- a/app/Listeners/HandleUserLoggedIn.php +++ b/app/Listeners/HandleUserLoggedIn.php @@ -71,7 +71,7 @@ class HandleUserLoggedIn // if they're using Stripe make sure they're using Stripe.js $accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE); - if ($accountGateway && ! $accountGateway->getPublishableStripeKey()) { + if ($accountGateway && ! $accountGateway->getPublishableKey()) { Session::flash('warning', trans('texts.missing_publishable_key')); } elseif ($account->isLogoTooLarge()) { Session::flash('warning', trans('texts.logo_too_large', ['size' => $account->getLogoSize() . 'KB'])); diff --git a/app/Models/AccountGateway.php b/app/Models/AccountGateway.php index 535ec60de72c..07c5c80bfb89 100644 --- a/app/Models/AccountGateway.php +++ b/app/Models/AccountGateway.php @@ -95,7 +95,16 @@ class AccountGateway extends EntityModel */ public function isGateway($gatewayId) { - return $this->gateway_id == $gatewayId; + if (is_array($gatewayId)) { + foreach ($gatewayId as $id) { + if ($this->gateway_id == $id) { + return true; + } + } + return false; + } else { + return $this->gateway_id == $gatewayId; + } } /** @@ -127,9 +136,9 @@ class AccountGateway extends EntityModel /** * @return bool|mixed */ - public function getPublishableStripeKey() + public function getPublishableKey() { - if (! $this->isGateway(GATEWAY_STRIPE)) { + if (! $this->isGateway([GATEWAY_STRIPE, GATEWAY_PAYMILL])) { return false; } @@ -254,7 +263,7 @@ class AccountGateway extends EntityModel return null; } - $stripe_key = $this->getPublishableStripeKey(); + $stripe_key = $this->getPublishableKey(); return substr(trim($stripe_key), 0, 8) == 'pk_test_' ? 'tartan' : 'production'; } @@ -272,7 +281,7 @@ class AccountGateway extends EntityModel public function isTestMode() { if ($this->isGateway(GATEWAY_STRIPE)) { - return strpos($this->getPublishableStripeKey(), 'test') !== false; + return strpos($this->getPublishableKey(), 'test') !== false; } else { return $this->getConfigField('testMode'); } diff --git a/app/Ninja/PaymentDrivers/PaymillPaymentDriver.php b/app/Ninja/PaymentDrivers/PaymillPaymentDriver.php new file mode 100644 index 000000000000..701ff1115d3a --- /dev/null +++ b/app/Ninja/PaymentDrivers/PaymillPaymentDriver.php @@ -0,0 +1,27 @@ +input['sourceToken'])) { + $data['token'] = $this->input['sourceToken']; + unset($data['card']); + } + + return $data; + } +} diff --git a/app/Ninja/PaymentDrivers/StripePaymentDriver.php b/app/Ninja/PaymentDrivers/StripePaymentDriver.php index 2be1c5b83327..6b0a63284c26 100644 --- a/app/Ninja/PaymentDrivers/StripePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/StripePaymentDriver.php @@ -63,7 +63,7 @@ class StripePaymentDriver extends BasePaymentDriver public function tokenize() { - return $this->accountGateway->getPublishableStripeKey(); + return $this->accountGateway->getPublishableKey(); } public function rules() diff --git a/composer.json b/composer.json index 58c3f6d6e2c9..ce0c41ed52d5 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "google/apiclient": "^2.0", "guzzlehttp/guzzle": "~6.0", "intervention/image": "dev-master", - "invoiceninja/omnipay-collection": "0.6@dev", + "invoiceninja/omnipay-collection": "0.7@dev", "jaybizzle/laravel-crawler-detect": "1.*", "jlapp/swaggervel": "master-dev", "jonnyw/php-phantomjs": "dev-fixes", diff --git a/composer.lock b/composer.lock index 829b53cb175d..6225f03dc0cc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "8c61bb54d84a6fcf49038e56aa706561", - "content-hash": "189d617b1ea403a147b9fe61c0b2185b", + "hash": "7ee707d4d8d5e695a06f09148055a914", + "content-hash": "6d17fba6edb89baff674e8d4a89e00e5", "packages": [ { "name": "abdala/omnipay-pagseguro", @@ -838,6 +838,50 @@ "description": "Braintree PHP Client Library", "time": "2018-02-27 22:51:38" }, + { + "name": "bramdevries/omnipay-paymill", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/bramdevries/omnipay-paymill.git", + "reference": "df264a980b4b6005899f659d55b24d5c125d7e2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bramdevries/omnipay-paymill/zipball/df264a980b4b6005899f659d55b24d5c125d7e2e", + "reference": "df264a980b4b6005899f659d55b24d5c125d7e2e", + "shasum": "" + }, + "require": { + "omnipay/common": "~2.0" + }, + "require-dev": { + "omnipay/tests": "~2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Omnipay\\Paymill\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "authors": [ + { + "name": "Bram Devries", + "email": "bramdevries93@gmail.com" + } + ], + "description": "Paymill driver for the Omnipay payment processing library", + "keywords": [ + "gateway", + "merchant", + "omnipay", + "pay", + "payment", + "paymill" + ], + "time": "2014-12-14 17:00:43" + }, { "name": "cardgate/omnipay-cardgate", "version": "v2.0.0", @@ -3493,16 +3537,16 @@ }, { "name": "invoiceninja/omnipay-collection", - "version": "v0.6", + "version": "v0.7", "source": { "type": "git", "url": "https://github.com/invoiceninja/omnipay-collection.git", - "reference": "2ca215e97e3b436b26b0b8f52e865ed94eb61408" + "reference": "12d9c8d40d62301e2226db63d1e5534747f660fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/invoiceninja/omnipay-collection/zipball/2ca215e97e3b436b26b0b8f52e865ed94eb61408", - "reference": "2ca215e97e3b436b26b0b8f52e865ed94eb61408", + "url": "https://api.github.com/repos/invoiceninja/omnipay-collection/zipball/12d9c8d40d62301e2226db63d1e5534747f660fe", + "reference": "12d9c8d40d62301e2226db63d1e5534747f660fe", "shasum": "" }, "require": { @@ -3510,6 +3554,7 @@ "agmscode/omnipay-agms": "~1.0", "alfaproject/omnipay-skrill": "dev-master", "andreas22/omnipay-fasapay": "1.*", + "bramdevries/omnipay-paymill": "^1.0", "cardgate/omnipay-cardgate": "~2.0", "delatbabel/omnipay-fatzebra": "dev-master", "dercoder/omnipay-ecopayz": "~1.0", @@ -3549,7 +3594,7 @@ } ], "description": "Collection of Omnipay drivers", - "time": "2018-01-17 13:51:24" + "time": "2018-03-07 13:26:16" }, { "name": "jakoch/phantomjs-installer", @@ -9243,7 +9288,7 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.35", + "version": "v2.8.36", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -9401,7 +9446,7 @@ }, { "name": "symfony/http-foundation", - "version": "v3.4.5", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", diff --git a/database/seeds/PaymentLibrariesSeeder.php b/database/seeds/PaymentLibrariesSeeder.php index 89b3221b66ec..3dc53b918194 100644 --- a/database/seeds/PaymentLibrariesSeeder.php +++ b/database/seeds/PaymentLibrariesSeeder.php @@ -74,6 +74,7 @@ class PaymentLibrariesSeeder extends Seeder ['name' => 'FirstData Payeezy', 'provider' => 'FirstData_Payeezy'], ['name' => 'GoCardless', 'provider' => 'GoCardlessV2\Redirect', 'sort_order' => 9, 'is_offsite' => true], ['name' => 'PagSeguro', 'provider' => 'PagSeguro'], + ['name' => 'PAYMILL', 'provider' => 'Paymill'], ]; foreach ($gateways as $gateway) { diff --git a/resources/views/accounts/account_gateway.blade.php b/resources/views/accounts/account_gateway.blade.php index 4b193e2d6b3d..fe04136bc99c 100644 --- a/resources/views/accounts/account_gateway.blade.php +++ b/resources/views/accounts/account_gateway.blade.php @@ -34,7 +34,7 @@ {!! Former::populateField('show_address', intval($accountGateway->show_address)) !!} {!! Former::populateField('show_shipping_address', intval($accountGateway->show_shipping_address)) !!} {!! Former::populateField('update_address', intval($accountGateway->update_address)) !!} - {!! Former::populateField('publishable_key', $accountGateway->getPublishableStripeKey() ? str_repeat('*', strlen($accountGateway->getPublishableStripeKey())) : '') !!} + {!! Former::populateField('publishable_key', $accountGateway->getPublishableKey() ? str_repeat('*', strlen($accountGateway->getPublishableKey())) : '') !!} {!! Former::populateField('enable_ach', $accountGateway->getAchEnabled() ? 1 : 0) !!} {!! Former::populateField('enable_apple_pay', $accountGateway->getApplePayEnabled() ? 1 : 0) !!} {!! Former::populateField('enable_sofort', $accountGateway->getSofortEnabled() ? 1 : 0) !!} @@ -84,13 +84,12 @@ @endif @endif + + @foreach ($gateways as $gateway) - -
-
-
- @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) -
- @else - {!! Former::text(!empty($tokenize) ? '' : 'card_number') - ->id('card_number') - ->placeholder(trans('texts.card_number')) - ->autocomplete('cc-number') - ->label('') !!} - @endif -
+ @if ($accountGateway->isGateway(GATEWAY_PAYMILL)) +
+
+
-
-
- @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) -
- @else - {!! Former::select(!empty($tokenize) ? '' : 'expiration_month') - ->id('expiration_month') - ->autocomplete('cc-exp-month') - ->placeholder(trans('texts.expiration_month')) - ->addOption('01 - ' . trans('texts.january'), '1') - ->addOption('02 - ' . trans('texts.february'), '2') - ->addOption('03 - ' . trans('texts.march'), '3') - ->addOption('04 - ' . trans('texts.april'), '4') - ->addOption('05 - ' . trans('texts.may'), '5') - ->addOption('06 - ' . trans('texts.june'), '6') - ->addOption('07 - ' . trans('texts.july'), '7') - ->addOption('08 - ' . trans('texts.august'), '8') - ->addOption('09 - ' . trans('texts.september'), '9') - ->addOption('10 - ' . trans('texts.october'), '10') - ->addOption('11 - ' . trans('texts.november'), '11') - ->addOption('12 - ' . trans('texts.december'), '12')->label('') - !!} - @endif + @else +
+ +
+
+ @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) +
+ @else + {!! Former::text(!empty($tokenize) ? '' : 'card_number') + ->id('card_number') + ->placeholder(trans('texts.card_number')) + ->autocomplete('cc-number') + ->label('') !!} + @endif +
-
- @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) -
- @else - {!! Former::select(!empty($tokenize) ? '' : 'expiration_year') - ->id('expiration_year') - ->autocomplete('cc-exp-year') - ->placeholder(trans('texts.expiration_year')) - ->options( - array_combine( - range(date('Y'), date('Y') + 10), - range(date('Y'), date('Y') + 10) +
+
+ @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) +
+ @else + {!! Former::select(!empty($tokenize) ? '' : 'expiration_month') + ->id('expiration_month') + ->autocomplete('cc-exp-month') + ->placeholder(trans('texts.expiration_month')) + ->addOption('01 - ' . trans('texts.january'), '1') + ->addOption('02 - ' . trans('texts.february'), '2') + ->addOption('03 - ' . trans('texts.march'), '3') + ->addOption('04 - ' . trans('texts.april'), '4') + ->addOption('05 - ' . trans('texts.may'), '5') + ->addOption('06 - ' . trans('texts.june'), '6') + ->addOption('07 - ' . trans('texts.july'), '7') + ->addOption('08 - ' . trans('texts.august'), '8') + ->addOption('09 - ' . trans('texts.september'), '9') + ->addOption('10 - ' . trans('texts.october'), '10') + ->addOption('11 - ' . trans('texts.november'), '11') + ->addOption('12 - ' . trans('texts.december'), '12')->label('') + !!} + @endif +
+
+ @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) +
+ @else + {!! Former::select(!empty($tokenize) ? '' : 'expiration_year') + ->id('expiration_year') + ->autocomplete('cc-exp-year') + ->placeholder(trans('texts.expiration_year')) + ->options( + array_combine( + range(date('Y'), date('Y') + 10), + range(date('Y'), date('Y') + 10) + ) ) - ) - ->label('') !!} - @endif + ->label('') !!} + @endif +
+
+ @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) +
+ @else + {!! Former::text(!empty($tokenize) ? '' : 'cvv') + ->id('cvv') + ->placeholder(trans('texts.cvv')) + ->autocomplete('off') + ->label('') !!} + @endif +
-
- @if ($accountGateway->gateway_id == GATEWAY_BRAINTREE) -
- @else - {!! Former::text(!empty($tokenize) ? '' : 'cvv') - ->id('cvv') - ->placeholder(trans('texts.cvv')) - ->autocomplete('off') - ->label('') !!} - @endif + +
+ +
+ @if (isset($amount) && $client && $account->showTokenCheckbox($storageGateway/* will contain gateway id */)) + selectTokenCheckbox() ? 'CHECKED' : '' }} value="1" style="margin-left:0px; vertical-align:top"> + + + @if ($storageGateway == GATEWAY_STRIPE) + {!! trans('texts.token_billing_secure', ['link' => link_to('https://stripe.com/', 'Stripe.com', ['target' => '_blank'])]) !!} + @elseif ($storageGateway == GATEWAY_BRAINTREE) + {!! trans('texts.token_billing_secure', ['link' => link_to('https://www.braintreepayments.com/', 'Braintree', ['target' => '_blank'])]) !!} + @endif + + @endif +
- -
- -
- @if (isset($amount) && $client && $account->showTokenCheckbox($storageGateway/* will contain gateway id */)) - selectTokenCheckbox() ? 'CHECKED' : '' }} value="1" style="margin-left:0px; vertical-align:top"> - - - @if ($storageGateway == GATEWAY_STRIPE) - {!! trans('texts.token_billing_secure', ['link' => link_to('https://stripe.com/', 'Stripe.com', ['target' => '_blank'])]) !!} - @elseif ($storageGateway == GATEWAY_BRAINTREE) - {!! trans('texts.token_billing_secure', ['link' => link_to('https://www.braintreepayments.com/', 'Braintree', ['target' => '_blank'])]) !!} - @endif - - @endif -
+
+
-
-
-
-
+ @endif
@endif diff --git a/resources/views/payments/paymill/credit_card.blade.php b/resources/views/payments/paymill/credit_card.blade.php new file mode 100644 index 000000000000..c1a777708f61 --- /dev/null +++ b/resources/views/payments/paymill/credit_card.blade.php @@ -0,0 +1,83 @@ +@extends('payments.credit_card') + +@section('head') + @parent + + + + + + + + + +@stop diff --git a/resources/views/payments/stripe/bank_transfer.blade.php b/resources/views/payments/stripe/bank_transfer.blade.php index ceac49b109d2..bb9feb718619 100644 --- a/resources/views/payments/stripe/bank_transfer.blade.php +++ b/resources/views/payments/stripe/bank_transfer.blade.php @@ -5,7 +5,7 @@