Daniels118
24-07-2017, 13:33
Buongiorno a tutti, spero di scrivere nella sezione giusta.
Un paio di settimane fa ho integrato il pagamento Express Checkout di paypal in un sito di e-commerce che ho realizzato (non parliamo di piattaforme come prestashop e simili, è una soluzione custom), e per circa una settimana ha funzionato senza problemi, poi improvvisamente ha smesso completamente di funzionare. La tipologia di integrazione che ho utilizzato è quella con checkout.js + server side rest, di cui potete trovare qui un esempio: https://developer.paypal.com/demo/checkout/#/pattern/server
Di seguito il codice che ho utilizzato io (ometto per brevità il codice html completo, ma riporto integralmente la parte javascript):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<!-- CUT -->
<script language="javascript" type="text/javascript" src="https://www.paypalobjects.com/api/checkout.js?ver=69"></script>
<!-- CUT -->
</head>
<body style="">
<!-- CUT -->
<div id="paypal-button" style="float: right;"></div>
<!-- CUT -->
</body>
</html>
$(function() {
if ($('#paypal-button').length > 0) initExpressCheckout();
});
function initExpressCheckout() {
paypal.Button.render({
//env: 'sandbox',
env: 'production',
locale: 'it_IT',
commit: true,
payment: function() {
return paypal.request.post(home + "azioni/create_payment.php", {
id_ordine: id_ordine
}).then(function(data) {
return data.paymentID;
});
},
onAuthorize: function(data, actions) {
return paypal.request.post(home + "azioni/execute_payment.php", {
id_ordine: id_ordine,
paymentID: data.paymentID,
payerID: data.payerID
}).then(function(data2) {
if (data2.state == 'approved' || data2.name == 'DUPLICATE_TRANSACTION') {
$('#paypal-button').hide().after('Il pagamento è stato confermato');
} else {
alert('Il pagamento non è andato a buon fine');
}
});
},
onError: function(err) {
alert(err);
}
}, '#paypal-button');
}
Quello che accade è che il pulsante viene renderizzato ma quando lo clicco non succede assolutamente nulla.
Dopo qualche secondo che la pagina è stata caricata (anche se non premo il pulsante) vengono fuori i seguenti errori nella console javascript:
checkout.js:5876 Uncaught TypeError: Cannot read property 'ref' of undefinedgetWindowByRef @ checkout.js:5876(anonymous function) @ checkout.js:5939(anonymous function) @ checkout.js:7073ChildComponent.setWindows @ checkout.js:3706ChildComponent @ checkout.js:3620Component.registerChild @ checkout.js:4129Component @ checkout.js:4100create @ checkout.js:6374modules../src/components/button/component.js @ checkout.js:8097__webpack_require__ @ checkout.js:11modules../src/components/button/index.js @ checkout.js:8532__webpack_require__ @ checkout.js:11modules../src/components/index.js @ checkout.js:9427__webpack_require__ @ checkout.js:11modules../src/api/rest.js @ checkout.js:7891__webpack_require__ @ checkout.js:11modules../src/api/index.js @ checkout.js:7783__webpack_require__ @ checkout.js:11modules../src/interface.js @ checkout.js:10347__webpack_require__ @ checkout.js:11modules../src/index.js @ checkout.js:10235__webpack_require__ @ checkout.js:11modules../src/load.js @ checkout.js:12281__webpack_require__ @ checkout.js:11modules../node_modules/Base64/base64.js @ checkout.js:38(anonymous function) @ checkout.js:39
promise.js:7Uncaught TypeError: Cannot read property 'Promise' of undefined../node_modules/xo-buttonjs/public/js/button/promise.js @ promise.js:7__webpack_require__ @ bootstrap bbe5750…:19../node_modules/xo-buttonjs/public/js/button/index.js @ index.js:3__webpack_require__ @ bootstrap bbe5750…:190 @ index.js:5__webpack_require__ @ bootstrap bbe5750…:190 @ bootstrap bbe5750…:39(anonymous function) @ bootstrap bbe5750…:39
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3555 Uncaught TypeError: window.preload is not a function(anonymous function) @ button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3555
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3587 Uncaught TypeError: window.preload is not a function(anonymous function) @ button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3587
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3602 Uncaught TypeError: window.preload is not a function(anonymous function) @ button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3602
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3623 Uncaught TypeError: window.preloadComplete is not a function
Spero riusciate a darmi qualche dritta, ho già googolato senza successo :(
Grazie in anticipo a chi mi risponderà.
Daniele
Un paio di settimane fa ho integrato il pagamento Express Checkout di paypal in un sito di e-commerce che ho realizzato (non parliamo di piattaforme come prestashop e simili, è una soluzione custom), e per circa una settimana ha funzionato senza problemi, poi improvvisamente ha smesso completamente di funzionare. La tipologia di integrazione che ho utilizzato è quella con checkout.js + server side rest, di cui potete trovare qui un esempio: https://developer.paypal.com/demo/checkout/#/pattern/server
Di seguito il codice che ho utilizzato io (ometto per brevità il codice html completo, ma riporto integralmente la parte javascript):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<!-- CUT -->
<script language="javascript" type="text/javascript" src="https://www.paypalobjects.com/api/checkout.js?ver=69"></script>
<!-- CUT -->
</head>
<body style="">
<!-- CUT -->
<div id="paypal-button" style="float: right;"></div>
<!-- CUT -->
</body>
</html>
$(function() {
if ($('#paypal-button').length > 0) initExpressCheckout();
});
function initExpressCheckout() {
paypal.Button.render({
//env: 'sandbox',
env: 'production',
locale: 'it_IT',
commit: true,
payment: function() {
return paypal.request.post(home + "azioni/create_payment.php", {
id_ordine: id_ordine
}).then(function(data) {
return data.paymentID;
});
},
onAuthorize: function(data, actions) {
return paypal.request.post(home + "azioni/execute_payment.php", {
id_ordine: id_ordine,
paymentID: data.paymentID,
payerID: data.payerID
}).then(function(data2) {
if (data2.state == 'approved' || data2.name == 'DUPLICATE_TRANSACTION') {
$('#paypal-button').hide().after('Il pagamento è stato confermato');
} else {
alert('Il pagamento non è andato a buon fine');
}
});
},
onError: function(err) {
alert(err);
}
}, '#paypal-button');
}
Quello che accade è che il pulsante viene renderizzato ma quando lo clicco non succede assolutamente nulla.
Dopo qualche secondo che la pagina è stata caricata (anche se non premo il pulsante) vengono fuori i seguenti errori nella console javascript:
checkout.js:5876 Uncaught TypeError: Cannot read property 'ref' of undefinedgetWindowByRef @ checkout.js:5876(anonymous function) @ checkout.js:5939(anonymous function) @ checkout.js:7073ChildComponent.setWindows @ checkout.js:3706ChildComponent @ checkout.js:3620Component.registerChild @ checkout.js:4129Component @ checkout.js:4100create @ checkout.js:6374modules../src/components/button/component.js @ checkout.js:8097__webpack_require__ @ checkout.js:11modules../src/components/button/index.js @ checkout.js:8532__webpack_require__ @ checkout.js:11modules../src/components/index.js @ checkout.js:9427__webpack_require__ @ checkout.js:11modules../src/api/rest.js @ checkout.js:7891__webpack_require__ @ checkout.js:11modules../src/api/index.js @ checkout.js:7783__webpack_require__ @ checkout.js:11modules../src/interface.js @ checkout.js:10347__webpack_require__ @ checkout.js:11modules../src/index.js @ checkout.js:10235__webpack_require__ @ checkout.js:11modules../src/load.js @ checkout.js:12281__webpack_require__ @ checkout.js:11modules../node_modules/Base64/base64.js @ checkout.js:38(anonymous function) @ checkout.js:39
promise.js:7Uncaught TypeError: Cannot read property 'Promise' of undefined../node_modules/xo-buttonjs/public/js/button/promise.js @ promise.js:7__webpack_require__ @ bootstrap bbe5750…:19../node_modules/xo-buttonjs/public/js/button/index.js @ index.js:3__webpack_require__ @ bootstrap bbe5750…:190 @ index.js:5__webpack_require__ @ bootstrap bbe5750…:190 @ bootstrap bbe5750…:39(anonymous function) @ bootstrap bbe5750…:39
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3555 Uncaught TypeError: window.preload is not a function(anonymous function) @ button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3555
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3587 Uncaught TypeError: window.preload is not a function(anonymous function) @ button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3587
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3602 Uncaught TypeError: window.preload is not a function(anonymous function) @ button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3602
button?env=production&locale.x=it_IT&version=4&uid=539265a272&style.color=gold&style.shape=pill&sty…:3623 Uncaught TypeError: window.preloadComplete is not a function
Spero riusciate a darmi qualche dritta, ho già googolato senza successo :(
Grazie in anticipo a chi mi risponderà.
Daniele