Support adding WePay ACH from payment page

This commit is contained in:
Joshua Dwire 2016-05-25 16:54:49 -04:00
parent 4dded687b5
commit acbc0e887f
5 changed files with 107 additions and 58 deletions

View File

@ -111,6 +111,8 @@ class ClientPortalController extends BaseController
if($braintreeGateway->getPayPalEnabled()) { if($braintreeGateway->getPayPalEnabled()) {
$data['braintreeClientToken'] = $this->paymentService->getBraintreeClientToken($account); $data['braintreeClientToken'] = $this->paymentService->getBraintreeClientToken($account);
} }
} elseif ($wepayGateway = $account->getGatewayConfig(GATEWAY_WEPAY)){
$data['enableWePayACH'] = $wepayGateway->getAchEnabled();
} }
$showApprove = $invoice->quote_invoice_id ? false : true; $showApprove = $invoice->quote_invoice_id ? false : true;
@ -224,16 +226,18 @@ class ClientPortalController extends BaseController
foreach(Gateway::$paymentTypes as $type) { foreach(Gateway::$paymentTypes as $type) {
if ($gateway = $account->getGatewayByType($type)) { if ($gateway = $account->getGatewayByType($type)) {
$types = array($type); if ($type == PAYMENT_TYPE_DIRECT_DEBIT) {
if ($gateway->gateway_id == GATEWAY_STRIPE) {
if ($type == PAYMENT_TYPE_STRIPE) { $type = PAYMENT_TYPE_STRIPE_ACH;
$types = array(PAYMENT_TYPE_STRIPE_CREDIT_CARD); } elseif ($gateway->gateway_id == GATEWAY_WEPAY) {
if ($gateway->getAchEnabled()) { $type = PAYMENT_TYPE_WEPAY_ACH;
$types[] = PAYMENT_TYPE_STRIPE_ACH;
} }
} elseif ($type == PAYMENT_TYPE_PAYPAL && $gateway->gateway_id == GATEWAY_BRAINTREE) {
$type = PAYMENT_TYPE_BRAINTREE_PAYPAL;
} elseif ($type == PAYMENT_TYPE_CREDIT_CARD && $gateway->gateway_id == GATEWAY_STRIPE) {
$type = PAYMENT_TYPE_STRIPE_CREDIT_CARD;
} }
foreach($types as $type) {
$typeLink = strtolower(str_replace('PAYMENT_TYPE_', '', $type)); $typeLink = strtolower(str_replace('PAYMENT_TYPE_', '', $type));
$url = URL::to("/payment/{$invitation->invitation_key}/{$typeLink}"); $url = URL::to("/payment/{$invitation->invitation_key}/{$typeLink}");
@ -244,8 +248,10 @@ class ClientPortalController extends BaseController
if ($type == PAYMENT_TYPE_STRIPE_CREDIT_CARD) { if ($type == PAYMENT_TYPE_STRIPE_CREDIT_CARD) {
$label = trans('texts.' . strtolower(PAYMENT_TYPE_CREDIT_CARD)); $label = trans('texts.' . strtolower(PAYMENT_TYPE_CREDIT_CARD));
} elseif ($type == PAYMENT_TYPE_STRIPE_ACH) { } elseif ($type == PAYMENT_TYPE_STRIPE_ACH || $type == PAYMENT_TYPE_WEPAY_ACH) {
$label = trans('texts.' . strtolower(PAYMENT_TYPE_DIRECT_DEBIT)); $label = trans('texts.' . strtolower(PAYMENT_TYPE_DIRECT_DEBIT));
} elseif ($type == PAYMENT_TYPE_BRAINTREE_PAYPAL) {
$label = trans('texts.' . strtolower(PAYMENT_TYPE_PAYPAL));
} else { } else {
$label = trans('texts.' . strtolower($type)); $label = trans('texts.' . strtolower($type));
} }
@ -253,14 +259,6 @@ class ClientPortalController extends BaseController
$paymentTypes[] = [ $paymentTypes[] = [
'url' => $url, 'label' => $label 'url' => $url, 'label' => $label
]; ];
if($gateway->getPayPalEnabled()) {
$paymentTypes[] = [
'label' => trans('texts.paypal'),
'url' => $url = URL::to("/payment/{$invitation->invitation_key}/braintree_paypal"),
];
}
}
} }
} }

View File

@ -156,7 +156,23 @@ class PaymentController extends BaseController
$details = json_decode(Input::get('details')); $details = json_decode(Input::get('details'));
$data['details'] = $details; $data['details'] = $details;
if ($paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) {
if ($paymentType == PAYMENT_TYPE_BRAINTREE_PAYPAL) {
if ($deviceData = Input::get('device_data')) {
Session::put($invitation->id . 'device_data', $deviceData);
}
Session::put($invitation->id . 'payment_type', PAYMENT_TYPE_BRAINTREE_PAYPAL);
if (!$sourceId || !$details) {
return Redirect::to('view/'.$invitationKey);
}
} elseif ($paymentType == PAYMENT_TYPE_WEPAY_ACH) {
Session::put($invitation->id . 'payment_type', PAYMENT_TYPE_WEPAY_ACH);
if (!$sourceId) {
return Redirect::to('view/'.$invitationKey);
}
} else {
if ($paymentType == PAYMENT_TYPE_TOKEN) { if ($paymentType == PAYMENT_TYPE_TOKEN) {
$useToken = true; $useToken = true;
$accountGateway = $invoice->client->account->getTokenGateway(); $accountGateway = $invoice->client->account->getTokenGateway();
@ -206,15 +222,6 @@ class PaymentController extends BaseController
$data['tokenize'] = true; $data['tokenize'] = true;
} }
} else {
if ($deviceData = Input::get('device_data')) {
Session::put($invitation->id . 'device_data', $deviceData);
}
Session::put($invitation->id . 'payment_type', PAYMENT_TYPE_BRAINTREE_PAYPAL);
if (!$sourceId || !$details) {
return Redirect::to('view/'.$invitationKey);
}
} }
$data += [ $data += [
@ -497,7 +504,6 @@ class PaymentController extends BaseController
->withInput(Request::except('cvv')); ->withInput(Request::except('cvv'));
} }
try { try {
// For offsite payments send the client's details on file // For offsite payments send the client's details on file
// If we're using a token then we don't need to send any other data // If we're using a token then we don't need to send any other data
@ -511,17 +517,22 @@ class PaymentController extends BaseController
$details = $this->paymentService->getPaymentDetails($invitation, $accountGateway, $data); $details = $this->paymentService->getPaymentDetails($invitation, $accountGateway, $data);
$details['paymentType'] = $paymentType; $details['paymentType'] = $paymentType;
// Check for authorization
if (($paymentType == PAYMENT_TYPE_STRIPE_ACH || $paymentType == PAYMENT_TYPE_WEPAY_ACH) && !Input::get('authorize_ach')) {
Session::flash('error', trans('texts.ach_authorization_required'));
return Redirect::to('client/paymentmethods/add/' . $typeLink.'/'.$sourceToken)->withInput(Request::except('cvv'));
}
if ($paymentType == PAYMENT_TYPE_WEPAY_ACH && !Input::get('tos_agree')) {
Session::flash('error', trans('texts.wepay_payment_tos_agree_required'));
return Redirect::to('client/paymentmethods/add/' . $typeLink.'/'.$sourceToken)->withInput(Request::except('cvv'));
}
// check if we're creating/using a billing token // check if we're creating/using a billing token
$tokenBillingSupported = false; $tokenBillingSupported = false;
$sourceReferenceParam = 'token'; $sourceReferenceParam = 'token';
if ($accountGateway->gateway_id == GATEWAY_STRIPE) { if ($accountGateway->gateway_id == GATEWAY_STRIPE) {
$tokenBillingSupported = true; $tokenBillingSupported = true;
$customerReferenceParam = 'customerReference'; $customerReferenceParam = 'customerReference';
if ($paymentType == PAYMENT_TYPE_STRIPE_ACH && !Input::get('authorize_ach')) {
Session::flash('error', trans('texts.ach_authorization_required'));
return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv'));
}
} elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) {
$tokenBillingSupported = true; $tokenBillingSupported = true;
$sourceReferenceParam = 'paymentMethodToken'; $sourceReferenceParam = 'paymentMethodToken';
@ -547,8 +558,8 @@ class PaymentController extends BaseController
} }
$details[$sourceReferenceParam] = $sourceReference; $details[$sourceReferenceParam] = $sourceReference;
unset($details['card']); unset($details['card']);
} elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing') || $paymentType == PAYMENT_TYPE_STRIPE_ACH) { } elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing') || $paymentType == PAYMENT_TYPE_STRIPE_ACH || $paymentType == PAYMENT_TYPE_WEPAY_ACH) {
$token = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */); $token = $this->paymentService->createToken($paymentType, $gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */);
if ($token) { if ($token) {
$details[$sourceReferenceParam] = $token; $details[$sourceReferenceParam] = $token;
if ($customerReferenceParam) { if ($customerReferenceParam) {
@ -586,7 +597,7 @@ class PaymentController extends BaseController
if (!$ref) { if (!$ref) {
$this->error('No-Ref', $response->getMessage(), $accountGateway); $this->error('No-Ref', $response->getMessage(), $accountGateway);
if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL && $paymentType != PAYMENT_TYPE_WEPAY_ACH) {
return Redirect::to('payment/'.$invitationKey) return Redirect::to('payment/'.$invitationKey)
->withInput(Request::except('cvv')); ->withInput(Request::except('cvv'));
} else { } else {
@ -614,7 +625,7 @@ class PaymentController extends BaseController
$response->redirect(); $response->redirect();
} else { } else {
$this->error('Unknown', $response->getMessage(), $accountGateway); $this->error('Unknown', $response->getMessage(), $accountGateway);
if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL && $paymentType != PAYMENT_TYPE_WEPAY_ACH) {
return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv'));
} else { } else {
return Redirect::to('view/'.$invitationKey); return Redirect::to('view/'.$invitationKey);
@ -622,7 +633,7 @@ class PaymentController extends BaseController
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error('Uncaught', false, $accountGateway, $e); $this->error('Uncaught', false, $accountGateway, $e);
if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL && $paymentType != PAYMENT_TYPE_WEPAY_ACH) {
return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv'));
} else { } else {
return Redirect::to('view/'.$invitationKey); return Redirect::to('view/'.$invitationKey);

View File

@ -1334,7 +1334,9 @@ $LANG = array(
'wepay_payment_tos_agree' => 'I agree to the WePay :terms and :privacy_policy.', 'wepay_payment_tos_agree' => 'I agree to the WePay :terms and :privacy_policy.',
'privacy_policy' => 'Privacy Policy', 'privacy_policy' => 'Privacy Policy',
'wepay_payment_tos_agree_required' => 'You must agree to the WePay Terms of Service and Privacy Policy.', 'wepay_payment_tos_agree_required' => 'You must agree to the WePay Terms of Service and Privacy Policy.',
'payment_settings_supported_gateways' => 'These options are supported by the WePay, Stripe, and Braintree gateways.' 'payment_settings_supported_gateways' => 'These options are supported by the WePay, Stripe, and Braintree gateways.',
'ach_email_prompt' => 'Please enter your email address:',
'verification_pending' => 'Verification Pending',
); );
return $LANG; return $LANG;

View File

@ -59,6 +59,35 @@
}) })
}); });
</script> </script>
@elseif(!empty($enableWePayACH))
<script type="text/javascript" src="https://static.wepay.com/js/tokenization.v2.js"></script>
<script type="text/javascript">
$(function() {
var achLink = $('.dropdown-menu a[href$="/wepay_ach"]'),
achUrl = achLink.attr('href');
WePay.set_endpoint('{{ WEPAY_ENVIRONMENT }}');
achLink.click(function(e) {
e.preventDefault();
$('#wepay-error').remove();
var email = {!! json_encode($contact->email) !!} || prompt('{{ trans('texts.ach_email_prompt') }}');
if(!email)return;
WePay.bank_account.create({
'client_id': '{{ WEPAY_CLIENT_ID }}',
'email':email
}, function(data){
dataObj = JSON.parse(data);
if(dataObj.bank_account_id) {
window.location.href = achLink.attr('href') + '/' + dataObj.bank_account_id + "?details=" + encodeURIComponent(data);
} else if(dataObj.error) {
$('#wepay-error').remove();
achLink.closest('.container').prepend($('<div id="wepay-error" style="margin-top:20px" class="alert alert-danger"></div>').text(dataObj.error_description));
}
});
});
});
</script>
@endif @endif
@stop @stop

View File

@ -50,20 +50,25 @@
</script> </script>
@elseif($gateway->gateway_id == GATEWAY_WEPAY && $gateway->getAchEnabled()) @elseif($gateway->gateway_id == GATEWAY_WEPAY && $gateway->getAchEnabled())
<script type="text/javascript" src="https://static.wepay.com/js/tokenization.v2.js"></script> <script type="text/javascript" src="https://static.wepay.com/js/tokenization.v2.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
WePay.set_endpoint('{{ WEPAY_ENVIRONMENT }}'); WePay.set_endpoint('{{ WEPAY_ENVIRONMENT }}');
// Shortcuts
$('#add-ach').click(function(e) { $('#add-ach').click(function(e) {
e.preventDefault(); e.preventDefault();
$('#wepay-error').remove();
var email = {!! json_encode($contact->email) !!} || prompt('{{ trans('texts.ach_email_prompt') }}');
if(!email)return;
WePay.bank_account.create({ WePay.bank_account.create({
'client_id': '{{ WEPAY_CLIENT_ID }}', 'client_id': '{{ WEPAY_CLIENT_ID }}',
'email':{!! json_encode($contact->email) !!} 'email':email
}, function(data){ }, function(data){
dataObj = JSON.parse(data); dataObj = JSON.parse(data);
if(dataObj.bank_account_id) { if(dataObj.bank_account_id) {
window.location.href = $('#add-ach').attr('href') + '/' + dataObj.bank_account_id + "?details=" + encodeURIComponent(data); window.location.href = $('#add-ach').attr('href') + '/' + dataObj.bank_account_id + "?details=" + encodeURIComponent(data);
} else if(dataObj.error) {
$('#add-ach').after($('<div id="wepay-error" style="margin-top:20px" class="alert alert-danger"></div>').text(dataObj.error_description));
} }
}); });
}); });
@ -84,7 +89,11 @@
{{ $paymentMethod->bank_name }} {{ $paymentMethod->bank_name }}
@endif @endif
@if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW) @if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW)
@if($gateway->gateway_id == GATEWAY_STRIPE)
<a href="#" onclick="completeVerification('{{$paymentMethod->public_id}}','{{$paymentMethod->currency->symbol}}')">({{trans('texts.complete_verification')}})</a> <a href="#" onclick="completeVerification('{{$paymentMethod->public_id}}','{{$paymentMethod->currency->symbol}}')">({{trans('texts.complete_verification')}})</a>
@else
({{ trans('texts.verification_pending') }})
@endif
@elseif($paymentMethod->status == PAYMENT_METHOD_STATUS_VERIFICATION_FAILED) @elseif($paymentMethod->status == PAYMENT_METHOD_STATUS_VERIFICATION_FAILED)
({{trans('texts.verification_failed')}}) ({{trans('texts.verification_failed')}})
@endif @endif