eth-commerce icon indicating copy to clipboard operation
eth-commerce copied to clipboard

Update the total amount

Open ghost opened this issue 5 years ago • 0 comments

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.

ghost avatar Jun 11 '20 18:06 ghost