npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mmpay-browser-sdk

v1.0.4

Published

JavaScript SDK for integrating the MMQR Merchant and Redirect payment gateway

Downloads

184

Readme

Supa JavaScript SDK

💳 Introduction

Welcome to the Supa JavaScript SDK! This library provides a secure and seamless way to integrate QR Code and Bank Redirect payments into any e-commerce checkout flow. Developed using TypeScript, the SDK offers a clean, type-safe interface and handles complex tasks like API communication, UI rendering, and asynchronous payment status polling automatically.


🛠️ Installation

The Supa SDK is distributed as a single JavaScript file, ready for direct inclusion.

Step 1: Include the SDK

Embed the following <script> tag into the <head> or before the closing </body> tag of your checkout page.

<script src="https://browser.myanmyanpay.com/v1/sdk.js"></script>

Step 2: Set up the Payment Container

Create a simple HTML element where the SDK will render the payment-specific UI (the QR code and redirect link).

<div id="mmpay-checkout-widget"> </div>

🚀 Usage

The MMQRMerchant class provides two distinct methods to suit different integration needs.

1. showPaymentModal() (Recommended: UI + Polling)

This is the easiest way to integrate. This method initiates the transaction, renders the UI (QR code/Redirect link) into your container, and automatically polls your gateway for payment completion status, executing a callback when the payment is final.

Method Signature

showPaymentModal(
    containerId: string,
    paymentData: PaymentData,
    onComplete: (result: PaymentResult) => void
): Promise<void>

Example Implementation

document.getElementById('place-order-button').addEventListener('click', () => {
    const MMPay = new MMPaySDK('pk_live_YOUR_PUBLISHABLE_KEY');
    const paymentDetails = {
        amount: 50000,
        orderId: 'ORD-' + new Date().getTime(),
        callbackUrl: 'https://your-merchant-site.com/payment-confirmation' // Redirect URL after mobile payment
    };
    MMPay.showPaymentModal(
        'mmpay-checkout-widget', // ID of the container element
        paymentDetails,
        (result) => {
            // This callback fires ONLY after the payment is completed, failed, or expired.
            if (result.success) {
                console.log(`Payment confirmed! Transaction ID: ${result.transactionId}`);
                // Redirect user to the success page
                window.location.href = `/thank-you?txn=${result.transactionId}`;
            } else {
                console.error(`Payment failed: ${result.message}`);
                // Update the UI to show the failure message
                document.getElementById('mmpay-checkout-widget').innerHTML = `Payment failed: ${result.message}`;
            }
        }
    );
});

2. createPaymentRequest() (Advanced: JSON Only)

Use this method if you need to build a fully custom user interface or if you are only initiating the request from the client and handling polling/UI on your server. This method returns the raw QR/Redirect URLs in JSON format.

Method Signature

createPaymentRequest(paymentData: PaymentData): Promise<CreatePaymentResponse>

Example Implementation

document.getElementById('get-qr-data').addEventListener('click', async () => {
    const Supa = new MMQRMerchant('pk_live_YOUR_PUBLISHABLE_KEY');
    const paymentDetails = {
        amount: 100.00,
        currency: 'USD',
        orderId: 'CUST-API-' + Date.now()
    };
    try {
        const response = await Supa.createPaymentRequest(paymentDetails);

        if (response.success) {
            console.log('Transaction initiated:', response.transactionId);
            console.log('QR Code URL:', response.qrCodeUrl);
            // Use response.qrCodeUrl and response.redirectUrl to build your custom UI
        } else {
            console.error('Initiation failed:', response.error);
        }
    } catch (error) {
        console.error("API call error:", error);
    }
});

🧪 Testing and Environments

The SDK supports easy and secure switching between Sandbox (Test) and Production (Live) environments.

Environment Configuration

The environment is set during SDK initialization using the options object. | Option | Value | API Base URL | Key Type | Purpose | | :--- | :--- | :--- | :--- | :--- | | environment | 'production' (Default) | https://api.Supa.com/v1 | pk_live_... | Live transactions with real money. | | environment | 'sandbox' | https://sandbox.api.Supa.com/v1 | pk_test_... | Testing and development (no money exchanged). |

Example: Sandbox Initialization

Always use Sandbox Mode with your Test Publishable Key (pk_test_...) for development.

// Test key and environment must match!
const SupaTest = new MMQRMerchant('pk_test_XYZ789', {
    environment: 'sandbox', // <-- Activates the test API URL
    pollInterval: 2000      // Optional: change polling frequency (default is 3000ms)
});

// Now call methods on the test instance
SupaTest.showPaymentModal(/* ... */);

🧑‍💻 Development & Contribution

If you are modifying the SDK code itself (MMQRMerchant.ts), use the following commands.

Dependencies

Ensure you have Node.js and TypeScript installed globally or locally:

npm install typescript --save-dev

Build Command

Use the defined script to compile the TypeScript source into the final JavaScript file for distribution.

npm run build

This command cleans the old output and compiles MMQRMerchant.ts into dist/MMQRMerchant.js.