eth-commerce
eth-commerce copied to clipboard
Update the total amount
Feature Request
Hey. Excellent script. I would like to use it in an Online Shop for Checkout. I kinda hacked it in a way that now I remove and regenerate the DOM object of the button each time the value changes by calling this custom function:
var extCurrency = 'EUR';
function addMetaMask() {
if ($('#metamask-checkout').length) $('#metamask-checkout').remove();
// create div
$('<div/>')
.addClass('eth-commerce-button')
.attr('id', 'metamask-checkout')
.appendTo("div.widget");
// turn it into an ETHCommerce button
var ethCommerce = new EthCommerce();
ethCommerce.render(
{
targetElement: 'metamask-checkout',
type: 'PAY',
amount: $('span.ct-cart-total').text().replace(/\D/g,''),
currency: extCurrency,
address: '0x11A7Ca870700f284e4647E55DeD9040f0F86D4D4'
}, (e)=>{
console.log('error callback', e);
},(tx)=>{
console.log('success callback', tx);
});
}
It would be cool if your class had a function to update the amount in a more elegant way.