diff --git a/config/mpesa.php b/config/mpesa.php index a341300..33beb77 100755 --- a/config/mpesa.php +++ b/config/mpesa.php @@ -1,6 +1,15 @@ 'v1', /* |-------------------------------------------------------------------------- | Default Account diff --git a/src/Mpesa/Auth/Authenticator.php b/src/Mpesa/Auth/Authenticator.php index 96cad4e..09266e5 100755 --- a/src/Mpesa/Auth/Authenticator.php +++ b/src/Mpesa/Auth/Authenticator.php @@ -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' => [ diff --git a/src/Mpesa/C2B/Identity.php b/src/Mpesa/C2B/Identity.php index e2e8919..295defe 100755 --- a/src/Mpesa/C2B/Identity.php +++ b/src/Mpesa/C2B/Identity.php @@ -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()); diff --git a/src/Mpesa/C2B/Registrar.php b/src/Mpesa/C2B/Registrar.php index d125648..f26274b 100755 --- a/src/Mpesa/C2B/Registrar.php +++ b/src/Mpesa/C2B/Registrar.php @@ -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()); diff --git a/src/Mpesa/C2B/STK.php b/src/Mpesa/C2B/STK.php index 2dca92c..bd73640 100755 --- a/src/Mpesa/C2B/STK.php +++ b/src/Mpesa/C2B/STK.php @@ -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()); @@ -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()); diff --git a/src/Mpesa/C2B/Simulate.php b/src/Mpesa/C2B/Simulate.php index 1ede8b4..ccba4a1 100755 --- a/src/Mpesa/C2B/Simulate.php +++ b/src/Mpesa/C2B/Simulate.php @@ -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()); diff --git a/src/Mpesa/Repositories/Endpoint.php b/src/Mpesa/Repositories/Endpoint.php index c4afba0..5daf9f8 100644 --- a/src/Mpesa/Repositories/Endpoint.php +++ b/src/Mpesa/Repositories/Endpoint.php @@ -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); + } }