risolto così:
codice:
let nome = null;
let cognome = null;
let indirizzo = null;
let cap = null;
let citta = null;
let provincia = null;
let cf = null;
let prefisso = null;
let telefono = null;
let email = null;
let d_nome = null;
let d_cognome = null;
let d_indirizzo = null;
let d_cap = null;
let d_citta = null;
let d_provincia = null;
let d_cf = null;
let d_prefisso = null;
let d_telefono = null;
let d_email = null;
let is_privacy = null;
paypal.Buttons({
env: 'sandbox',
commit: true,
style: {
layout: 'vertical',
color: 'blue',
shape: 'rect',
label: 'paypal',
height: 35
},
onClick: function (data, actions) {
nome = $('#nome').val();
cognome = $('#congnome').val();
indirizzo = $('#indirizzo').val();
cap = $('#cap').val();
citta = $('#citta').val();
provincia = $('#provincia').val();
telefono = $('#telefono').val();
email = $('#email').val();
cf = $('#cf').val();
prefisso = $('#prefisso').val();
is_privacy = $('#chk_privay').prop("checked");
// CONTROLLA SE LA PRIVCAY È CECCATA
if (!is_privacy) {
$('#msg_err').html('Devi accettare la Privacy Policy prima di continuare');
$('#modal_privacy').modal('show');
return actions.reject();
} else {
// CONTROLLA CHE TUTTI I VALORI SIANO INSERITI
if (R.isEmpty(nome) || R.isEmpty(cognome) || R.isEmpty(indirizzo) || R.isEmpty(cap) || R.isEmpty(citta)
|| R.isEmpty(provincia) || R.isEmpty(prefisso) || R.isEmpty(telefono) || R.isEmpty(email)) {
$('#msg_err').html('Tutti i campi, tranne il codice fiscale, sono obbligatori');
$('#modal_privacy').modal('show');
return actions.reject();
} else {
// CONTROLLA SE È UN REGALO
if (sessionStorage.getItem('IS_REGALO') === 'SI') {
d_nome = $('#dnome').val();
d_cognome = $('#dcongnome').val();
d_indirizzo = $('#dindirizzo').val();
d_cap = $('#dcap').val();
d_citta = $('#dcitta').val();
d_provincia = $('#dprovincia').val();
d_telefono = $('#dtelefono').val();
d_email = $('#demail').val();
d_cf = $('#dcf').val();
d_prefisso = $('#dprefisso').val();
// CONTROLLA CHE TUTTI I CAMPI DEL BENEFICIARIO SIANO INSERITI
if (R.isEmpty(d_nome) || R.isEmpty(d_cognome) || R.isEmpty(d_indirizzo) || R.isEmpty(d_cap) || R.isEmpty(d_citta)
|| R.isEmpty(d_provincia) || R.isEmpty(d_prefisso) || R.isEmpty(d_telefono) || R.isEmpty(d_email)) {
$('#msg_err').html('Tutti i campi, compresi quelli del beneficiario, tranne il codice fiscale, sono obbligatori');
$('#modal_privacy').modal('show');
return actions.reject();
} else {
return actions.resolve();
}
} else {
return actions.resolve();
}
}
}
},
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '50'
}
}]
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
},
onError: function (err) {
console.log('ERRORE');
console.log(err);
}
}).render('#paypal-button-container');
invece di disabilitare i bottoni nell'onInit, ho usato le actions dell'onClick.