Skip to content

making version a setting that is configured in mpesa.php #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/mpesa.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Default Version
|--------------------------------------------------------------------------
|
| This is the default version to be used when calling safaricom.
*/

'version' => 'v1',
/*
|--------------------------------------------------------------------------
| Default Account
Expand Down
2 changes: 1 addition & 1 deletion src/Mpesa/Auth/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function authenticate()
private function makeRequest($key, $secret)
{
$credentials = base64_encode($key . ':' . $secret);
$endpoint = $this->core->configRepository()->url(Endpoint::MPESA_AUTH);
$endpoint = $this->core->configRepository()->url(Endpoint::getEndpoint(Endpoint::MPESA_AUTH));

return $this->core->client()->request('GET', $endpoint, [
'headers' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Mpesa/C2B/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function validate($number, $callback = null)
try {
$response = $this->clientRequest(
$body,
$this->core->configRepository()->url(Endpoint::MPESA_ID_CHECK)
$this->core->configRepository()->url(Endpoint::getEndpoint(Endpoint::MPESA_ID_CHECK))
);

return json_decode($response->getBody());
Expand Down
2 changes: 1 addition & 1 deletion src/Mpesa/C2B/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function submit($shortCode = null, $confirmationURL = null, $validationUR
try {
$response = $this->clientRequest(
$body,
$this->core->configRepository()->url(Endpoint::MPESA_REGISTER)
$this->core->configRepository()->url(Endpoint::getEndpoint(Endpoint::MPESA_REGISTER))
);

return json_decode($response->getBody());
Expand Down
4 changes: 2 additions & 2 deletions src/Mpesa/C2B/STK.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function push($amount = null, $number = null, $reference = null, $descrip
try {
$response = $this->clientRequest(
$body,
$this->core->configRepository()->url(Endpoint::MPESA_LNMO)
$this->core->configRepository()->url(Endpoint::getEndpoint(Endpoint::MPESA_LNMO))
);

return json_decode($response->getBody());
Expand Down Expand Up @@ -278,7 +278,7 @@ public function validate($checkoutRequestID, $account = null)
try {
$response = $this->clientRequest(
$body,
$this->core->configRepository()->url(Endpoint::MPESA_LNMO_VALIDATE)
$this->core->configRepository()->url(Endpoint::getEndpoint(Endpoint::MPESA_LNMO_VALIDATE))
);

return json_decode($response->getBody());
Expand Down
2 changes: 1 addition & 1 deletion src/Mpesa/C2B/Simulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function push($amount = null, $number = null, $reference = null, $account
try {
$response = $this->clientRequest(
$body,
$this->core->configRepository()->url(Endpoint::MPESA_SIMULATE)
$this->core->configRepository()->url(Endpoint::getEndpoint(Endpoint::MPESA_SIMULATE))
);

return json_decode($response->getBody());
Expand Down
23 changes: 17 additions & 6 deletions src/Mpesa/Repositories/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@

class Endpoint
{
public const MPESA_AUTH = 'oauth/v1/generate?grant_type=client_credentials';
public const MPESA_AUTH = 'oauth/:version/generate?grant_type=client_credentials';

public const MPESA_ID_CHECK = 'mpesa/checkidentity/v1/processrequest';
public const MPESA_ID_CHECK = 'mpesa/checkidentity/:version/processrequest';

public const MPESA_REGISTER = 'mpesa/c2b/v2/registerurl';
public const MPESA_REGISTER = 'mpesa/c2b/:version/registerurl';

public const MPESA_SIMULATE = 'mpesa/c2b/v2/simulate';
public const MPESA_SIMULATE = 'mpesa/c2b/:version/simulate';

public const MPESA_LNMO = 'mpesa/stkpush/v1/processrequest';
public const MPESA_LNMO = 'mpesa/stkpush/:version/processrequest';

public const MPESA_LNMO_VALIDATE = 'mpesa/stkpushquery/v1/query';
public const MPESA_LNMO_VALIDATE = 'mpesa/stkpushquery/:version/query';

public const CUSTOMER_PAYBILL_ONLINE = 'CustomerPayBillOnline';

public const CUSTOMER_BUYGOODS_ONLINE = 'CustomerBuyGoodsOnline';

public static function getVersion()
{
return config('mpesa.version', 'v1');
}

public static function getEndpoint($endpoint)
{
$version = self::getVersion();
return str_replace(':version', $version, $endpoint);
}
}