PayPal JavaScript SDK: I can't set the amount value dynamically

Viewed 65

I need to change "value": 22 to the value of the variable precioServicio but I cannot change it.

var precioServicio = document.getElementById("precioServicio");

createOrder: function(data, actions) {
    return actions.order.create({
      purchase_units: [{"amount":{"currency_code":"USD","value":22}}] //PRECIO A PAGAR
    });
  },
2 Answers

Replace the hardcoded number 22 with... precioServicio or document.getElementById("precioServicio")

You can use purchase_units: [{"amount":{"currency_code":"USD","value":Number(precioServicio)}}]

Related