I am building a lottery web application where customers can select their own numbers or get 4 random numbers. How can I carry these numbers that the customer inputs/randomly generates into my shopping cart / paypal button? Thanks for any help. This is my code so far for the generation of random lottery numbers on JSP page.
<div id="num1" class="ball col-md-2"><span id="one"></span></div>
<div id="num2" class="ball col-md-2"><span id="two"></span></div>
<div id="num3" class="ball col-md-2"><span id="three"></span></div>
<div id="num4" class="ball col-md-2"><span id="four"></span></div>
<%-- onclick to execute JavaScript function--%>
<button onclick="random()">QuickPick!</button>
</div>
This is the JS file to execute the random numbers to be generated.
function random(){
//selects the 4 circles on the page
var one= document.getElementById('one');
var two= document.getElementById('two');
var three= document.getElementById('three');
var four= document.getElementById('four');
//create random number for each of the circles between 1-30
var a = Math.floor(Math.random()*30);
var b = Math.floor(Math.random()*30);
var c = Math.floor(Math.random()*30);
var d = Math.floor(Math.random()*30);
//put the random number into each of the 4 circles
one.textContent = a;
two.textContent = b;
three.textContent = c;
four.textContent = d;
}
I have set up a PayPal REST API integration by following instructions on the website, I also can use a buy now smart button from PayPal. My question is, how can I issue the customers a receipt of the numbers they have selected up successful purchase of the ticket? Is there a way to pass the values of the JS code into the PayPal checkout page, any help is greatly appreciated as I cannot find a way to do this, thanks.
In the Integrate Checkout guide, see the bullet #6 which has this example of transferring item information to PayPal:
createOrder: function(data, actions) {
return actions.order.create({
"purchase_units": [{
"amount": {
"currency_code": "USD",
"value": "100",
"breakdown": {
"item_total": { /* Required when including the `items` array */
"currency_code": "USD",
"value": "100"
}
}
},
"items": [
{
"name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
"description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
"unit_amount": {
"currency_code": "USD",
"value": "50"
},
"quantity": "2"
},
]
}]
});
},
You can pass the same type of line item information whether using actions.order.create to create the order in the client side JS, or the REST API to create the order on the server. It is the same Orders v2 JSON format either way.
(A server-side REST API integration to create and capture the order is the most robust way; you can pair this with a JS SDK button for approval per the guide in bullet #5 of the above link.)