2017-05-05 4 views
0

Ich versuche Paypal Checkout zu implementieren. Ich fand dieses Stück Code, die für mich nahezu perfekt ist, aber nicht ganz:Paypal Checkout mit Umleitung?

onAuthorize: function(data, actions) { 
    // Get the payment details 
    return actions.payment.get().then(function(data) { 
     // Display the payment details and a confirmation button 
     var shipping = data.payer.payer_info.shipping_address; 
     document.querySelector('#recipient').innerText = shipping.recipient_name; 
     document.querySelector('#line1').innerText  = shipping.line1; 
     document.querySelector('#city').innerText  = shipping.city; 
     document.querySelector('#state').innerText  = shipping.state; 
     document.querySelector('#zip').innerText  = shipping.postal_code; 
     document.querySelector('#country').innerText = shipping.country_code; 
     document.querySelector('#paypal-button-container').style.display = 'none'; 
     document.querySelector('#confirm').style.display = 'block'; 
     // Listen for click on confirm button 
     document.querySelector('#confirmButton').addEventListener('click', function() { 
      // Disable the button and show a loading message 
      document.querySelector('#confirm').innerText = 'Loading...'; 
      document.querySelector('#confirm').disabled = true; 
      // Execute the payment 
      return actions.payment.execute().then(function() { 
       // Show a thank-you note 
       document.querySelector('#thanksname').innerText = shipping.recipient_name; 
       document.querySelector('#confirm').style.display = 'none'; 
       document.querySelector('#thanks').style.display = 'block'; 
      }); 
     }); 
    }); 
} 

Ich möchte den Benutzer auf einem anderen PHP-Seite umgeleitet werden, wenn die Zahlung autorisiert ist. Kann ich weiterhin die Funktionen actions.payment.get() und actions.payment.execute() aufrufen? Wenn ja, wie soll ich fortfahren, sie anzurufen? Wenn nicht, warum?

Antwort

0

Sie können Ihre PHP-URL konfigurieren, wenn Sie die Zahlung vorbei an den Urls auf die Anforderung Zahlung erstellen erstellen mit dem redirect_urls Eigenschaft

{ 
    intent: "sale", 
    ... 
    redirect_urls : 
    { 
    return_url : "http://youreturnurl.com/finished", 
    cancel_url : "http://youreturnurl.com/canceled" 
    }, 
    ... 
    transactions: [ { 
    ... 
    }] 
    ... 
} 

und Sie brauchen nur actions.redirect() in Ihrer dann Methode aufzurufen nach die get().

onAuthorize: function(data, actions) { 
    return actions.payment.get().then(function(data) { 
    //do extra actions 
    ... 
    return actions.redirect(); 
}} 

Sie können für die onCancel() das gleiche tun oder einfach das Popup mit actions.close() schließen.

Verwandte Themen