HashPay Button

Accept M-PESA payments with one line of JavaScript.


…or a form-free button — just add class="hashpay-button" and data-attributes. Click it: a loader shows, then the M-PESA modal pops up.

Integration

Drop this into any page — the merchant only ever exposes their public account_id.

<script src="https://pay.hashback.co.ke/hashpay.js"></script>

<button id="pay">Pay KES 100</button>
<script>
  var handler = HashPay.setup({
    account:   'HP945692',      // your public account id
    amount:    100,             // KES
    reference: 'order_12345',   // optional
    onSuccess: function (txn) {
      alert('Paid! Receipt: ' + txn.receipt);
    },
    onCancel:  function () { console.log('closed'); },
    onError:   function (e) { console.error(e); }
  });
  document.getElementById('pay')
          .addEventListener('click', handler.openIframe);
</script>

Or zero JS — just data-attributes:

<button class="hashpay-button"
        data-account="HP945692"
        data-amount="100"
        data-reference="order_12345">Pay KES 100</button>

Already know the payer's number? Embed it with data-phone — the popup opens with the field filled in, so on mobile they just tap Pay. Add data-phone-lock to make it read-only.

<button class="hashpay-button"
        data-account="HP945692"
        data-amount="100"
        data-phone="0712345678"
        data-phone-lock>Pay KES 100</button>

0712345678, +254712345678, 254 712 345 678 and 712345678 are all accepted; an invalid value is ignored and the payer types their own.