Add SOFORT support on Stripe #1338

This commit is contained in:
Hillel Coren 2017-09-05 16:37:19 +03:00
parent d251df7531
commit 5a3d5b8eea
7 changed files with 66 additions and 21 deletions

View File

@ -296,6 +296,7 @@ class AccountGatewayController extends BaseController
if ($gatewayId == GATEWAY_STRIPE) { if ($gatewayId == GATEWAY_STRIPE) {
$config->enableAlipay = boolval(Input::get('enable_alipay')); $config->enableAlipay = boolval(Input::get('enable_alipay'));
$config->enableSofort = boolval(Input::get('enable_sofort'));
} }
if ($gatewayId == GATEWAY_STRIPE || $gatewayId == GATEWAY_WEPAY) { if ($gatewayId == GATEWAY_STRIPE || $gatewayId == GATEWAY_WEPAY) {

View File

@ -152,6 +152,14 @@ class AccountGateway extends EntityModel
return ! empty($this->getConfigField('enableAlipay')); return ! empty($this->getConfigField('enableAlipay'));
} }
/**
* @return bool
*/
public function getSofortEnabled()
{
return ! empty($this->getConfigField('enableSofort'));
}
/** /**
* @return bool * @return bool
*/ */

View File

@ -24,6 +24,7 @@ class Country extends Eloquent
'swap_currency_symbol', 'swap_currency_symbol',
'thousand_separator', 'thousand_separator',
'decimal_separator', 'decimal_separator',
'iso_3166_3',
]; ];
/** /**

View File

@ -142,7 +142,7 @@ class BasePaymentDriver
} }
// For these gateway types we use the API directrly rather than Omnipay // For these gateway types we use the API directrly rather than Omnipay
if (in_array($this->gatewayType, [GATEWAY_TYPE_ALIPAY])) { if ($this->shouldUseSource()) {
return $this->createSource(); return $this->createSource();
} }
@ -520,6 +520,12 @@ class BasePaymentDriver
]; ];
} }
public function shouldUseSource()
{
// Use Omnipay by default
return false;
}
protected function shouldCreateToken() protected function shouldCreateToken()
{ {
if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER)) { if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER)) {

View File

@ -22,12 +22,13 @@ class StripePaymentDriver extends BasePaymentDriver
GATEWAY_TYPE_TOKEN, GATEWAY_TYPE_TOKEN,
]; ];
if ($this->accountGateway && $this->accountGateway->getAchEnabled()) { if ($gateway = $this->accountGateway) {
$types[] = GATEWAY_TYPE_BANK_TRANSFER; if ($gateway->getAchEnabled() || $gateway->getSofortEnabled()) {
} $types[] = GATEWAY_TYPE_BANK_TRANSFER;
}
if ($this->accountGateway && $this->accountGateway->getAlipayEnabled()) { if ($gateway->getAlipayEnabled()) {
$types[] = GATEWAY_TYPE_ALIPAY; $types[] = GATEWAY_TYPE_ALIPAY;
}
} }
return $types; return $types;
@ -64,6 +65,34 @@ class StripePaymentDriver extends BasePaymentDriver
} }
} }
public function shouldUseSource()
{
if (in_array($this->gatewayType, [GATEWAY_TYPE_ALIPAY])) {
return true;
}
if ($this->gatewayType == GATEWAY_TYPE_BANK_TRANSFER) {
$achEnabled = $this->accountGateway->getAchEnabled();
$sofortEnabled = $this->accountGateway->getSofortEnabled();
if ($sofortEnabled) {
if (! $achEnabled) {
return true;
}
if ($country = $this->client()->country) {
$country = $country->iso_3166_3;
} elseif ($country = $this->account()->country) {
$country = $country->iso_3166_3;
}
// https://stripe.com/docs/sources/sofort
if ($country && in_array($country, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP'])) {
return true;
}
}
}
return false;
}
protected function checkCustomerExists($customer) protected function checkCustomerExists($customer)
{ {
$response = $this->gateway() $response = $this->gateway()

View File

@ -1213,7 +1213,7 @@ $LANG = array(
'payment_type_stripe' => 'Stripe', 'payment_type_stripe' => 'Stripe',
'ach' => 'ACH', 'ach' => 'ACH',
'enable_ach' => 'Enable ACH', 'enable_ach' => 'Accept US bank transfers',
'stripe_ach_help' => 'ACH support must also be enabled in :link.', 'stripe_ach_help' => 'ACH support must also be enabled in :link.',
'ach_disabled' => 'Another gateway is already configured for direct debit.', 'ach_disabled' => 'Another gateway is already configured for direct debit.',
@ -2439,9 +2439,12 @@ $LANG = array(
'deleted_account_details' => 'Your account (:account) has been successfully deleted.', 'deleted_account_details' => 'Your account (:account) has been successfully deleted.',
'alipay' => 'Alipay', 'alipay' => 'Alipay',
'enable_alipay' => 'Enable Alipay', 'sofort' => 'Sofort',
'enable_alipay' => 'Accept Alipay',
'enable_sofort' => 'Accept EU bank transfers',
'stripe_alipay_help' => 'These gateways also need to be activated in :link.', 'stripe_alipay_help' => 'These gateways also need to be activated in :link.',
); );
return $LANG; return $LANG;

View File

@ -19,6 +19,7 @@
{!! Former::populateField('update_address', intval($accountGateway->update_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->getPublishableStripeKey() ? str_repeat('*', strlen($accountGateway->getPublishableStripeKey())) : '') !!}
{!! Former::populateField('enable_ach', $accountGateway->getAchEnabled() ? 1 : 0) !!} {!! Former::populateField('enable_ach', $accountGateway->getAchEnabled() ? 1 : 0) !!}
{!! Former::populateField('enable_sofort', $accountGateway->getSofortEnabled() ? 1 : 0) !!}
{!! Former::populateField('enable_alipay', $accountGateway->getAlipayEnabled() ? 1 : 0) !!} {!! Former::populateField('enable_alipay', $accountGateway->getAlipayEnabled() ? 1 : 0) !!}
{!! Former::populateField('enable_paypal', $accountGateway->getPayPalEnabled() ? 1 : 0) !!} {!! Former::populateField('enable_paypal', $accountGateway->getPayPalEnabled() ? 1 : 0) !!}
{!! Former::populateField('plaid_client_id', $accountGateway->getPlaidClientId() ? str_repeat('*', strlen($accountGateway->getPlaidClientId())) : '') !!} {!! Former::populateField('plaid_client_id', $accountGateway->getPlaidClientId() ? str_repeat('*', strlen($accountGateway->getPlaidClientId())) : '') !!}
@ -154,6 +155,11 @@
->text(trans('texts.enable_ach')) ->text(trans('texts.enable_ach'))
->value(1) !!} ->value(1) !!}
{!! Former::checkbox('enable_sofort')
->label(trans('texts.sofort'))
->text(trans('texts.enable_sofort'))
->value(1) !!}
{!! Former::checkbox('enable_alipay') {!! Former::checkbox('enable_alipay')
->label(trans('texts.alipay')) ->label(trans('texts.alipay'))
->text(trans('texts.enable_alipay')) ->text(trans('texts.enable_alipay'))
@ -252,21 +258,11 @@
} }
} }
function onEnableAchChanged() {
var visible = $('#enable_ach').is(':checked');
$('.stripe-webhook-options').toggle(visible);
$('.stripe-ach-options').toggle(visible);
}
function onEnableAlipayChanged() {
var visible = $('#enable_alipay').is(':checked');
$('.stripe-webhook-options').toggle(visible);
}
function updateWebhookShown() { function updateWebhookShown() {
var enableAch = $('#enable_ach').is(':checked'); var enableAch = $('#enable_ach').is(':checked');
var enableAlipay = $('#enable_alipay').is(':checked'); var enableAlipay = $('#enable_alipay').is(':checked');
$('.stripe-webhook-options').toggle(enableAch || enableAlipay); var enableSofort = $('#enable_sofort').is(':checked');
$('.stripe-webhook-options').toggle(enableAch || enableAlipay || enableSofort);
$('.stripe-ach-options').toggle(enableAch); $('.stripe-ach-options').toggle(enableAch);
} }
@ -282,6 +278,7 @@
$('#enable_ach').change(updateWebhookShown); $('#enable_ach').change(updateWebhookShown);
$('#enable_alipay').change(updateWebhookShown); $('#enable_alipay').change(updateWebhookShown);
$('#enable_sofort').change(updateWebhookShown);
@if (!$accountGateway && count($secondaryGateways)) @if (!$accountGateway && count($secondaryGateways))
$('#primary_gateway_id').append($('<option>', { $('#primary_gateway_id').append($('<option>', {