Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 24-07-2017, 13:33   #1
Daniels118
Senior Member
 
L'Avatar di Daniels118
 
Iscritto dal: Jan 2014
Messaggi: 852
[Javascript] Problema Paypal Express Checkout

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/ch...pattern/server
Di seguito il codice che ho utilizzato io (ometto per brevità il codice html completo, ma riporto integralmente la parte javascript):
Codice HTML:
<!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>
Codice:
$(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:
Codice:
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
Daniels118 è offline   Rispondi citando il messaggio o parte di esso
Old 24-07-2017, 18:07   #2
Daniels118
Senior Member
 
L'Avatar di Daniels118
 
Iscritto dal: Jan 2014
Messaggi: 852
Ho risolto, è bastato copiare i tag nell'head dell'esempio esattamente come sono riportati. La cosa strana è che inizialmente funzionava... ma la cosa ancora più strana è che ora funziona anche ripristinando i tag come li avevo scritti io... mi sa che non comprenderò mai quali oscuri meccanismi si celano dietro questi bizzarri eventi, ma alla fine mi basta che funzioni. Grazie comunque a coloro che hanno cercato di venirne a capo.
Buona serata
Daniele
Daniels118 è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 02:26.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v