How to fill billing fields?

thierryler
Contributor
Contributor

Using the standard checkout, how can I pre fill the billing fields ?

 

My code :

 

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

<div id="paypal-button-container"></div>

<script>
  showSpinner();

  const price = 123.45;
  const customId = 'abcdef';

  paypal.Buttons({
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [{
          amount: {
            currency_code: "EUR",
            value: price,
          },
          // invoice_id: invoiceId,
          custom_id: customId,
        }]
      });
    },

    onApprove: function(data, actions) {
      console.log('ICE ::: onApprove ::: data: ', data)
      showSpinner();
      const { facilitatorAccessToken, orderID, payerID } = data
      // Here call server
    },

    onCancel: function (data) {
      console.log('ICE ::: onCancel ::: data: ', data)
    },

    onError: function (err) {
      console.log('ICE ::: onError ::: data: ', err)
    },

    onClick: function()  {
      console.log('ICE ::: onClick')
    },

    onInit: function(data, actions)  {
      console.log('ICE ::: onInit ::: data: ', data)
      hideSpinner();
    }
  }).render('#paypal-button-container');
</script>
    

 

It gives me that :

 

capture.png

 

 

1) As you can see (right column) I allready collected the customer's address on a previous page. So I do not really need to collect that fields again. Can I simply hide the address inputs? Or can I pre fill the inputs with the data I collected before?

2) Can I remove the delivery checkbox? I do not want the customer to specify and other address for the delivery...

 

Login to Me Too
1 REPLY 1

Nexus_Software
Contributor
Contributor

Hello @thierryler ,

 

One way to prepopulate the billing fields is to add the payer -> address object

E.g.

    paypal.Buttons({


        // Sets up the transaction when a payment button is clicked

        createOrder: function(data, actions) {

          return actions.order.create({
                  
                  payer: {
                  birth_date: '2021-01-01',
                  email_address: 'customer_at_emailaddress',
                  phone: {
                    phone_number: {
                        national_number[Removed. Phone #s not permitted],
                    }
                  },
                  name: {
                    given_name: 'Bub',
                    surname: 'Customer',
                  },
                  address: {
                    address_line_1: '33 ABC Street',
                    address_line_2: 'Apt 3',
                    admin_area_2: 'San Jose',
                    admin_area_1: 'CA',
                    postal_code: '95121',
                    country_code: 'US',
                  },
                },


            purchase_units: [{

              amount: {

                value: '33.00' // Can reference variables or functions. Example: `value: document.getElementById('...').value`

              }

            }]

          });

        },

 

 

 

add_address.png

 

Thank you.

 

Powered by Custom Software : NexWebSites.com
PayPal Developers

 

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.