i am just learning how to code javascript. got confused by this chunk of code. from my reading function(data, actions) is an anonymous function that passes two parameters to the function body. however, i don't see "data" being referenced anywhere inside the function. am i reading it wrong?
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// Set up the transaction
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
}
}).render('#paypal-button-container');
</script>
All the PayPal JS SDK callback functions have two parameters, data and actions. This is just the name/convention the SDK chooses to use for those parameters' names.
When creating a PayPal order or subscription on button click there isn't anything useful in the data object, so you won't find samples that make use of it -- but if you wanted to check its contents while developing you can log it to your browser console with something like:
createOrder: function(data, actions) {
console.log("createOrder data param", data, JSON.stringify(data,null,2) );
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
}