Coder Social home page Coder Social logo

brunobar79 / eth-commerce Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 7.0 3.7 MB

Javascript library to accept ethereum payments on any website

Home Page: https://www.eth-commerce.com

License: MIT License

HTML 7.09% JavaScript 30.59% CSS 62.30% PHP 0.02%
blockchain crypto cryptocurrency dapp ethereum javascript metamask payments web3

eth-commerce's Introduction

Metrics

eth-commerce's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

eth-commerce's Issues

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.

Amount not passed to MetaMask

Hey there, I just noticed that the button doesn't seem to pass the amount to MM anymore. I found a little error in the function getEtherPriceIn. It sends a POST request where it should be GET. Now it works.

  getEtherPriceIn(currency) {
    return new Promise((resolve, reject) => {
      fetch(
        `https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=${currency}&sign=true`,
        {
          method: "GET", // <----------------------------------------
          mode: "cors"
        }
      )
        .then(response => response.json())
        .then(data => {
          resolve(data[currency]);
        })
        .catch(e => {
          reject(e);
        });
    });
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.