Smart Payment Button help.

mike913
New Community Member

Thank you for taking the time to read.

So i have been banging my head against a brick wall for a few hours now and could really do with some help i have created a smart payment button.

The problem i am facing is i need it to be a custom amount my customers pay different prices and owe different amounts so i need it to allow the customer to enter the amount and then click pay.
*Note i have swapped my id for xxxx 

The code so far is as follows

 

 

 

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<script
src="https://www.paypal.com/sdk/js?client-id=xxx&commit=true">
</script>

<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// Set up the transaction
return actions.order.create({
purchase_units: [{
amount: {
value: '22.50'
}
}]
});
}
}).render('#paypal-button-container');
</script>


</body>

 

I have it set at £22.50 so far but as i say i need it to be a custom amount 

so for example if Mr Adams needs to pay £35 he can visit my website enter the amount and click pay with paypal or visa, and so on.

Thank you once again for reading and i hope someone will help.  

Login to Me Too
1 REPLY 1

Scott_Bestvater
Contributor
Contributor

You can have an input box where the user enters the amount.

 

Try this on your page:
<p><input type="text" id="userInput" onInput="myFunction(this.value);"><div id="paypal-button"></div></p>

 

Then in your script tag add a function to grab that amount and use that value in the :

function myFunction() {
amount = document.getElementById("userInput").value;

};

 

And modify your code to use that variable:

purchase_units: [{
amount: {
value: (amount)
}
}]

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.