Skip to content

Lets you add a "Pay With Mpesa" button to your website

Notifications You must be signed in to change notification settings

muaad/mpesa_button

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mpesa Button Generator

This is a script that lets you add a "Pay With Mpesa" button to your site.

Image of Yaktocat

Usage

  • Insert the following snippet of code directly after the opening <body> tag on each page you want to load it:
<script>  
  (function(d, s, id){
     var js, mpesa = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://cdn.jsdelivr.net/gh/muaad/mpesa_button@master/src/button.min.js";
     mpesa.parentNode.insertBefore(js, mpesa);
   }(document, 'script', 'mpesa_btn_js'));
</script>

  • Add a <div> with an ID of mpesaButton where you want the button installed:
<div id='mpesaButton'></div>

You can specify a number of options for the button like prepopulating the amount and phone fields by providing data attributes for the button. For example:

<div id='mpesaButton' data-phone='254722XXXXXX' data-amount=3000 data-url='https://domain.com/mpesa/payments/request'></div>

The URL data attribute is the URL used to post the form values to. This is where you will send the payment request using the Mpesa API.

And, that is it!

About

Lets you add a "Pay With Mpesa" button to your website

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published