Skip to content

Commit

Permalink
refactor(payment): update code base
Browse files Browse the repository at this point in the history
  • Loading branch information
papac committed Sep 11, 2020
1 parent 1623445 commit 463e5f9
Show file tree
Hide file tree
Showing 17 changed files with 348 additions and 36 deletions.
28 changes: 28 additions & 0 deletions config/payment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
<?php

return [
/**
* Define the model used my gateway
*/
'model' => \App\Models\User::class,

/**
* The default gateway
*/
'default' => 'orange_ci',

/**
* List of available gateway
*/
'gateways' => [
'orange_ci' => [
'client_key' => '',
'merchant_key' => ''
],

'mtn_ci' => [
'client_key' => '',
'merchant_key' => ''
],

'moov_ci' => [
'client_key' => '',
'merchant_key' => ''
]
]
];
40 changes: 40 additions & 0 deletions src/Bowcasher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Bow\Payment;

use Bow\Payment\Common\PaymentManagerContract;
use BowcasherOrangeMoneyService;

class Bowcasher
{
/**
* Instance of
*
* @var PaymentManagerContract
*/
private static $instance;

/**
* Make configuration
*
* @return PaymentManagerContract
*/
public static function configure($config)
{
static::$instance = new BowcasherOrangeMoneyService($config['gateways']['orange_ci']);
}

/**
* __callStatic
*
* @param string $name
* @param array $arguments
* @return mixed
*/
public static function __callStatic($name, $arguments)
{
if (method_exists(static::$instance, $name)) {
return call_user_func_array([static::$instance, $name], $arguments);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Bow\Configuration\Configuration;
use Bow\Configuration\Loader as Config;

class PaymmentConfirguration extends Configuration
class BowcasherConfiguration extends Configuration
{
/**
* Create payment configuration
Expand All @@ -21,7 +21,7 @@ public function create(Config $config)
$config['payment'] = $payment;

$this->container->make('payment', function ($config) {
return Pay::configure($config['payment']);
return Bowcasher::configure($config['payment']);
});
}

Expand Down
61 changes: 61 additions & 0 deletions src/Common/PaymentManagerContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Bow\Payment\Common;

abstract class PaymentManagerContract
{
const PRODUCTION = 'production';
const DEVELOPMENT = 'development';

/**
* Define the payment mode
*
* @var string
*/
protected $environment = PaymentManagerContract::DEVELOPMENT;

/**
* Make pay
*
* @return mixed
*/
abstract public function pay(...$args);

/**
* Verify payment
*
* @return void
*/
abstract public function verify();

/**
* Switch to production mode
*
* @return string
*/
public function switchToProduction()
{
$this->environment = PaymentManagerContract::PRODUCTION;
}

/**
* Switch to development mode
*
* @return string
*/
public function switchToDevelopment()
{
$this->environment = PaymentManagerContract::DEVELOPMENT;
}

/**
* Get the payment environment
*
* @param string $environment
* @return string
*/
public function getEnvironment()
{
return $this->environment;
}
}
10 changes: 5 additions & 5 deletions src/Common/PaymentToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class PaymentToken
* @var int
*/
private $expires_in;

/**
* Define the realy time for token expiration
* Define the really time for token expiration
*
* @var int
*/
private $expires_realy_in;
private $expires_really_in;

/**
* PaymentToken constructor
Expand All @@ -47,7 +47,7 @@ public function __construct(string $access_token, string $token_type, int $expir

$this->expires_in = $expires_in;

$this->expires_realy_in = (time() + $expires_in) - 5;
$this->expires_really_in = (time() + $expires_in) - 5;
}

/**
Expand Down Expand Up @@ -97,6 +97,6 @@ public function getExpiresIn()
*/
public function hasExpired()
{
return $this->expires_realy_in - time() <= 0;
return $this->expires_really_in - time() <= 0;
}
}
40 changes: 40 additions & 0 deletions src/Common/TokenGeneratorContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Bow\Payment\Common;

use Bow\Payment\Common\PaymentToken;

interface TokenGeneratorContract
{
/**
* Get payment token
*
* @return PaymentToken
*/
public function getToken();

/**
* Set the get token url
*
* @deprecated
* @param string $url
* @return mixed
*/
public function setUrl(string $url);

/**
* Set the get token url
*
* @param string $url
* @return mixed
*/
public function setTokenGeneratorEndpoint(string $url);

/**
* Set credentials
*
* @param mixed $credentials
* @return mixed
*/
public function setCredentials($credentials);
}
48 changes: 48 additions & 0 deletions src/Common/TransactionStatusContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Bow\Payment\Common;

interface TransactionStatusContract
{
/**
* Get the notification token
*
* @return string
*/
public function getNotificationToken();

/**
* Define if transaction fail
*
* @return bool
*/
public function fail();

/**
* Define if transaction initiated
*
* @return bool
*/
public function initiated();

/**
* Define if transaction expired
*
* @return bool
*/
public function expired();

/**
* Define if transaction success
*
* @return bool
*/
public function success();

/**
* Define if transaction pending
*
* @return bool
*/
public function pending();
}
2 changes: 1 addition & 1 deletion src/MTNMobileMoney/Collection/MomoPaymentStatus.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bow\Payment\MTNMobileMoney\Collection
namespace Bow\Payment\MTNMobileMoney\Collection;

class MomoPaymentStatus
{
Expand Down
4 changes: 2 additions & 2 deletions src/MTNMobileMoney/MomoEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MomoEnvironment
* @param string $subscription_key
* @return void
*/
public function __construct(string $subscription_key. string $basic_auth)
public function __construct(string $subscription_key, string $basic_auth)
{
$this->subscription_key = $subscription_key;
$this->basic_auth = $basic_auth;
Expand Down Expand Up @@ -111,7 +111,7 @@ public function getBaseUri()
*
* @return array
*/
public function getAuthorzition()
public function getAuthorization()
{
return [
'Authorization' => 'Basic ' . $this->basic_auth,
Expand Down
Loading

0 comments on commit 463e5f9

Please sign in to comment.