Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
Paypal Checkout onShippingChange won't work with Ajax-Call

When a customer changes the shipping adress in the paypal checkout I am fetching it with "onShippingChange". However when I check the given adress and deny it or need to update the shipping costs it won't work.

Working example without the ajax call:

paypal.Buttons({
...
    onShippingChange: function(data, actions) {
        if(data.shipping_address.country_code == 'ES'){
            return actions.reject();
        }
    return actions.resolve();
...
});

As soon as I change it to the following it won't work:

paypal.Buttons({
...
      onShippingChange: function(data, actions) {
         fetch(ajax, {
            method: 'post',
            body: new URLSearchParams({
                'do':'getShippingPricePaypalCheckout',
                'country':data.shipping_address.country_code,
                'id':data.orderID
            }),
            headers: {
                'Accept': 'application/json',
                'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          }).then(function(res) {
              return res.json();
          }).then(function(_data) {
              if(!_data || _data == 'false' || _data == false){
                  console.log("Value of data: "+data);
                  return actions.reject();
              }else
                  return actions.resolve();
          });
    }
...
});

In debug mode the actions.reject() is called. But in the paypal checkout the error-message, that the shipping country is not supported, will not show up.

The print out of console.log is correct and says "Value of data: false", so the actions.resolve() is being called but Paypal doesn't get it.

Any ideas?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Ok, I found my mistake.

I need a return before the fetch:

...
onShippingChange: function(data, actions) {
         return fetch(ajax, {
...

Now it is working :)

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda