PHP Javascript - Insert variable into total parameter of PayPal checkout -


i have code here checkout on website:

<div id="paypal-button"></div>      <script>         paypal.button.render({              env: 'sandbox',              client: {                 sandbox:    'xxxxxx',                 production: 'xxxxxx'             },              commit: true,              payment: function(data, actions) {                 return actions.payment.create({                     payment: {                         transactions: [                             {                                 amount: { total: '14.50', currency: 'gbp' }                             }                         ]                     }                 });             },              onauthorize: function(data, actions) {                 return actions.payment.execute().then(function(payment) {                  });             }          }, '#paypal-button');     </script> 

instead of having price set '14.50', want value value of cart. example, if cart total comes '30.50', want value '30.50'. know cannot insert variable javascript though.

thank help.

what mean when cannot insert variable in javascript?

do display cart total somewhere? use value dom , update script:

var carttotal = document.getelementbyid('yourcarttotalinputhere').value; 

and replace amount '14.50' variable carttotal.

alternatively, if have javascript class managing cart can save value in namespace in global window , can access way. example:

window.cartdata.amount = 30; 

then replace '14.50' window.cartdata.amount.


Comments