M-Pesa payment button for any website

JMSURF PAY guide · updated 21 November 2026

One line on any website shows a Pay with M-Pesa button. It opens your JMSURF PAY payment link in a window on your page, so the customer pays without leaving your site. It works on plain HTML sites and on site builders that let you paste HTML.

Set it up

  1. 1Make a payment link. In the dashboard open Payment links, New and pick the channel the money goes to. Leave the amount empty if each order has its own amount.
  2. 2Copy the snippet. Open Developers, Integrations, Website payment button and pick the link. The snippet is ready to paste.
  3. 3Paste it. Put the snippet where the button should show. The button appears right after it.

HTML

<script src="https://jmsurfpay.co.ke/button.js"
        data-link="PAYMENT_LINK_CODE"
        data-amount="1500"
        data-reference="ORDER1001"
        data-label="Pay with M-Pesa"
        async></script>

Options

AttributeWhat it does
data-linkRequired. The payment link code, the part after /pay/.
data-amountOptional. Whole shillings, for links without a fixed amount.
data-referenceOptional. Your order number: letters, digits and dashes, up to 12. It is saved on the payment and sent in webhooks.
data-labelOptional. The button text.
data-modeOptional. modal (the default) or popup.
data-callbackOptional. The name of a function on your page, called with each event.

Know when it is paid

The button tells your page what happened with browser events:

JavaScript

document.addEventListener("jmsurfpay:success", function (e) {
  // e.detail: { status, amount, reference, mpesaReceiptNumber, checkoutRequestId }
  showThankYou(e.detail.reference);
});
document.addEventListener("jmsurfpay:failed", function (e) { /* e.detail.message */ });
document.addEventListener("jmsurfpay:close", function () { /* the window was closed */ });

Confirm on your server

Only the public payment link is in the page, never a key. Use the browser event for the thank-you message. Before you release goods, confirm the payment with the payment.completed webhook on your server. It carries the same reference.

Start on the Free plan: 1 payment channel, up to KES 50,000 a month, test keys included. Questions? WhatsApp +254 712 504 593.

Read next

© 2026 JMSURF PAY. All rights reserved. · ODPC reg. no. 194-9812-26EBPowered by JMSURF TECHNOLOGIES LTD