Hey there. I’m trying to parse a string value to a variable, from a page code to an html component. While this works if I use numeric values, as soon as I use a non numeric, it blows apart? It’s driving me nuts, and no combination of var and/or let has made it right.
Is there any out there who can take a look? Thanks in advance.
PAGE CODE that works:
$w.onReady( function () {
// when a message is received from the HTML Component
$w(“#html1”).postMessage(‘0.44’);
PAGE CODE that doesn’t work
$w.onReady( function () {
// when a message is received from the HTML Component
$w(“#html1”).postMessage(‘this should be a string value’);
HTML Component Code:
<script type="text/javascript">
AMOUNT = 0;
window.onmessage = (event) => {
if (event.data > 0) { // here I also tried if (event.data > '')
AMOUNT = 0.2;
CUSTOMVAR = event.data;
}
}
paypal.Button.render({
env: 'sandbox', // sandbox | production
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: 'AVAsdrgkjshrgkjhdfgdgaUY0m9TuJKBB27u1dosborN7A2X5AwLYYl1GhRoUQo2naGFUKRGVM84p23BjMV',
production: '<insert production client id>'
},
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function(data, actions) {
// Make a call to the REST api to create the payment
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: `${AMOUNT}`, currency: 'USD' },
custom: `${CUSTOMVAR}`
}
]
}
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
// Make a call to the REST api to execute the payment
return actions.payment.execute().then(function() {
window.alert('Payment Complete!');
window.alert(`${CUSTOMVAR}`);
});
}
}, '#paypal-button-container');
</script>