Smart buttons - Update value on event or button click

damianohm
Contributor
Contributor

Hi there,

 

I have integrated the Smart buttons into a form we have for registrations and wanted to allow the user to register multiple people at the same time. 

 

Is this possible with the Smart Buttons and if so is there any documentation or examples for doing it?

 

Currently my button code looks like:

 

 

var order_value = $('#course-summary').data('price');
paypal.Buttons({
        style: {
            layout:  'horizontal',
            color:   'white',
            shape:   'rect',
            label:   'paypal',
            tagline: false
          },
        createOrder: function(data, actions) {
          return actions.order.create({
            "intent": "CAPTURE",
            purchase_units: [{
              amount: {
                "currency_code": "GBP",
                value: order_value
              }
            }]
          });
        },
        onApprove: function(data, actions) {
          return actions.order.capture().then(function(details) {
            alert('Transaction completed by ' + details.payer.name.given_name + ' - Order ID = ' + data.orderID);
            // 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');

 

 

I have looked at the onclick attribute but not worked out how to use it to update the value. Also noticed for the changing shipping examples there is 

actions.order.patch but I can't find other examples of it's use.
 
Any help welcome!
 
Thanks
Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

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