From dbd04dee720f9b64f050785a372d573820c883cc Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Sun, 2 Feb 2025 17:45:47 +0000 Subject: [PATCH 1/2] refactoring --- src/Common/PaymentManagerContract.php | 7 +++--- src/Common/PaymentToken.php | 10 ++++---- src/MTNMobileMoney/MomoEnvironment.php | 25 +++++++------------ src/MTNMobileMoney/MonoTokenGenerator.php | 20 +-------------- .../BowcasherOrangeMoneyService.php | 2 +- src/OrangeMoney/OrangeMoney.php | 16 ++++++------ src/OrangeMoney/OrangeMoneyPayment.php | 22 +--------------- 7 files changed, 28 insertions(+), 74 deletions(-) diff --git a/src/Common/PaymentManagerContract.php b/src/Common/PaymentManagerContract.php index c91576a..fac04db 100644 --- a/src/Common/PaymentManagerContract.php +++ b/src/Common/PaymentManagerContract.php @@ -5,6 +5,7 @@ abstract class PaymentManagerContract { const PRODUCTION = 'production'; + const DEVELOPMENT = 'development'; /** @@ -33,7 +34,7 @@ abstract public function verify(); * * @return string */ - public function switchToProduction() + public function switchToProduction(): void { $this->environment = PaymentManagerContract::PRODUCTION; } @@ -43,7 +44,7 @@ public function switchToProduction() * * @return string */ - public function switchToDevelopment() + public function switchToDevelopment(): void { $this->environment = PaymentManagerContract::DEVELOPMENT; } @@ -54,7 +55,7 @@ public function switchToDevelopment() * @param string $environment * @return string */ - public function getEnvironment() + public function getEnvironment(): string { return $this->environment; } diff --git a/src/Common/PaymentToken.php b/src/Common/PaymentToken.php index 0b71e57..684f976 100644 --- a/src/Common/PaymentToken.php +++ b/src/Common/PaymentToken.php @@ -55,7 +55,7 @@ public function __construct(string $access_token, string $token_type, int $expir * * @var string */ - public function __toString() + public function __toString(): string { return $this->token_type . ' ' . $this->access_token; } @@ -65,7 +65,7 @@ public function __toString() * * @return string */ - public function getAccessToken() + public function getAccessToken(): string { return $this->access_token; } @@ -75,7 +75,7 @@ public function getAccessToken() * * @return string */ - public function getType() + public function getType(): string { return $this->token_type; } @@ -85,7 +85,7 @@ public function getType() * * @return int */ - public function getExpiresIn() + public function getExpiresIn(): int { return $this->expires_in; } @@ -95,7 +95,7 @@ public function getExpiresIn() * * @return string */ - public function hasExpired() + public function hasExpired(): bool { return $this->expires_really_in - time() <= 0; } diff --git a/src/MTNMobileMoney/MomoEnvironment.php b/src/MTNMobileMoney/MomoEnvironment.php index 72c73c9..e7ebc45 100644 --- a/src/MTNMobileMoney/MomoEnvironment.php +++ b/src/MTNMobileMoney/MomoEnvironment.php @@ -11,23 +11,16 @@ class MomoEnvironment */ private $environment = 'sandbox'; - /** - * Define the basic auth value - * - * @var string - */ - private $basic_auth; - /** * MomoEnvironment constructor * * @param string $subscription_key * @return void */ - public function __construct(string $subscription_key, string $basic_auth) - { - $this->subscription_key = $subscription_key; - $this->basic_auth = $basic_auth; + public function __construct( + private string $subscription_key, + private string $basic_auth + ) { } /** @@ -55,9 +48,9 @@ public function getBasicAuthorizationKey() * * @return bool */ - public function production() + public function production(): bool { - return $this->environment = 'production'; + return $this->environment == 'production'; } /** @@ -65,7 +58,7 @@ public function production() * * @return bool */ - public function sandbox() + public function sandbox(): bool { return $this->environment == 'sandbox'; } @@ -95,7 +88,7 @@ public function switchToProduction() * * @return string */ - public function getBaseUri() + public function getBaseUri(): string { if ($this->sandbox()) { $base_uri = 'https://sandbox.momodeveloper.mtn.com/v1_0/'; @@ -111,7 +104,7 @@ public function getBaseUri() * * @return array */ - public function getAuthorization() + public function getAuthorization(): array { return [ 'Authorization' => 'Basic ' . $this->basic_auth, diff --git a/src/MTNMobileMoney/MonoTokenGenerator.php b/src/MTNMobileMoney/MonoTokenGenerator.php index 6144c7f..db711e1 100644 --- a/src/MTNMobileMoney/MonoTokenGenerator.php +++ b/src/MTNMobileMoney/MonoTokenGenerator.php @@ -14,33 +14,15 @@ class MomoEnvironment */ private $http; - /** - * The environment system - * - * @var MomoEnvironment - */ - private $environment; - - /** - * The name of payment action interface - * - * @var string - */ - private $interface_name; - /** * MomoEnvironment constructor * * @param MomoEnvironment $environment * @return mixed */ - public function __construct(MomoEnvironment $environment, $interface_name = 'collection') + public function __construct(private MomoEnvironment $environment, private string $interface_name = 'collection') { - $this->environment = $environment; - $this->http = new HttpClient(['base_uri' => $this->environment->getBaseUri()]); - - $this->interface_name = $interface_name; } /** diff --git a/src/OrangeMoney/BowcasherOrangeMoneyService.php b/src/OrangeMoney/BowcasherOrangeMoneyService.php index b0cfc7f..581f824 100644 --- a/src/OrangeMoney/BowcasherOrangeMoneyService.php +++ b/src/OrangeMoney/BowcasherOrangeMoneyService.php @@ -56,7 +56,7 @@ public function pay(...$args) $orange = $payment->prepare($amount, $order_id, $reference); $payment_information = $orange->getPaymentInformation(); - // Redirect to payment plateforme + // Redirect to payment plateforme $orange->pay(); } diff --git a/src/OrangeMoney/OrangeMoney.php b/src/OrangeMoney/OrangeMoney.php index 703c4bc..130886d 100644 --- a/src/OrangeMoney/OrangeMoney.php +++ b/src/OrangeMoney/OrangeMoney.php @@ -11,15 +11,13 @@ class OrangeMoney * @param string $pay_token * @param string $notif_token */ - public function __construct($payment_url, $pay_token, $notif_token) - { - $this->pay_token = $pay_token; - - $this->payment_url = $payment_url; - - $this->notif_token = $notif_token; + public function __construct( + private $payment_url, + private $pay_token, + private $notif_token + ) { } - + /** * Redirect client to make payment * @@ -44,7 +42,7 @@ public function getPaymentInformation() "notif_token" => $this->notif_token ]; } - + /** * __toString * diff --git a/src/OrangeMoney/OrangeMoneyPayment.php b/src/OrangeMoney/OrangeMoneyPayment.php index f8f1a5b..69d8f46 100644 --- a/src/OrangeMoney/OrangeMoneyPayment.php +++ b/src/OrangeMoney/OrangeMoneyPayment.php @@ -21,13 +21,6 @@ class OrangeMoneyPayment */ private $pay_url = '/orange-money-webpay/dev/v1/webpayment'; - /** - * The generate orange money token - * - * @var OrangeMoneyToken - */ - private $token; - /** * The return url * @@ -49,13 +42,6 @@ class OrangeMoneyPayment */ private $notif_url; - /** - * The merchant id - * - * @var string - */ - private $merchant_key; - /** * OrangeMoney constructor * @@ -64,15 +50,9 @@ class OrangeMoneyPayment * @param string $currency * @return mixed */ - public function __construct(OrangeMoneyToken $token, $merchant_key, string $currency = 'OUV') + public function __construct(private OrangeMoneyToken $token, private string $merchant_key, private string $currency = 'OUV') { - $this->token = $token; - $this->http = new HttpClient(['base_uri' => 'https://api.orange.com']); - - $this->merchant_key = $merchant_key; - - $this->currency = $currency; } /** From ff7e4289317f90fa8918f53f31e9cf96474df269 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Tue, 9 Dec 2025 18:36:22 +0000 Subject: [PATCH 2/2] Refactoring payment architecture --- config/payment.php | 38 +++- src/Bowcasher.php | 40 ---- src/Common/PaymentManagerContract.php | 62 ------ src/Common/ProcessorGatewayInterface.php | 34 +++ ...> ProcessorTransactionStatusInterface.php} | 19 +- src/Common/TokenGeneratorContract.php | 40 ---- src/{ => IvoryCost}/MTNMobileMoney/.gitkeep | 0 .../MTNMobileMoney/Collection/MomoPayment.php | 0 .../Collection/MomoPaymentStatus.php | 0 .../MTNMobileMoney/MomoEnvironment.php | 0 .../MTNMobileMoney/MonoTokenGenerator.php | 0 src/{ => IvoryCost}/MoovFlooz/.gitkeep | 0 .../OrangeMoney/OrangeMoneyGateway.php} | 55 ++--- .../OrangeMoney/OrangeMoneyPayment.php | 16 +- .../OrangeMoney/OrangeMoneyResponse.php} | 10 +- .../OrangeMoney/OrangeMoneyToken.php} | 6 +- .../OrangeMoney/OrangeMoneyTokenGenerator.php | 9 +- .../OrangeMoney/OrangeMoneyTransaction.php | 12 +- .../OrangeMoneyTransactionStatus.php | 26 +-- src/{Stripe => IvoryCost/Wave}/.gitkeep | 0 src/Payment.php | 202 ++++++++++++++++++ ...guration.php => PaymentConfirguration.php} | 10 +- src/PaymentNotificationController.php | 34 --- src/UserPayment.php | 21 +- 24 files changed, 349 insertions(+), 285 deletions(-) delete mode 100644 src/Bowcasher.php delete mode 100644 src/Common/PaymentManagerContract.php create mode 100644 src/Common/ProcessorGatewayInterface.php rename src/Common/{TransactionStatusContract.php => ProcessorTransactionStatusInterface.php} (58%) delete mode 100644 src/Common/TokenGeneratorContract.php rename src/{ => IvoryCost}/MTNMobileMoney/.gitkeep (100%) rename src/{ => IvoryCost}/MTNMobileMoney/Collection/MomoPayment.php (100%) rename src/{ => IvoryCost}/MTNMobileMoney/Collection/MomoPaymentStatus.php (100%) rename src/{ => IvoryCost}/MTNMobileMoney/MomoEnvironment.php (100%) rename src/{ => IvoryCost}/MTNMobileMoney/MonoTokenGenerator.php (100%) rename src/{ => IvoryCost}/MoovFlooz/.gitkeep (100%) rename src/{OrangeMoney/BowcasherOrangeMoneyService.php => IvoryCost/OrangeMoney/OrangeMoneyGateway.php} (51%) rename src/{ => IvoryCost}/OrangeMoney/OrangeMoneyPayment.php (91%) rename src/{OrangeMoney/OrangeMoney.php => IvoryCost/OrangeMoney/OrangeMoneyResponse.php} (83%) rename src/{Common/PaymentToken.php => IvoryCost/OrangeMoney/OrangeMoneyToken.php} (96%) rename src/{ => IvoryCost}/OrangeMoney/OrangeMoneyTokenGenerator.php (89%) rename src/{ => IvoryCost}/OrangeMoney/OrangeMoneyTransaction.php (93%) rename src/{ => IvoryCost}/OrangeMoney/OrangeMoneyTransactionStatus.php (72%) rename src/{Stripe => IvoryCost/Wave}/.gitkeep (100%) create mode 100644 src/Payment.php rename src/{BowcasherConfirguration.php => PaymentConfirguration.php} (69%) delete mode 100644 src/PaymentNotificationController.php diff --git a/config/payment.php b/config/payment.php index 2195533..d175aff 100644 --- a/config/payment.php +++ b/config/payment.php @@ -1,5 +1,7 @@ 'orange_ci', + 'default' => [ + 'gateway' => Payment::ORANGE, + 'country' => 'ci', + ], /** * List of available gateway */ - 'gateways' => [ - 'orange_ci' => [ + 'ivoiry_cost' => [ + 'orange' => [ + 'client_key' => '', + 'client_secret' => '', + 'webhook_secret' => '' + ], + + 'mtn' => [ + 'client_key' => '', + 'client_secret' => '', + 'webhook_secret' => '' + ], + + 'moov' => [ 'client_key' => '', - 'merchant_key' => '' + 'client_secret' => '', + 'webhook_secret' => '' ], - 'mtn_ci' => [ + 'wave' => [ 'client_key' => '', - 'merchant_key' => '' + 'client_secret' => '', + 'webhook_secret' => '' ], - 'moov_ci' => [ + 'djamo' => [ 'client_key' => '', - 'merchant_key' => '' + 'client_secret' => '', + 'webhook_secret' => '' ] - ] + ], ]; diff --git a/src/Bowcasher.php b/src/Bowcasher.php deleted file mode 100644 index 936305e..0000000 --- a/src/Bowcasher.php +++ /dev/null @@ -1,40 +0,0 @@ -environment = PaymentManagerContract::PRODUCTION; - } - - /** - * Switch to development mode - * - * @return string - */ - public function switchToDevelopment(): void - { - $this->environment = PaymentManagerContract::DEVELOPMENT; - } - - /** - * Get the payment environment - * - * @param string $environment - * @return string - */ - public function getEnvironment(): string - { - return $this->environment; - } -} diff --git a/src/Common/ProcessorGatewayInterface.php b/src/Common/ProcessorGatewayInterface.php new file mode 100644 index 0000000..bcff06b --- /dev/null +++ b/src/Common/ProcessorGatewayInterface.php @@ -0,0 +1,34 @@ +config = $config; } /** @@ -31,29 +24,27 @@ public function __construct(array $config) * * @return void */ - public function pay(...$args) + public function payment(...$args) { $token_generator = $this->getTokenGenerator(); $payment = new OrangeMoneyPayment( $token_generator->getToken(), - $this->config['merchant_key'] + $this->config['client_secret'], ); // Set the right production endpoint - if ($this->getEnvironment() == PaymentManagerContract::PRODUCTION) { - $payment->setPaymentEndpoint('/orange-money-webpay/v1/webpayment'); - } + $payment->setPaymentEndpoint('/orange-money-webpay/v1/webpayment'); $payment->setNotifyUrl($args['notif_url']); $payment->setCancelUrl($args['cancel_url']); $payment->setReturnUrl($args['return_url']); $amount = $args['amount']; - $order_id = $args['order_id']; $reference = $args['reference']; - $orange = $payment->prepare($amount, $order_id, $reference); + $orange = $payment->prepare($amount, $reference); + $payment_information = $orange->getPaymentInformation(); // Redirect to payment plateforme @@ -64,25 +55,24 @@ public function pay(...$args) * Verify payment * * @param array ...$args - * @return TransactionStatusContract + * @return ProcessorTransactionStatusInterface */ public function verify(...$args) { $token_generator = $this->getTokenGenerator(); + // Transaction status $transaction = new OrangeMoneyTransaction($token_generator->getToken()); // Set the production url - if ($this->getEnvironment() == PaymentManagerContract::PRODUCTION) { - $transaction->setTransactionStatusEndpoint('/orange-money-webpay/v1/transactionstatus'); - } + $transaction->setTransactionStatusEndpoint('/orange-money-webpay/v1/transactionstatus'); $amount = $args['amount']; $order_id = $args['order_id']; - $reference = $args['reference']; + $pay_token = $args['pay_token']; // Check the transaction status - return $transaction->check($amount, $order_id, $reference); + return $transaction->check($amount, $order_id, $pay_token); } /** @@ -95,11 +85,8 @@ private function getTokenGenerator() $token_generator = new OrangeMoneyTokenGenerator($this->config['client_key']); // Set the right production endpoint - if ($this->getEnvironment() == PaymentManagerContract::PRODUCTION) { - $token_generator->setTokenGeneratorEndpoint('/oauth/v2/token'); - } + $token_generator->setTokenGeneratorEndpoint('/oauth/v2/token'); return $token_generator; } } - \ No newline at end of file diff --git a/src/OrangeMoney/OrangeMoneyPayment.php b/src/IvoryCost/OrangeMoney/OrangeMoneyPayment.php similarity index 91% rename from src/OrangeMoney/OrangeMoneyPayment.php rename to src/IvoryCost/OrangeMoney/OrangeMoneyPayment.php index 69d8f46..e75cad1 100644 --- a/src/OrangeMoney/OrangeMoneyPayment.php +++ b/src/IvoryCost/OrangeMoney/OrangeMoneyPayment.php @@ -1,9 +1,9 @@ http->post($this->pay_url, [ - 'json' => $this->buildRequestData($amount, $reference, $order_id), + 'json' => $this->buildRequestData($amount, $reference), 'headers' => [ 'Authorization' => (string) $this->token, 'Accept' => 'application/json', @@ -77,7 +76,7 @@ public function prepare($amount, string $order_id, string $reference) // Parse Json data $data = json_decode($response->getBody()->getContents(), true); - return new OrangeMoney( + return new OrangeMoneyResponse( $data['payment_url'], $data['pay_token'], $data['notif_token'] @@ -161,16 +160,15 @@ public function setMerchantId(string $merchant_key) * * @param int|double $amount * @param string $reference - * @param string $order_id * @return array */ - protected function buildRequestData($amount, string $reference, string $order_id) + protected function buildRequestData($amount, string $reference) { return [ "merchant_key" => $this->merchant_key, "currency" => $this->currency, - "order_id" => $order_id, "amount" => $amount, + 'order_id' => $reference, "return_url" => $this->return_url, "cancel_url" => $this->cancel_url, "notif_url" => $this->notif_url, diff --git a/src/OrangeMoney/OrangeMoney.php b/src/IvoryCost/OrangeMoney/OrangeMoneyResponse.php similarity index 83% rename from src/OrangeMoney/OrangeMoney.php rename to src/IvoryCost/OrangeMoney/OrangeMoneyResponse.php index 130886d..c6aacd4 100644 --- a/src/OrangeMoney/OrangeMoney.php +++ b/src/IvoryCost/OrangeMoney/OrangeMoneyResponse.php @@ -1,8 +1,8 @@ getBody()->getContents(); $token = json_decode($content); - + return new OrangeMoneyToken( $token->access_token, $token->token_type, diff --git a/src/OrangeMoney/OrangeMoneyTransaction.php b/src/IvoryCost/OrangeMoney/OrangeMoneyTransaction.php similarity index 93% rename from src/OrangeMoney/OrangeMoneyTransaction.php rename to src/IvoryCost/OrangeMoney/OrangeMoneyTransaction.php index e58b01f..dd6bd30 100644 --- a/src/OrangeMoney/OrangeMoneyTransaction.php +++ b/src/IvoryCost/OrangeMoney/OrangeMoneyTransaction.php @@ -1,9 +1,9 @@ check($amount, $order_id, $pay_token); - return $status->fail(); + return $status->isFail(); } /** @@ -104,7 +104,7 @@ public function checkIfHasPending($amount, string $order_id, string $pay_token) { $status = $this->check($amount, $order_id, $pay_token); - return $status->pending(); + return $status->isPending(); } /** @@ -118,7 +118,7 @@ public function checkIfHasSuccess($amount, string $order_id, string $pay_token) { $status = $this->check($amount, $order_id, $pay_token); - return $status->success(); + return $status->isSuccess(); } /** diff --git a/src/OrangeMoney/OrangeMoneyTransactionStatus.php b/src/IvoryCost/OrangeMoney/OrangeMoneyTransactionStatus.php similarity index 72% rename from src/OrangeMoney/OrangeMoneyTransactionStatus.php rename to src/IvoryCost/OrangeMoney/OrangeMoneyTransactionStatus.php index a808ff8..e2ede79 100644 --- a/src/OrangeMoney/OrangeMoneyTransactionStatus.php +++ b/src/IvoryCost/OrangeMoney/OrangeMoneyTransactionStatus.php @@ -1,10 +1,10 @@ notif_token = $notif_token; } - /** - * Get the notification token - * - * @return string - */ - public function getNotificationToken() - { - return $this->notif_token; - } - /** * Define if transaction fail * * @return bool */ - public function fail() + public function isFail() { return $this->status == 'FAIL'; } @@ -58,7 +48,7 @@ public function fail() * * @return bool */ - public function initiated() + public function isInitiated() { return $this->status == 'INITIATED'; } @@ -68,7 +58,7 @@ public function initiated() * * @return bool */ - public function expired() + public function isExpired() { return $this->status == 'EXPIRED'; } @@ -78,7 +68,7 @@ public function expired() * * @return bool */ - public function success() + public function isSuccess() { return $this->status == 'SUCCESS'; } @@ -88,7 +78,7 @@ public function success() * * @return bool */ - public function pending() + public function isPending() { return $this->status == 'PENDING'; } diff --git a/src/Stripe/.gitkeep b/src/IvoryCost/Wave/.gitkeep similarity index 100% rename from src/Stripe/.gitkeep rename to src/IvoryCost/Wave/.gitkeep diff --git a/src/Payment.php b/src/Payment.php new file mode 100644 index 0000000..b70d628 --- /dev/null +++ b/src/Payment.php @@ -0,0 +1,202 @@ + + */ + public const CI_PROVIDER = [ + Payment::ORANGE => \Bow\Payment\IvoryCost\OrangeMoney\OrangeMoneyGateway::class, + Payment::MOOV => null, + Payment::WAVE => null, + Payment::MTN => null, + Payment::DJAMO => null, + ]; + + /** + * The payment manager instance + * + * @var ProcessorGatewayInterface + */ + private static $providerGateway; + + /** + * The payment instance + * + * @var Payment + */ + private static $instance; + + /** + * ForPayment constructor + * + * @param array $config + * @return mixed + */ + public function __construct(private array $config) + { + $default = $this->config['default']; + $country = $default['country'] ?? 'ci'; + $defaultProvider = $default['gateway'] ?? Payment::ORANGE; + + $this->resolveGateway($country, $defaultProvider); + } + + /** + * Resolve the payment gateway + * + * @param string $country + * @param string $provider + * @return void + */ + private function resolveGateway(string $country, string $provider) + { + switch ($country) { + case self::CI: + $provider = self::CI_PROVIDER[$provider] ?? null; + if ($provider === null) { + throw new \InvalidArgumentException("The payment gateway [{$provider}] is not supported in country [{$country}]."); + } + $config = $this->resolveConfig('ivoiry_cost', $provider); + static::$providerGateway = new $provider($config); + break; + // Other gateways can be added here + default: + throw new \InvalidArgumentException("The payment gateway [{$provider}] is not supported."); + } + } + + /** + * Resolve configuration for a specific country and provider + * + * @param string $country + * @param string $provider + * @return array|null + */ + public function resolveConfig(string $country, string $provider) + { + return $this->config[$country][$provider] ?? []; + } + + /** + * Make configuration + * + * @return PaymentManagerContract + */ + public static function configure(array $configuration) + { + static::$instance = new Payment($configuration); + + return static::$instance; + } + + /** + * Switch payment provider + * + * @param string $country + * @param string $provider + * @return void + */ + public function withProvider(string $country, string $provider): void + { + $this->resolveGateway($country, $provider); + } + + /** + * Make payment + * + * @return mixed + */ + public function payment(...$args) + { + return static::$providerGateway->payment(...$args); + } + + /** + * Make transfer + * + * @return mixed + */ + public function transfer(...$args) + { + return static::$providerGateway->transfer(...$args); + } + + /** + * Get balance + * + * @return mixed + */ + public function balance(...$args) + { + return static::$providerGateway->balance(...$args); + } + + /** + * Verify payment + * + * @return void + */ + public function verify() + { + return static::$providerGateway->verify(); + } + + /** + * __callStatic + * + * @param string $methodName + * @param array $methodArguments + * @return mixed + */ + public static function __callStatic($methodName, $methodArguments) + { + if (method_exists(static::$instance, $methodName)) { + return call_user_func_array([static::$instance, $methodName], $methodArguments); + } + } +} diff --git a/src/BowcasherConfirguration.php b/src/PaymentConfirguration.php similarity index 69% rename from src/BowcasherConfirguration.php rename to src/PaymentConfirguration.php index 55bb620..2ddf62d 100644 --- a/src/BowcasherConfirguration.php +++ b/src/PaymentConfirguration.php @@ -5,14 +5,14 @@ use Bow\Configuration\Configuration; use Bow\Configuration\Loader as Config; -class BowcasherConfiguration extends Configuration +class PaymentConfiguration extends Configuration { /** * Create payment configuration * * @param Config $config */ - public function create(Config $config) + public function create(Config $config): void { $payment = require __DIR__.'/../config/payment'; @@ -21,7 +21,7 @@ public function create(Config $config) $config['payment'] = $payment; $this->container->make('payment', function ($config) { - return Bowcasher::configure($config['payment']); + return Payment::configure($config['payment']); }); } @@ -30,8 +30,8 @@ public function create(Config $config) * * @return mixed */ - public function run() + public function run(): void { - return $this->container->make('payment'); + $this->container->make('payment'); } } diff --git a/src/PaymentNotificationController.php b/src/PaymentNotificationController.php deleted file mode 100644 index 6a28234..0000000 --- a/src/PaymentNotificationController.php +++ /dev/null @@ -1,34 +0,0 @@ -user = config('payment.model'); - } - - /** - * Process payment notification here - * - * @param Request $request - * @return mixed - */ - public function handle(Request $request) - { - $user_id = $request->get('user_id'); - - $user = $this->user->find($user_id); - - $user->payment(); - } -} diff --git a/src/UserPayment.php b/src/UserPayment.php index 9f02cce..60bbd73 100644 --- a/src/UserPayment.php +++ b/src/UserPayment.php @@ -4,13 +4,30 @@ trait UserPayment { + public function withPaymentProvider(string $country, string $provider): self + { + Payment::withProvider($country, $provider); + + return $this; + } + + /** + * Make user payment + * + * @return mixed + */ + public function payment($amount, $reference) + { + return Payment::payment($amount, $reference); + } + /** * Make user payment * * @return mixed */ - public function payment($amount, $order_id, $reference) + public function transfer($amount, $reference) { - return Bowcasher::pay($amount, $order_id, $reference); + return Payment::transfer($amount, $reference); } }