Micro Documentation

Payment Client JS SDK

Client side JavaScript/TypeScript library for accepting Micropayments

Installation

You can use either from a CDN:

<script type="text/javascript" src="https://cdn.stage.m.todaq.net/micropay.min.js"></script>

Or through npm

npm install --save @todaqmicro/payment-js

Basic Usage

The most basic way to set up a micro payment button is using elements.

const micro = await loadMicroPayments(
  // Replace <PUBLIC_SECRET> with your accounts' public secret.
  "<PUBLIC_SECRET>",
  { apiVersion: 'main' }
);

const elements = micro.elements();
const button = await elements.create('payment', {
  // Replace <HASH> with the commodities hash.
  hash: '<HASH>',
  theme: "light",
  styles: {
    colorPrimary: '#000000',
    colorBackground: '#FDB902',
    borderRadius: '0',
  },
});

if (button) {
  button.mount("#signup-submit");        
}

There are three major steps in creating a micro payment button:

  1. Load the MicroPayment SDK with loadMicroPayments using async/await or Promises.
  2. Create a payment element using the elements.create() function.
  3. Mount the payment1 element to a DOM element with .mount().

When a payment has been made a payment event is emitted on the HTML document DOM element. Simply add an event listener and then you can validate the payment with the validatePayment function on the server side.