Support configuring Stripe for ACH and Plaid

This commit is contained in:
Joshua Dwire 2016-04-28 16:38:01 -04:00
parent 1cb2b9dc25
commit e5fb354643
6 changed files with 155 additions and 3 deletions

View File

@ -86,6 +86,7 @@ class AccountGatewayController extends BaseController
->where('id', '!=', GATEWAY_BITPAY)
->where('id', '!=', GATEWAY_GOCARDLESS)
->where('id', '!=', GATEWAY_DWOLLA)
->where('id', '!=', GATEWAY_STRIPE)
->orderBy('name')->get();
$data['hiddenFields'] = Gateway::$hiddenFields;
@ -104,6 +105,18 @@ class AccountGatewayController extends BaseController
$paymentTypes = [];
foreach (Gateway::$paymentTypes as $type) {
if ($accountGateway || !$account->getGatewayByType($type)) {
if ($type == PAYMENT_TYPE_CREDIT_CARD && $account->getGatewayByType(PAYMENT_TYPE_STRIPE)) {
// Stripe is already handling credit card payments
continue;
}
if ($type == PAYMENT_TYPE_DIRECT_DEBIT && $stripeGateway = $account->getGatewayByType(PAYMENT_TYPE_STRIPE)) {
if (!empty($stripeGateway->getConfig()->enableAch)) {
// Stripe is already handling ACH payments
continue;
}
}
$paymentTypes[$type] = trans('texts.'.strtolower($type));
if ($type == PAYMENT_TYPE_BITCOIN) {
@ -185,6 +198,8 @@ class AccountGatewayController extends BaseController
$gatewayId = GATEWAY_GOCARDLESS;
} elseif ($paymentType == PAYMENT_TYPE_DWOLLA) {
$gatewayId = GATEWAY_DWOLLA;
} elseif ($paymentType == PAYMENT_TYPE_STRIPE) {
$gatewayId = GATEWAY_STRIPE;
}
if (!$gatewayId) {
@ -204,6 +219,7 @@ class AccountGatewayController extends BaseController
// do nothing - we're unable to acceptance test with StripeJS
} else {
$rules['publishable_key'] = 'required';
$rules['enable_ach'] = 'boolean';
}
}
@ -259,6 +275,31 @@ class AccountGatewayController extends BaseController
$config->publishableKey = $oldConfig->publishableKey;
}
$plaidClientId = Input::get('plaid_client_id');
if ($plaidClientId = str_replace('*', '', $plaidClientId)) {
$config->plaidClientId = $plaidClientId;
} elseif ($oldConfig && property_exists($oldConfig, 'plaidClientId')) {
$config->plaidClientId = $oldConfig->plaidClientId;
}
$plaidSecret = Input::get('plaid_secret');
if ($plaidSecret = str_replace('*', '', $plaidSecret)) {
$config->plaidSecret = $plaidSecret;
} elseif ($oldConfig && property_exists($oldConfig, 'plaidSecret')) {
$config->plaidSecret = $oldConfig->plaidSecret;
}
$plaidPublicKey = Input::get('plaid_public_key');
if ($plaidPublicKey = str_replace('*', '', $plaidPublicKey)) {
$config->plaidPublicKey = $plaidPublicKey;
} elseif ($oldConfig && property_exists($oldConfig, 'plaidPublicKey')) {
$config->plaidPublicKey = $oldConfig->plaidPublicKey;
}
if ($gatewayId == GATEWAY_STRIPE) {
$config->enableAch = boolval(Input::get('enable_ach'));
}
$cardCount = 0;
if ($creditcards) {
foreach ($creditcards as $card => $value) {

View File

@ -632,6 +632,7 @@ if (!defined('CONTACT_EMAIL')) {
define('PAYMENT_TYPE_SWITCH', 23);
define('PAYMENT_TYPE_PAYPAL', 'PAYMENT_TYPE_PAYPAL');
define('PAYMENT_TYPE_STRIPE', 'PAYMENT_TYPE_STRIPE');
define('PAYMENT_TYPE_CREDIT_CARD', 'PAYMENT_TYPE_CREDIT_CARD');
define('PAYMENT_TYPE_DIRECT_DEBIT', 'PAYMENT_TYPE_DIRECT_DEBIT');
define('PAYMENT_TYPE_BITCOIN', 'PAYMENT_TYPE_BITCOIN');

View File

@ -71,5 +71,53 @@ class AccountGateway extends EntityModel
return $this->getConfigField('publishableKey');
}
public function getAchEnabled()
{
return !empty($this->getConfigField('enableAch'));
}
public function getPlaidSecret()
{
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
return false;
}
return $this->getConfigField('plaidSecret');
}
public function getPlaidClientId()
{
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
return false;
}
return $this->getConfigField('plaidClientId');
}
public function getPlaidPublicKey()
{
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
return false;
}
return $this->getConfigField('plaidPublicKey');
}
public function getPlaidEnabled()
{
return !empty($this->getPlaidClientId()) && $this->getAchEnabled();
}
public function getPlaidEnvironment()
{
if (!$this->getPlaidClientId()) {
return null;
}
$stripe_key = $this->getPublishableStripeKey();
return substr(trim($stripe_key), 0, 8) == 'sk_test_' ? 'tartan' : 'production';
}
}

View File

@ -9,6 +9,7 @@ class Gateway extends Eloquent
public $timestamps = true;
public static $paymentTypes = [
PAYMENT_TYPE_STRIPE,
PAYMENT_TYPE_CREDIT_CARD,
PAYMENT_TYPE_PAYPAL,
PAYMENT_TYPE_BITCOIN,
@ -97,8 +98,10 @@ class Gateway extends Eloquent
return PAYMENT_TYPE_BITCOIN;
} else if ($gatewayId == GATEWAY_DWOLLA) {
return PAYMENT_TYPE_DWOLLA;
}else if ($gatewayId == GATEWAY_GOCARDLESS) {
} else if ($gatewayId == GATEWAY_GOCARDLESS) {
return PAYMENT_TYPE_DIRECT_DEBIT;
} else if ($gatewayId == GATEWAY_STRIPE) {
return PAYMENT_TYPE_STRIPE;
} else {
return PAYMENT_TYPE_CREDIT_CARD;
}

View File

@ -502,7 +502,7 @@ $LANG = array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit Card',
'payment_type_credit_card' => 'Other Providers',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',
'knowledge_base' => 'Knowledge Base',
@ -1205,6 +1205,19 @@ $LANG = array(
'card_solo' => 'Solo',
'card_switch' => 'Switch',
'card_visacard' => 'Visa',
'payment_type_stripe' => 'Stripe',
'ach' => 'ACH',
'enable_ach' => 'Enable ACH',
'stripe_ach_help' => 'ACH support must also be enabled at Stripe.',
'stripe_ach_disabled' => 'Another gateway is already configured for direct debit.',
'plaid' => 'Plaid',
'client_id' => 'Client Id',
'secret' => 'Secret',
'public_key' => 'Public Key',
'plaid_optional' => '(optional)',
'plaid_environment_help' => 'When a Stripe test key is given, Plaid\'s development environement (tartan) will be used.',
);
return $LANG;

View File

@ -22,6 +22,10 @@
{!! Former::populateField('show_address', intval($accountGateway->show_address)) !!}
{!! Former::populateField('update_address', intval($accountGateway->update_address)) !!}
{!! Former::populateField('publishable_key', $accountGateway->getPublishableStripeKey() ? str_repeat('*', strlen($accountGateway->getPublishableStripeKey())) : '') !!}
{!! Former::populateField('enable_ach', $accountGateway->getAchEnabled() ? '1' : null) !!}
{!! Former::populateField('plaid_client_id', $accountGateway->getPlaidClientId() ? str_repeat('*', strlen($accountGateway->getPlaidClientId())) : '') !!}
{!! Former::populateField('plaid_secret', $accountGateway->getPlaidSecret() ? str_repeat('*', strlen($accountGateway->getPlaidSecret())) : '') !!}
{!! Former::populateField('plaid_public_key', $accountGateway->getPlaidPublicKey() ? str_repeat('*', strlen($accountGateway->getPlaidPublicKey())) : '') !!}
@if ($config)
@foreach ($accountGateway->fields as $field => $junk)
@ -45,7 +49,7 @@
{!! Former::select('gateway_id')
->dataClass('gateway-dropdown')
->addGroupClass('gateway-option')
->addGroupClass('gateway-option gateway-choice')
->fromQuery($selectGateways, 'name', 'id')
->onchange('setFieldsShown()') !!}
@ -110,6 +114,34 @@
->class('creditcard-types')
->addGroupClass('gateway-option')
!!}
<div class="stripe-ach">
@if ($account->getGatewayByType(PAYMENT_TYPE_DIRECT_DEBIT))
{!! Former::checkbox('enable_ach')
->label(trans('texts.ach'))
->text(trans('texts.enable_ach'))
->value(null)
->disabled(true)
->help(trans('texts.stripe_ach_disabled')) !!}
@else
{!! Former::checkbox('enable_ach')
->label(trans('texts.ach'))
->text(trans('texts.enable_ach'))
->help(trans('texts.stripe_ach_help')) !!}
<div class="stripe-plaid">
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<h4>{{trans('texts.plaid')}}</h4>
<div class="help-block">{{trans('texts.plaid_optional')}}</div>
</div>
</div>
{!! Former::text('plaid_client_id')->label(trans('texts.client_id')) !!}
{!! Former::text('plaid_secret')->label(trans('texts.secret')) !!}
{!! Former::text('plaid_public_key')->label(trans('texts.public_key'))
->help(trans('texts.plaid_environment_help')) !!}
</div>
@endif
</div>
</div>
</div>
@ -128,9 +160,11 @@
var val = $('#payment_type_id').val();
if (val == 'PAYMENT_TYPE_CREDIT_CARD') {
$('.gateway-option').show();
$('.stripe-ach').hide();
setFieldsShown();
} else {
$('.gateway-option').hide();
$('.stripe-ach').hide();
if (val == 'PAYMENT_TYPE_PAYPAL') {
setFieldsShown({{ GATEWAY_PAYPAL_EXPRESS }});
@ -138,6 +172,10 @@
setFieldsShown({{ GATEWAY_DWOLLA }});
} else if (val == 'PAYMENT_TYPE_DIRECT_DEBIT') {
setFieldsShown({{ GATEWAY_GOCARDLESS }});
} else if (val == 'PAYMENT_TYPE_STRIPE') {
$('.gateway-option:not(.gateway-choice)').show();
$('.stripe-ach').show();
setFieldsShown({{ GATEWAY_STRIPE }});
} else {
setFieldsShown({{ GATEWAY_BITPAY }});
}
@ -171,14 +209,22 @@
}
}
function enablePlaidSettings() {
var visible = $('#enable_ach').is(':checked');
$('.stripe-plaid').toggle(visible);
}
$(function() {
setPaymentType();
enablePlaidSettings();
@if ($accountGateway)
$('.payment-type-option').hide();
@endif
$('#show_address').change(enableUpdateAddress);
enableUpdateAddress();
$('#enable_ach').change(enablePlaidSettings)
})
</script>