Для тех, кто использует OpenCart, кто может столкнуться с этим.
Сценарий по умолчанию в \ catalog \ view \ theme \ default \ template \ extension \ payment \ pp_ express .twig равен
(function () {
paypal.Button.render({
env: '{{ paypal_environment }}',
style: {
layout: '{{ payment_pp_express_style_layout }}',
size: '{{ payment_pp_express_style_size }}',
shape: '{{ payment_pp_express_style_shape }}',
color: '{{ payment_pp_express_style_color }}'
},
commit: true,
funding: {
allowed: [{{ allowed_payment_methods }}],
disallowed: [{{ disallowed_payment_methods }}]
},
payment: function (data, actions) {
return paypal.request.get("{{ continue }}", {
headers: {
'Accept': 'application/paypal-json-token',
}
}).then(function (response) {
if (!response || !response.token) {
throw new Error('There was an error fetching the PayPal token');
}
return response.token;
}).catch(function (err) {
throw err;
});
},
onAuthorize: function (data, actions) {
return actions.redirect();
},
onCancel: function (data, actions) {
return actions.redirect();
},
onError: function (error) {
$('.pp-checkout-button-container').empty().html('<div class="alert alert-danger">' + error + '</div>');
return;
}
}, '#pp-checkout-button');
})();
Заменить метод оплаты по умолчанию в скрипте на вызов вашего внешнего скрипта
(function () {
paypal.Button.render({
env: '{{ paypal_environment }}',
style: {
layout: '{{ payment_pp_express_style_layout }}',
size: '{{ payment_pp_express_style_size }}',
shape: '{{ payment_pp_express_style_shape }}',
color: '{{ payment_pp_express_style_color }}'
},
commit: true,
funding: {
allowed: [{{ allowed_payment_methods }}],
disallowed: [{{ disallowed_payment_methods }}]
},
payment: function(){
var response = myCustomValidationFunction();
return response.token;
},
onAuthorize: function (data, actions) {
return actions.redirect();
},
onCancel: function (data, actions) {
return actions.redirect();
},
onError: function (error) {
$('.pp-checkout-button-container').empty().html('<div class="alert alert-danger">' + error + '</div>');
return;
}
}, '#pp-checkout-button');
})();
function myCustomValidationFunction(){
/* External function for paypal.Button.render */
/* must return json data with a toekn element */
var json;
json.token = $.get(stript that returns json with token);
return json;
}