#paypal api #html
Hey guys,
I have an HTML Component on my page which is processing payments with PayPal.
Until now I have been successful in using .postmessage to send the Amount to the HTML component.
Does anyone know how to send the currency too along with the amount ?
HTML Component:
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script type="text/javascript">
let AMOUNT = 0;
window.onmessage = (event) => {
if (event.data > 0) {
AMOUNT = event.data; //wanna receive currency too
}
}
paypal.Button.render({
env: 'production',
style: {
label: 'checkout',
size: 'medium',
shape: 'rect',
color: 'blue',
tagline: 'false'
},
client: {
production: 'secret_key_here'
},
commit: true,
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: `${AMOUNT}`, currency: 'USD' } // see here, I want to send the currency too
}
],
redirect_urls: {
return_url: 'https://www.xxx.com',
cancel_url: 'https://www.xxx.com/cancel'
}
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
actions.redirect();
}
);
},
onCancel: function(data, actions) {
actions.redirect();
}
}, '#paypal-button-container');
</script>
</body>
Page:
$w("html1").postmessage($w("#input1#).value);
Is it possible to send AMOUNT & CURRENCY both to the HTML Component ?