This guide walks through a complete implementation of a donation page for T.R.I.E. (The Real Internet Experience) using TodaQ’s micropayment system. This example demonstrates how to integrate multiple payment elements with different donation amounts.
The page uses a simple HTML structure with three donation options:
<body>
  <main>
    <h1><img id="logo" src="golden_TRIEangle.svg" alt="T.R.I.E."></h1>
    <h2>Donate to T.R.I.E.</h2>
    <h3>and feel good about yourself</h3>
    <!-- Three donation options with unique IDs -->
    <div class="payment" id="donate5"></div>
    <div class="payment" id="donate05"></div>
    <div class="payment" id="donate005"></div>
  </main>
</body>
Load the TodaQ micropayment library from CDN:
<!-- Load TodaQ micropayment library from CDN -->
<script type="module" crossorigin="anonymous" src="https://cdn.m.todaq.net/micropay.js"></script>
The JavaScript code initializes the payment elements after the DOM is fully loaded (repeat for each unique amount):
document.addEventListener("DOMContentLoaded", async () => {
  // Initialize MicroPayments with merchant public key
  const micro = await loadMicroPayments(
    "mp_1d1ea49e1bfe48a9bc3ff8d06b5c3afc", // Merchant Public Key | Public Secret
    { apiVersion: 'main' }                 // API Configuration
  );
  const elements = micro.elements();
  // Create payment element
  const element = await elements.create('payment', {
    hash: 'fe490b57-9aa0-4cbc-886f-db1fc1c895e9', // Unique payment identifier | commodity hash
    theme: "light",
    styles: {
      colorPrimary: '#000000',
      colorBackground: '#FDB902', // Yellow background
      borderRadius: '0',          // Square corners
    },
  });
  element.mount("#donate5");
});
Handle successful payments by listening for the global purchase event:
// Global event listener for successful payments
document.addEventListener('purchase', async (nonce) => {
  location.assign('thanks.html'); // Redirect to thank you page
});
CDN Loading: The TodaQ Micropay Library loads from https://cdn.m.todaq.net/micropay.js
Initialization Flow:
Event Handling:
Styling Consistency:
https://cdn.m.todaq.net/micropay.js)This implementation provides a complete, working example that demonstrates the core concepts covered in the Getting Started guide, showing how to integrate multiple payment options with consistent styling and proper event handling.