mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Support adding WePay ACH from payment page
This commit is contained in:
parent
4dded687b5
commit
acbc0e887f
@ -111,6 +111,8 @@ class ClientPortalController extends BaseController
|
||||
if($braintreeGateway->getPayPalEnabled()) {
|
||||
$data['braintreeClientToken'] = $this->paymentService->getBraintreeClientToken($account);
|
||||
}
|
||||
} elseif ($wepayGateway = $account->getGatewayConfig(GATEWAY_WEPAY)){
|
||||
$data['enableWePayACH'] = $wepayGateway->getAchEnabled();
|
||||
}
|
||||
|
||||
$showApprove = $invoice->quote_invoice_id ? false : true;
|
||||
@ -224,43 +226,39 @@ class ClientPortalController extends BaseController
|
||||
|
||||
foreach(Gateway::$paymentTypes as $type) {
|
||||
if ($gateway = $account->getGatewayByType($type)) {
|
||||
$types = array($type);
|
||||
|
||||
if ($type == PAYMENT_TYPE_STRIPE) {
|
||||
$types = array(PAYMENT_TYPE_STRIPE_CREDIT_CARD);
|
||||
if ($gateway->getAchEnabled()) {
|
||||
$types[] = PAYMENT_TYPE_STRIPE_ACH;
|
||||
if ($type == PAYMENT_TYPE_DIRECT_DEBIT) {
|
||||
if ($gateway->gateway_id == GATEWAY_STRIPE) {
|
||||
$type = PAYMENT_TYPE_STRIPE_ACH;
|
||||
} elseif ($gateway->gateway_id == GATEWAY_WEPAY) {
|
||||
$type = PAYMENT_TYPE_WEPAY_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));
|
||||
$url = URL::to("/payment/{$invitation->invitation_key}/{$typeLink}");
|
||||
$typeLink = strtolower(str_replace('PAYMENT_TYPE_', '', $type));
|
||||
$url = URL::to("/payment/{$invitation->invitation_key}/{$typeLink}");
|
||||
|
||||
// PayPal doesn't allow being run in an iframe so we need to open in new tab
|
||||
if ($type === PAYMENT_TYPE_PAYPAL && $account->iframe_url) {
|
||||
$url = 'javascript:window.open("' . $url . '", "_blank")';
|
||||
}
|
||||
|
||||
if ($type == PAYMENT_TYPE_STRIPE_CREDIT_CARD) {
|
||||
$label = trans('texts.' . strtolower(PAYMENT_TYPE_CREDIT_CARD));
|
||||
} elseif ($type == PAYMENT_TYPE_STRIPE_ACH) {
|
||||
$label = trans('texts.' . strtolower(PAYMENT_TYPE_DIRECT_DEBIT));
|
||||
} else {
|
||||
$label = trans('texts.' . strtolower($type));
|
||||
}
|
||||
|
||||
$paymentTypes[] = [
|
||||
'url' => $url, 'label' => $label
|
||||
];
|
||||
|
||||
if($gateway->getPayPalEnabled()) {
|
||||
$paymentTypes[] = [
|
||||
'label' => trans('texts.paypal'),
|
||||
'url' => $url = URL::to("/payment/{$invitation->invitation_key}/braintree_paypal"),
|
||||
];
|
||||
}
|
||||
// PayPal doesn't allow being run in an iframe so we need to open in new tab
|
||||
if ($type === PAYMENT_TYPE_PAYPAL && $account->iframe_url) {
|
||||
$url = 'javascript:window.open("' . $url . '", "_blank")';
|
||||
}
|
||||
|
||||
if ($type == PAYMENT_TYPE_STRIPE_CREDIT_CARD) {
|
||||
$label = trans('texts.' . strtolower(PAYMENT_TYPE_CREDIT_CARD));
|
||||
} elseif ($type == PAYMENT_TYPE_STRIPE_ACH || $type == PAYMENT_TYPE_WEPAY_ACH) {
|
||||
$label = trans('texts.' . strtolower(PAYMENT_TYPE_DIRECT_DEBIT));
|
||||
} elseif ($type == PAYMENT_TYPE_BRAINTREE_PAYPAL) {
|
||||
$label = trans('texts.' . strtolower(PAYMENT_TYPE_PAYPAL));
|
||||
} else {
|
||||
$label = trans('texts.' . strtolower($type));
|
||||
}
|
||||
|
||||
$paymentTypes[] = [
|
||||
'url' => $url, 'label' => $label
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,23 @@ class PaymentController extends BaseController
|
||||
$details = json_decode(Input::get('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) {
|
||||
$useToken = true;
|
||||
$accountGateway = $invoice->client->account->getTokenGateway();
|
||||
@ -206,15 +222,6 @@ class PaymentController extends BaseController
|
||||
$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 += [
|
||||
@ -497,7 +504,6 @@ class PaymentController extends BaseController
|
||||
->withInput(Request::except('cvv'));
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// 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
|
||||
@ -511,17 +517,22 @@ class PaymentController extends BaseController
|
||||
$details = $this->paymentService->getPaymentDetails($invitation, $accountGateway, $data);
|
||||
$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
|
||||
$tokenBillingSupported = false;
|
||||
$sourceReferenceParam = 'token';
|
||||
if ($accountGateway->gateway_id == GATEWAY_STRIPE) {
|
||||
$tokenBillingSupported = true;
|
||||
$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) {
|
||||
$tokenBillingSupported = true;
|
||||
$sourceReferenceParam = 'paymentMethodToken';
|
||||
@ -547,8 +558,8 @@ class PaymentController extends BaseController
|
||||
}
|
||||
$details[$sourceReferenceParam] = $sourceReference;
|
||||
unset($details['card']);
|
||||
} elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing') || $paymentType == PAYMENT_TYPE_STRIPE_ACH) {
|
||||
$token = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */);
|
||||
} 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($paymentType, $gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */);
|
||||
if ($token) {
|
||||
$details[$sourceReferenceParam] = $token;
|
||||
if ($customerReferenceParam) {
|
||||
@ -586,7 +597,7 @@ class PaymentController extends BaseController
|
||||
if (!$ref) {
|
||||
$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)
|
||||
->withInput(Request::except('cvv'));
|
||||
} else {
|
||||
@ -614,7 +625,7 @@ class PaymentController extends BaseController
|
||||
$response->redirect();
|
||||
} else {
|
||||
$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'));
|
||||
} else {
|
||||
return Redirect::to('view/'.$invitationKey);
|
||||
@ -622,7 +633,7 @@ class PaymentController extends BaseController
|
||||
}
|
||||
} catch (\Exception $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'));
|
||||
} else {
|
||||
return Redirect::to('view/'.$invitationKey);
|
||||
|
@ -1334,7 +1334,9 @@ $LANG = array(
|
||||
'wepay_payment_tos_agree' => 'I agree to the WePay :terms and :privacy_policy.',
|
||||
'privacy_policy' => '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;
|
||||
|
@ -59,6 +59,35 @@
|
||||
})
|
||||
});
|
||||
</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
|
||||
@stop
|
||||
|
||||
|
@ -50,20 +50,25 @@
|
||||
</script>
|
||||
@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">
|
||||
$(function() {
|
||||
WePay.set_endpoint('{{ WEPAY_ENVIRONMENT }}');
|
||||
// Shortcuts
|
||||
$('#add-ach').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':{!! json_encode($contact->email) !!}
|
||||
'email':email
|
||||
}, function(data){
|
||||
dataObj = JSON.parse(data);
|
||||
if(dataObj.bank_account_id) {
|
||||
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 }}
|
||||
@endif
|
||||
@if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW)
|
||||
<a href="#" onclick="completeVerification('{{$paymentMethod->public_id}}','{{$paymentMethod->currency->symbol}}')">({{trans('texts.complete_verification')}})</a>
|
||||
@if($gateway->gateway_id == GATEWAY_STRIPE)
|
||||
<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)
|
||||
({{trans('texts.verification_failed')}})
|
||||
@endif
|
||||
|
Loading…
Reference in New Issue
Block a user