Skip to content

Commit

Permalink
More xomprehensive Example Controller for B2C
Browse files Browse the repository at this point in the history
  • Loading branch information
maukoese committed Jan 8, 2021
1 parent b3e9fcd commit 82a5fb8
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 96 deletions.
12 changes: 6 additions & 6 deletions LARAVEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ C2B::init(
"key" => "Your Consumer Key",
"secret" => "Your Consumer Secret",
"passkey" => "Your Online Passkey",
"validation_url" => url("lipwa/validate"),
"confirmation_url" => url("lipwa/confirm"),
"callback_url" => url("lipwa/reconcile"),
"results_url" => url("lipwa/results"),
"timeout_url" => url("lipwa/timeout"),
"validation_url" => url("api/lipwa/validate"),
"confirmation_url" => url("api/lipwa/confirm"),
"callback_url" => url("api/lipwa/reconcile"),
"results_url" => url("api/lipwa/results"),
"timeout_url" => url("api/lipwa/timeout"),
)
);
```
Expand All @@ -56,6 +56,6 @@ Route::prefix("lipwa")->group(function ()
```

### CSRF verification
Remember to add `lipwa/*` to the `$except` array in `app/Http/Middleware/VerifyCsrfToken.php` to whitelist your endpoints so they can receive data from M-PESA.
Remember to add `api/lipwa/*` to the `$except` array in `app/Http/Middleware/VerifyCsrfToken.php` to whitelist your endpoints so they can receive data from M-PESA.

See [the README](README.md) for making and processing payment requests.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ C2B::init(
"username" => "", // Required for B2B and B2C APIs only
"password" => "", // Required for B2B and B2C APIs only
"passkey" => "Your Online Passkey",
"validation_url" => "lipwa/validate",
"confirmation_url" => "lipwa/confirm",
"callback_url" => "lipwa/reconcile",
"results_url" => "lipwa/results")
"validation_url" => "api/lipwa/validate",
"confirmation_url" => "api/lipwa/confirm",
"callback_url" => "api/lipwa/reconcile",
"results_url" => "api/lipwa/results")
)
);
```
Expand All @@ -100,10 +100,10 @@ C2B::init(
```php
C2B::init(
array(
"validation_url" => "lipwa/validate",
"confirmation_url" => "lipwa/confirm",
"callback_url" => "lipwa/reconcile",
"results_url" => "lipwa/results")
"validation_url" => "api/lipwa/validate",
"confirmation_url" => "api/lipwa/confirm",
"callback_url" => "api/lipwa/reconcile",
"results_url" => "api/lipwa/results")
)
);
```
Expand Down Expand Up @@ -173,7 +173,9 @@ Whenever M-Pesa receives a transaction on your shortcode, a validation request i
These URLs must be HTTPS in production. Validation is an optional feature that needs to be activated on M-Pesa, the owner of the shortcode needs to make this request for activation. This can be done by sending an email to [[email protected]](mailto:[email protected]), or through a chat on the [developer portal](https://developer.safaricom.co.ke).

#### Register Validation/Confirmation URLs
Simply call the `register` method of the `C2B` class, optionally passing a callback function to process the response from M-PESA. If no callback URL is supplied, the method will return an array of the response from M-PESA.
Simply call the `register` method of the `C2B` class, optionally passing a callback function to process the response from M-PESA. If no callback URL is supplied, the method will return an array of the response from M-PESA.

You can pass an optional second parameter for the response type. This defaults to `Completed`

```php
C2B::register();
Expand Down Expand Up @@ -245,9 +247,6 @@ C2B::confirm(function ($response){
});
```

See [the README](README.md) for making and processing other payment requests.


### Processing Timeouts

When a valid M-Pesa API request is received by the API Gateway, it is sent to M-Pesa where it is added to a queue. M-Pesa then processes the requests in the queue and sends a response to the API Gateway which then forwards the response to the URL registered in the CallBackURL or ResultURL request parameter. Whenever M-Pesa receives more requests than the queue can handle, M-Pesa responds by rejecting any more requests and the API Gateway sends a queue timeout response to the URL registered in the QueueTimeOutURL request parameter. Use the `timeout()` method to process this response.
Expand Down Expand Up @@ -471,7 +470,7 @@ C2B::result(function ($response){

## Helper Functions

You can use the helper function s for more concise code
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.

Expand All @@ -480,15 +479,15 @@ $config = array(
"env" => "sandbox",
"type" => 4, // For Paybill, or, 2 for Till, 1 for MSISDN
"shortcode" => "174379",
"headoffice" => "174379",
"headoffice" => "174379",
"key" => "Your Consumer Key",
"secret" => "Your Consumer Secret",
"username" => "",
"passkey" => "Your Online Passkey",
"validation_url" => "lipwa/validate",
"confirmation_url" => "lipwa/confirm",
"callback_url" => "lipwa/reconcile",
"results_url" => "lipwa/results",
"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");
```
Expand Down
Loading

0 comments on commit 82a5fb8

Please sign in to comment.