Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda