Skip to content

Helper Functions

Mauko Maunde edited this page Jan 8, 2021 · 1 revision

You can use the helper functions for more concise code

To configure the class, use the mpesa_setup_config function , passing your configuration options as the first argument, and the API you wish to setup(C2B, C2B, B2C, B2B) as the second argument. The API is set to C2B by default.

$config = array(
    "env"               => "sandbox",
    "type"              => 4, // For Paybill, or, 2 for Till, 1	for MSISDN
    "shortcode"         => "174379",
    "headoffice"        => "174379",
    "key"               => "Your Consumer Key",
    "secret"            => "Your Consumer Secret",
    "username"          => "",
    "passkey"           => "Your Online Passkey",
    "validation_url"    => "api/lipwa/validate",
    "confirmation_url"  => "api/lipwa/confirm",
    "callback_url"      => "api/lipwa/reconcile",
    "results_url"       => "api/lipwa/results",
);
mpesa_setup_config($config, "C2B");

Optionally, you could configure with the mpesa_setup_* function s

mpesa_setup_stk($config);
mpesa_setup_c2b($config);
mpesa_setup_b2c($config);
mpesa_setup_b2b($config);

To make a C2B Prompt request, pass the user"s phone number, the amount due, and an optional reference(shows up on the user"s phone) respectively

mpesa_stk_push($phone, $amount, $reference);

To simulate a c2b transaction, call the function as follows, passing the user"s phone number, the amount due, and an optional reference respectively

mpesa_c2b_request($phone, $amount, $reference);

To send funds to a client

mpesa_b2c_request();

Transfer funds between one business to another

mpesa_b2b_request();

Validate Or Confirm Transaction Details. Call this function at your validation/confirmation endpoint.

mpesa_validate();
mpesa_confirm()
Clone this wiki locally