paypalexpress-checkoutpaypal-pdt

How to dynamically change currency & pass other data in PayPal Express Checkout


I want to accept payment in Multiple currencies & also autofill the Address/Name in PayPal form using Express Checkout method

I have tried going through various posts, paypal getting started, paypal community, but not able to find if it possible. Currently, using Express Checkout I'm able to receive payment on changing the get parameter of the script.

<script src="https://www.paypal.com/sdk/js?client-id=valueOfClientID&currency=GBP"> </script>

Is is possible to pass the currency & name/address details in below code?

<script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '24'
          }
        }]
      });
    },
    onApprove: function(data, actions) {
      return actions.order.capture().then(function(details) {
        alert('Transaction completed by ' + details.payer.name.given_name);
        // Call your server to save the transaction
        return fetch('/paypal-transaction-complete', {
          method: 'post',
          headers: {
            'content-type': 'application/json'
          },
          body: JSON.stringify({
            orderID: data.orderID
          })
        });
      });
    }
  }).render('#paypal-button-container');
</script>

Solution

  • Based on the currency dynamically inject the script to the page and pass the address object as mentioned in the link