Client side JavaScript/TypeScript library for accepting Micropayments
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
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:
loadMicroPayments using async/await or Promises.payment element using the elements.create() function.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.