I have been give the task of making a PayPal button which will receive a value based on user choices, but there are so many options in the website that making a button for each choice is unreasonable, I have searched for the answer but either the information was outdated, insecure, or I didn't have the knowledge to understand.
I have seen terms of checkout API,..etc., this and that, but I can't just figure it out.
So, can you guys enlighten me and show me the way.
I know html, php but still kind of a beginner, js sort of.
You can use
document.write('variable')
In JavaScript
Or
echo 'variable'
In PHP
To change the text of a button to be a certain variable that could depend on the item. JavaScript is easier to setup but PHP could work well if you have a server side data base of items and their prices.
Without knowing more about your problem, I'll outline an implementation of a product and quantity system that you can flick through.
You say you have a collection of items, x, y, x
and provide the option to choose the length of time (in months) the user can have the product.
Let's say, in Javascript, you have the following class for a Product
object:
function Product() = {
this.Name = "Gaming Computer";
this.Price = 100; // Per month, in $.
}
So a user selects a Product
, and the Product
the choose is the Gaming Computer
. You can test see the name of the product in code by performing:
console.log(Product.Name)
// Gaming Computer
You now have the product, and the associated property
, price
. From the inline comment you can see this is in $, per month
.
Let's assume the user picks Gaming computer, 6 months
. You don't want to do the following:
var month = $('#monthComboBox').val();
if(product.Name == "Gaming Computer" and month == 1) {
// do stuff
} else if(product.Name == "Gaming Computer" and month == 2) {
// This is getting laborious
} else ....
so you would do the following:
Product.Price * month = totalCost
, which will give you the total to be charged to the user. You can then pass this value to the Paypal button and charge it as needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.