diff --git a/src/MTNMobileMoney/MomoToken.php b/src/Common/PaymentToken.php similarity index 85% rename from src/MTNMobileMoney/MomoToken.php rename to src/Common/PaymentToken.php index 3cf289d..dd04924 100644 --- a/src/MTNMobileMoney/MomoToken.php +++ b/src/Common/PaymentToken.php @@ -1,39 +1,39 @@ subscription_key = $subscription_key; + $this->basic_auth = $basic_auth; } /** @@ -32,6 +40,16 @@ public function getSubscriptionKey() return $this->subscription_key; } + /** + * Get the basic authorization key + * + * @return string + */ + public function getBasicAuthorizationKey() + { + return $this->basic_auth; + } + /** * Check the environment * @@ -69,7 +87,7 @@ public function switchToSandbox() */ public function switchToProduction() { - $this->environment = 'sandbox'; + $this->environment = 'production'; } /** @@ -96,7 +114,7 @@ public function getBaseUri() public function getAuthorzition() { return [ - 'Authorization' => 'Basic ' . base64_encode('API URI and API Key'), + 'Authorization' => 'Basic ' . $this->basic_auth, 'Ocp-Apim-Subscription-Key' => $this->subscription_key, ]; } diff --git a/src/MTNMobileMoney/MonoTokenGenerator.php b/src/MTNMobileMoney/MonoTokenGenerator.php index 9f1d9b1..6144c7f 100644 --- a/src/MTNMobileMoney/MonoTokenGenerator.php +++ b/src/MTNMobileMoney/MonoTokenGenerator.php @@ -2,7 +2,8 @@ namespace Bow\Payment\MTMMobileMoney; -use \GuzzleHttp\Client as HttpClient; +use Bow\Payment\Common\PaymentToken as MomoToken; +use GuzzleHttp\Client as HttpClient; class MomoEnvironment { diff --git a/src/OrangeMoney/OrangeMoneyEnvironment.php b/src/OrangeMoney/OrangeMoneyEnvironment.php deleted file mode 100644 index 495105e..0000000 --- a/src/OrangeMoney/OrangeMoneyEnvironment.php +++ /dev/null @@ -1,99 +0,0 @@ -transation_status_endpoint = $endpoint; - } - - /** - * Set the token generator endpoint - * - * @param string $endpoint - * @return void - */ - public function setTokenGeneratorEndpoint(string $endpoint) - { - $this->token_generator_endpoint = $endpoint; - } - - /** - * Set the payment endpoint - * - * @param string $endpoint - * @return void - */ - public function setPaymentEndpoint(string $endpoint) - { - $this->payment_endpoint = $endpoint; - } - - /** - * Get the token generator - * - * @return string - */ - public function getTokenGeneratorEndpoint() - { - return trim($this->base_url, '/') .'/'. trim($this->token_generator_endpoint, '/'); - } - - /** - * Get the transaction status endpoint - * - * @return string - */ - public function getTransactionStatusEndpoint() - { - return trim($this->base_url, '/') .'/'. trim($this->transation_status_endpoint, '/'); - } - - /** - * Get the payment endpoint - * - * @return string - */ - public function getPaymentEndpoint() - { - return trim($this->base_url, '/') .'/'. trim($this->payment_endpoint, '/'); - } -} diff --git a/src/OrangeMoney/OrangeMoneyPayment.php b/src/OrangeMoney/OrangeMoneyPayment.php index 6768a81..bae1e32 100644 --- a/src/OrangeMoney/OrangeMoneyPayment.php +++ b/src/OrangeMoney/OrangeMoneyPayment.php @@ -2,6 +2,7 @@ namespace Bow\Payment\OrangeMoney; +use Bow\Payment\Common\PaymentToken as OrangeMoneyToken; use \GuzzleHttp\Client as HttpClient; class OrangeMoneyPayment @@ -60,9 +61,10 @@ class OrangeMoneyPayment * * @param OrangeMoneyToken $token * @param string $merchant_key + * @param string $currency * @return mixed */ - public function __construct(OrangeMoneyToken $token, $merchant_key) + public function __construct(OrangeMoneyToken $token, $merchant_key, string $currency = 'OUV') { $this->token = $token; @@ -70,9 +72,9 @@ public function __construct(OrangeMoneyToken $token, $merchant_key) $this->merchant_key = $merchant_key; - $this->currency = 'OUV'; + $this->currency = $currency; } - + /** * Make payment * diff --git a/src/OrangeMoney/OrangeMoneyToken.php b/src/OrangeMoney/OrangeMoneyToken.php deleted file mode 100644 index f885852..0000000 --- a/src/OrangeMoney/OrangeMoneyToken.php +++ /dev/null @@ -1,102 +0,0 @@ -access_token = $access_token; - - $this->token_type = $token_type; - - $this->expires_in = $expires_in; - - $this->expires_realy_in = (time() + $expires_in) - 5; - } - - /** - * __toString - * - * @var string - */ - public function __toString() - { - return $this->token_type . ' ' . $this->access_token; - } - - /** - * Get the access token - * - * @return string - */ - public function getAccessToken() - { - return $this->access_token; - } - - /** - * Get the token type - * - * @return string - */ - public function getType() - { - return $this->token_type; - } - - /** - * Get the expiration time - * - * @return int - */ - public function getExpiresIn() - { - return $this->expires_in; - } - - /** - * Get the expiration time - * - * @return string - */ - public function hasExpired() - { - return $this->expires_realy_in - time() <= 0; - } -} diff --git a/src/OrangeMoney/OrangeMoneyTokenGenerator.php b/src/OrangeMoney/OrangeMoneyTokenGenerator.php index 9f7b53c..554cadf 100644 --- a/src/OrangeMoney/OrangeMoneyTokenGenerator.php +++ b/src/OrangeMoney/OrangeMoneyTokenGenerator.php @@ -2,6 +2,7 @@ namespace Bow\Payment\OrangeMoney; +use Bow\Payment\Common\PaymentToken as OrangeMoneyToken; use \GuzzleHttp\Client as HttpClient; class OrangeMoneyTokenGenerator diff --git a/src/OrangeMoney/OrangeMoneyTransaction.php b/src/OrangeMoney/OrangeMoneyTransaction.php index 372e255..9014e2d 100644 --- a/src/OrangeMoney/OrangeMoneyTransaction.php +++ b/src/OrangeMoney/OrangeMoneyTransaction.php @@ -2,6 +2,7 @@ namespace Bow\Payment\OrangeMoney; +use Bow\Payment\Common\PaymentToken as OrangeMoneyToken; use \GuzzleHttp\Client as HttpClient; class OrangeMoneyTransaction diff --git a/src/OrangeMoney/OrangeMoneyTransactionStatus.php b/src/OrangeMoney/OrangeMoneyTransactionStatus.php index ba23caf..015ab65 100644 --- a/src/OrangeMoney/OrangeMoneyTransactionStatus.php +++ b/src/OrangeMoney/OrangeMoneyTransactionStatus.php @@ -51,6 +51,26 @@ public function fail() return $this->status == 'FAIL'; } + /** + * Define if transaction initiated + * + * @return bool + */ + public function initiated() + { + return $this->status == 'INITIATED'; + } + + /** + * Define if transaction expired + * + * @return bool + */ + public function expired() + { + return $this->status == 'EXPIRED'; + } + /** * Define if transaction success * diff --git a/tests/OrangeMoneyTest.php b/tests/OrangeMoneyTest.php index f1c74d6..4f20d36 100644 --- a/tests/OrangeMoneyTest.php +++ b/tests/OrangeMoneyTest.php @@ -2,7 +2,7 @@ use Bow\Payment\OrangeMoney\OrangeMoney; use Bow\Payment\OrangeMoney\OrangeMoneyPayment; -use Bow\Payment\OrangeMoney\OrangeMoneyToken; +use Bow\Payment\Common\PaymentToken as OrangeMoneyToken; use Bow\Payment\OrangeMoney\OrangeMoneyTokenGenerator; class OrangeMoneyTest extends \PHPUnit\Framework\TestCase @@ -17,7 +17,7 @@ public function testGetToken() $this->assertInstanceOf(OrangeMoneyToken::class, $stub->getToken()); } - public function testMakePayment() + public function testPreparePayment() { $token = $this->getMockBuilder(OrangeMoneyToken::class) ->disableOriginalConstructor()->getMock(); @@ -27,9 +27,18 @@ public function testMakePayment() ->setMethods(['prepare'])->getMock(); $payment_status = $this->createMock(OrangeMoney::class); - $payment->method('prepare') - ->willReturn($payment_status); + $payment->method('prepare')->willReturn($payment_status); $this->assertInstanceOf(OrangeMoney::class, $payment->prepare(500, 'reference', 1)); } + + public function testMakePayment() + { + $orange = $this->getMockBuilder(OrangeMoney::class) + ->disableOriginalConstructor()->setMethods(['pay'])->getMock(); + + $orange->method('pay')->willReturn(true); + + $this->assertTrue($orange->pay()); + } }