Skip to content

Commit

Permalink
Merge pull request #16 from Iankumu/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Iankumu authored May 17, 2024
2 parents 130ba6e + 99d0009 commit cd9dd65
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 37 deletions.
48 changes: 32 additions & 16 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ If you `have not` registered a `callback_url` in the `config/mpesa.php` file, yo
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::stkpush('0707070707', 100, '12345');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand All @@ -61,7 +62,8 @@ OR
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::stkpush('0707070707', 100, '12345','https://test.test/callback');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand Down Expand Up @@ -125,7 +127,8 @@ This API enables you to query the status of STKPUSH payment. This is useful of y
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::stkquery($checkoutRequestId);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;

```
Expand Down Expand Up @@ -153,7 +156,8 @@ This API enables you to register the callback URLs through which you can receive
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::c2bregisterURLS($shortcode);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand All @@ -164,7 +168,8 @@ You can now call the `c2bregisterURLS()` method on `Mpesa` facade and pass a sho
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::c2bregisterURLS(600998);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand Down Expand Up @@ -194,7 +199,8 @@ To simulate you need to pass these parameters to `c2bsimulate` method.
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::c2bsimulate($phonenumber, $amount, $shortcode, $command_id, $account_number = NULL);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand Down Expand Up @@ -225,15 +231,17 @@ To use this API you need to call `b2c()` method on the `Mpesa` facade. This func
use Iankumu\Mpesa\Facades\Mpesa;
$response =Mpesa::b2c($phonenumber, $command_id, $amount, $remarks);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

```php
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::b2c('0708374149','SalaryPayment',1000,'salary payment');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand All @@ -244,7 +252,8 @@ If the ID provided does not match the phone number on Safaricom Database, the tr
use Iankumu\Mpesa\Facades\Mpesa;
$response=Mpesa::validated_b2c('0708374149','SalaryPayment',1000,'salary payment','12345678');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand Down Expand Up @@ -333,15 +342,17 @@ To use this API you need to call `transactionStatus()` method on the `Mpesa` fac
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::transactionStatus($shortcode, $transactionid, $identiertype, $remarks);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

```php
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::transactionStatus('600999', 'OEI2AK4Q16', 4, 'Check transaction status');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand Down Expand Up @@ -447,15 +458,17 @@ To use this API you need to call `accountBalance()` method on the `Mpesa` facade
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::accountBalance($shortcode, $identiertype, $remarks);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

```php
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::accountBalance('600983', 4, 'check account balance');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand All @@ -476,15 +489,17 @@ To use this API you need to call `reversal()` method on the `Mpesa` facade. This
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::reversal($shortcode, $transactionid, $amount, $remarks);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

```php
use Iankumu\Mpesa\Facades\Mpesa;
$response = Mpesa::reversal('600981','OEI2AK4Q16', 500, 'Wrong Payment');

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```

Expand All @@ -507,6 +522,7 @@ use Iankumu\Mpesa\Facades\Mpesa;

$response = Mpesa::b2b($receiver_shortcode, $command_id, $amount, $remarks, $account_number = null);

$result = json_decode((string)$response);
/** @var \Illuminate\Http\Client\Response $response */
$result = $response->json();
return $result;
```
11 changes: 7 additions & 4 deletions tests/Unit/B2BTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Http;

test('that b2b will throw an exception when the callbacks are null', function () {
(new Mpesa())->b2b('403043','BusinessPayBill',100,'test','test');
(new Mpesa())->b2b('403043', 'BusinessPayBill', 100, 'test', 'test');
})->expectException(CallbackException::class);

it('can initiate b2b', function () {
Expand All @@ -24,9 +24,12 @@
]);

$mpesa = new Mpesa();
$response = $mpesa->b2b('403043','BusinessPayBill',100,'test','test');
$response = $mpesa->b2b('403043', 'BusinessPayBill', 100, 'test', 'test');

// $result = json_decode($response->body(), true);
$result = $response->json();

expect($response->status())->toBe(200);
$result = json_decode($response->body(), true);
expect($result)->toHaveKeys(['ResponseCode', 'ResponseDescription', 'ConversationID', 'OriginatorConversationID', 'TransactionID']);
expect($result['ResponseCode'])->toBe('0');
});
});
5 changes: 2 additions & 3 deletions tests/Unit/B2CTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

$response = $mpesa->b2c('0707070707', 'SalaryPayment', 100, 'Salary Payment');

$recorded = Http::recorded();
// $result = json_decode($response->body(), true);

[$request, $response] = $recorded[0];
$result = json_decode($response->body(), true);
$result = $response->json();

expect($response->status())->toBe(200);
expect($result)->toBe($expectedResponse);
Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/C2BRegisterURLSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

$response = $mpesa->c2bregisterURLS(12345);

$recorded = Http::recorded();

[$request, $response] = $recorded[0];
$result = json_decode($response->body(), true);
// $result = json_decode($response->body(), true);
$result = $response->json();

expect($response->status())->toBe(200);
expect($result)->toBe($expectedResponse);
Expand Down
8 changes: 2 additions & 6 deletions tests/Unit/MpesaSTKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@

$response = $mpesa->stkpush('0707070707', 100, 12345, 'https://test.test/callback');

$recorded = Http::recorded();

[$request, $response] = $recorded[0];
$result = json_decode($response->body(), true);
// $result = json_decode($response->body(), true);
$result = $response->json();

expect($response->status())->toBe(200);
expect($result)->toBe($expectedResponse);
Expand All @@ -53,9 +52,6 @@

$response = $mpesa->stkquery('ws_CO_191220191020363925');

$recorded = Http::recorded();

[$request, $response] = $recorded[0];
$result = json_decode($response->body(), true);

expect($response->status())->toBe(200);
Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/ValidatedB2CTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@

$response = $mpesa->validated_b2c('0707070707', 'SalaryPayment', 100, 'Salary Payment', '120912992');

$recorded = Http::recorded();

[$request, $response] = $recorded[0];
$result = json_decode($response->body(), true);
// $result = json_decode($response->body(), true);
$result = $response->json();

expect($response->status())->toBe(200);
expect($result)->toBe($expectedResponse);
Expand Down

0 comments on commit cd9dd65

Please sign in to comment.