From 081e541b3a7f87d349cfc1446c3ee325bad7c2d2 Mon Sep 17 00:00:00 2001 From: r-kujawa Date: Sat, 20 Apr 2024 06:46:32 -0600 Subject: [PATCH] Move model traits --- src/Models/PaymentMethod.php | 35 +++++++++++++++- src/Models/PaymentTransaction.php | 36 ++++++++++++++++- src/Models/Traits/PaymentMethodRequests.php | 39 ------------------ .../Traits/PaymentTransactionRequests.php | 40 ------------------- src/Models/Traits/WalletRequests.php | 18 --------- src/Models/Wallet.php | 14 ++++++- .../Traits/ConfiguresCheckoutGateway.php | 12 +++--- 7 files changed, 85 insertions(+), 109 deletions(-) delete mode 100644 src/Models/Traits/PaymentMethodRequests.php delete mode 100644 src/Models/Traits/PaymentTransactionRequests.php delete mode 100644 src/Models/Traits/WalletRequests.php rename src/{Models => }/Traits/ConfiguresCheckoutGateway.php (61%) diff --git a/src/Models/PaymentMethod.php b/src/Models/PaymentMethod.php index 17bcfd2..171f237 100644 --- a/src/Models/PaymentMethod.php +++ b/src/Models/PaymentMethod.php @@ -3,14 +3,14 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Checkout\Models\Traits\PaymentMethodRequests; +use Payavel\Checkout\Traits\ConfiguresCheckoutGateway; use Payavel\Orchestration\Support\ServiceConfig; use Payavel\Orchestration\Traits\HasFactory; class PaymentMethod extends Model { + use ConfiguresCheckoutGateway; use HasFactory; - use PaymentMethodRequests; /** * The attributes that aren't mass assignable. @@ -97,4 +97,35 @@ public function transactions() { return $this->hasMany(ServiceConfig::get('checkout', 'models.' . PaymentTransaction::class, PaymentTransaction::class)); } + + /** + * Fetch the payment method details from the provider. + * + * @return \Payavel\Checkout\CheckoutResponse + */ + public function fetch() + { + return $this->gateway->getPaymentMethod($this); + } + + /** + * Request the provider to update the payment method's details. + * + * @param array|mixed $data + * @return \Payavel\Checkout\CheckoutResponse + */ + public function patch($data) + { + return $this->gateway->updatePaymentMethod($this, $data); + } + + /** + * Request the provider to remove the payment method from their system. + * + * @return \Payavel\Checkout\CheckoutResponse + */ + public function disable() + { + return $this->gateway->deletePaymentMethod($this); + } } diff --git a/src/Models/PaymentTransaction.php b/src/Models/PaymentTransaction.php index 22d2051..18cb662 100644 --- a/src/Models/PaymentTransaction.php +++ b/src/Models/PaymentTransaction.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Checkout\Models\Traits\PaymentTransactionRequests; +use Payavel\Checkout\Traits\ConfiguresCheckoutGateway; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; use Payavel\Orchestration\Support\ServiceConfig; @@ -11,8 +11,8 @@ class PaymentTransaction extends Model { + use ConfiguresCheckoutGateway; use HasFactory; - use PaymentTransactionRequests; /** * The attributes that aren't mass assignable. @@ -88,4 +88,36 @@ public function events() { return $this->hasMany(ServiceConfig::get('checkout', 'models.' . PaymentTransactionEvent::class, PaymentTransactionEvent::class), 'transaction_id'); } + + /** + * Fetch the transaction details from the provider. + * + * @return \Payavel\Checkout\CheckoutResponse + */ + public function fetch() + { + return $this->gateway->getTransaction($this); + } + + /** + * Request the provider to void the transaction. + * + * @param array|mixed $data + * @return \Payavel\Checkout\CheckoutResponse + */ + public function void($data = []) + { + return $this->gateway->void($this, $data); + } + + /** + * Request the provider to refund the transaction. + * + * @param array|mixed $data + * @return \Payavel\Checkout\CheckoutResponse + */ + public function refund($data = []) + { + return $this->gateway->refund($this, $data); + } } diff --git a/src/Models/Traits/PaymentMethodRequests.php b/src/Models/Traits/PaymentMethodRequests.php deleted file mode 100644 index 886b1c6..0000000 --- a/src/Models/Traits/PaymentMethodRequests.php +++ /dev/null @@ -1,39 +0,0 @@ -gateway->getPaymentMethod($this); - } - - /** - * Request the provider to update the payment method's details. - * - * @param array|mixed $data - * @return \Payavel\Checkout\CheckoutResponse - */ - public function patch($data) - { - return $this->gateway->updatePaymentMethod($this, $data); - } - - /** - * Request the provider to remove the payment method from their system. - * - * @return \Payavel\Checkout\CheckoutResponse - */ - public function disable() - { - return $this->gateway->deletePaymentMethod($this); - } -} diff --git a/src/Models/Traits/PaymentTransactionRequests.php b/src/Models/Traits/PaymentTransactionRequests.php deleted file mode 100644 index dd26993..0000000 --- a/src/Models/Traits/PaymentTransactionRequests.php +++ /dev/null @@ -1,40 +0,0 @@ -gateway->getTransaction($this); - } - - /** - * Request the provider to void the transaction. - * - * @param array|mixed $data - * @return \Payavel\Checkout\CheckoutResponse - */ - public function void($data = []) - { - return $this->gateway->void($this, $data); - } - - /** - * Request the provider to refund the transaction. - * - * @param array|mixed $data - * @return \Payavel\Checkout\CheckoutResponse - */ - public function refund($data = []) - { - return $this->gateway->refund($this, $data); - } -} diff --git a/src/Models/Traits/WalletRequests.php b/src/Models/Traits/WalletRequests.php deleted file mode 100644 index e8c2a97..0000000 --- a/src/Models/Traits/WalletRequests.php +++ /dev/null @@ -1,18 +0,0 @@ -gateway->getWallet($this); - } -} diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index bf7b20f..cb1d405 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Checkout\Models\Traits\WalletRequests; +use Payavel\Checkout\Traits\ConfiguresCheckoutGateway; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; use Payavel\Orchestration\Support\ServiceConfig; @@ -11,8 +11,8 @@ class Wallet extends Model { + use ConfiguresCheckoutGateway; use HasFactory; - use WalletRequests; /** * The attributes that aren't mass assignable. @@ -77,4 +77,14 @@ public function paymentMethods() { return $this->hasMany(ServiceConfig::get('checkout', 'models.' . PaymentMethod::class, PaymentMethod::class)); } + + /** + * Fetch the wallet details from the provider. + * + * @return \Payavel\Checkout\CheckoutResponse + */ + public function fetch() + { + return $this->gateway->getWallet($this); + } } diff --git a/src/Models/Traits/ConfiguresCheckoutGateway.php b/src/Traits/ConfiguresCheckoutGateway.php similarity index 61% rename from src/Models/Traits/ConfiguresCheckoutGateway.php rename to src/Traits/ConfiguresCheckoutGateway.php index 6e186d5..1211fad 100644 --- a/src/Models/Traits/ConfiguresCheckoutGateway.php +++ b/src/Traits/ConfiguresCheckoutGateway.php @@ -1,17 +1,17 @@ paymentGateway)) { - $this->paymentGateway = (new CheckoutGateway()) + if (! isset($this->checkoutGateway)) { + $this->checkoutGateway = (new CheckoutGateway()) ->provider($this->provider) ->account($this->account); } - return $this->paymentGateway; + return $this->checkoutGateway; } }