From 238f35c419094b0291ec0c302f8db6896cd32e8e Mon Sep 17 00:00:00 2001 From: Robert Kujawa Date: Sat, 29 Jun 2024 15:10:28 -0600 Subject: [PATCH] Implement `Checkout::config` fucntion --- src/CheckoutGateway.php | 20 ++++++++++++++++++++ src/Facades/Checkout.php | 3 ++- src/Models/Dispute.php | 6 +++--- src/Models/Payment.php | 14 +++++++------- src/Models/PaymentInstrument.php | 8 ++++---- src/Models/PaymentRail.php | 8 ++++---- src/Models/PaymentType.php | 6 +++--- src/Models/Refund.php | 6 +++--- src/Models/TransactionEvent.php | 4 ++-- src/Models/Wallet.php | 8 ++++---- tests/Unit/TestDisputeModel.php | 1 - 11 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/CheckoutGateway.php b/src/CheckoutGateway.php index 61d93d6..dcd166c 100644 --- a/src/CheckoutGateway.php +++ b/src/CheckoutGateway.php @@ -10,4 +10,24 @@ public function __construct() { parent::__construct('checkout'); } + + /** + * Get or set the service's config. + * + * @param string|array $key + * @param mixed $default + * @return mixed + */ + public function config($key, $default = null) + { + if (is_array($key)) { + foreach ($key as $key => $value) { + $this->config->set($key, $value); + } + + return; + } + + return $this->config->get($key, $default); + } } diff --git a/src/Facades/Checkout.php b/src/Facades/Checkout.php index cd134e4..ac2c890 100644 --- a/src/Facades/Checkout.php +++ b/src/Facades/Checkout.php @@ -6,6 +6,7 @@ use Payavel\Checkout\CheckoutGateway; /** + * @method static mixed config($key, $default) * @method static \Payavel\Checkout\CheckoutGateway provider($provider) * @method static \Payavel\Orchestration\Contracts\Providable getProvider() * @method static void setProvider($provider) @@ -13,8 +14,8 @@ * @method static \Payavel\Checkout\CheckoutGateway account($account) * @method static \Payavel\Orchestration\Contracts\Accountable getAccount() * @method static void setAccount($account, $strict = true) - * @method static void reset() * @method static string|int|\Payavel\Orchestration\Contracts\Accountable getDefaultAccount() + * @method static void reset() * @method static \Payavel\Checkout\CheckoutResponse getWallet(\Payavel\Checkout\Models\Wallet $wallet) * @method static \Payavel\Checkout\CheckoutResponse getPaymentInstrument(\Payavel\Checkout\Models\PaymentInstrument $paymentInstrument) * @method static \Payavel\Checkout\CheckoutResponse tokenizePaymentInstrument(\Payavel\Checkout\Contracts\Billable $billable, $data) diff --git a/src/Models/Dispute.php b/src/Models/Dispute.php index 8f868d0..89a2d4f 100644 --- a/src/Models/Dispute.php +++ b/src/Models/Dispute.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class Dispute extends Model @@ -52,7 +52,7 @@ protected static function getFactoryNamespace() */ public function payment() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Payment::class, Payment::class)); + return $this->belongsTo(Checkout::config('models.' . Payment::class, Payment::class)); } /** @@ -62,6 +62,6 @@ public function payment() */ public function transactionEvents() { - return $this->morphMany(ServiceConfig::find('checkout')->get('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); + return $this->morphMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); } } diff --git a/src/Models/Payment.php b/src/Models/Payment.php index aa52fcd..66bf682 100644 --- a/src/Models/Payment.php +++ b/src/Models/Payment.php @@ -3,10 +3,10 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Contracts\Orchestrable; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\ServiceConfig; use Payavel\Orchestration\Traits\OrchestratesService; use Payavel\Orchestration\Traits\HasFactory; @@ -64,7 +64,7 @@ protected static function getFactoryNamespace() */ public function provider() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Provider::class, Provider::class)); + return $this->belongsTo(Checkout::config('models.' . Provider::class, Provider::class)); } /** @@ -74,7 +74,7 @@ public function provider() */ public function account() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Account::class, Account::class)); + return $this->belongsTo(Checkout::config('models.' . Account::class, Account::class)); } /** @@ -84,7 +84,7 @@ public function account() */ public function rail() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . PaymentRail::class, PaymentRail::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentRail::class, PaymentRail::class)); } /** @@ -94,7 +94,7 @@ public function rail() */ public function instrument() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . PaymentInstrument::class, PaymentInstrument::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentInstrument::class, PaymentInstrument::class)); } /** @@ -104,7 +104,7 @@ public function instrument() */ public function events() { - return $this->hasMany(ServiceConfig::find('checkout')->get('models.' . TransactionEvent::class, TransactionEvent::class)); + return $this->hasMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class)); } /** @@ -114,7 +114,7 @@ public function events() */ public function transactionEvents() { - return $this->morphMany(ServiceConfig::find('checkout')->get('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); + return $this->morphMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); } /** diff --git a/src/Models/PaymentInstrument.php b/src/Models/PaymentInstrument.php index bc765c0..00e11b4 100644 --- a/src/Models/PaymentInstrument.php +++ b/src/Models/PaymentInstrument.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class PaymentInstrument extends Model @@ -53,7 +53,7 @@ protected static function getFactoryNamespace() */ public function wallet() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Wallet::class, Wallet::class)); + return $this->belongsTo(Checkout::config('models.' . Wallet::class, Wallet::class)); } /** @@ -63,7 +63,7 @@ public function wallet() */ public function type() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . PaymentType::class, PaymentType::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentType::class, PaymentType::class)); } /** @@ -73,7 +73,7 @@ public function type() */ public function payments() { - return $this->hasMany(ServiceConfig::find('checkout')->get('models.' . Payment::class, Payment::class), 'instrument_id'); + return $this->hasMany(Checkout::config('models.' . Payment::class, Payment::class), 'instrument_id'); } /** diff --git a/src/Models/PaymentRail.php b/src/Models/PaymentRail.php index d9679ea..fd3ff2a 100644 --- a/src/Models/PaymentRail.php +++ b/src/Models/PaymentRail.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class PaymentRail extends Model @@ -54,7 +54,7 @@ protected static function getFactoryNamespace() */ public function parentType() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . PaymentType::class, PaymentType::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentType::class, PaymentType::class)); } /** @@ -64,7 +64,7 @@ public function parentType() */ public function type() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . PaymentType::class, PaymentType::class)); + return $this->belongsTo(Checkout::config('models.' . PaymentType::class, PaymentType::class)); } /** @@ -74,6 +74,6 @@ public function type() */ public function payments() { - return $this->hasMany(ServiceConfig::find('checkout')->get('models.' . Payment::class, Payment::class), 'rail_id'); + return $this->hasMany(Checkout::config('models.' . Payment::class, Payment::class), 'rail_id'); } } diff --git a/src/Models/PaymentType.php b/src/Models/PaymentType.php index f61dbdb..3d388d4 100644 --- a/src/Models/PaymentType.php +++ b/src/Models/PaymentType.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class PaymentType extends Model @@ -41,7 +41,7 @@ protected static function getFactoryNamespace() */ public function rails() { - return $this->hasMany(ServiceConfig::find('checkout')->get('models.' . PaymentRail::class, PaymentRail::class), 'parent_type_id'); + return $this->hasMany(Checkout::config('models.' . PaymentRail::class, PaymentRail::class), 'parent_type_id'); } /** @@ -51,6 +51,6 @@ public function rails() */ public function instruments() { - return $this->hasMany(ServiceConfig::find('checkout')->get('models.' . PaymentInstrument::class, PaymentInstrument::class), 'type_id'); + return $this->hasMany(Checkout::config('models.' . PaymentInstrument::class, PaymentInstrument::class), 'type_id'); } } diff --git a/src/Models/Refund.php b/src/Models/Refund.php index b84d879..0773ecb 100644 --- a/src/Models/Refund.php +++ b/src/Models/Refund.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class Refund extends Model @@ -52,7 +52,7 @@ protected static function getFactoryNamespace() */ public function payment() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Payment::class, Payment::class)); + return $this->belongsTo(Checkout::config('models.' . Payment::class, Payment::class)); } /** @@ -62,6 +62,6 @@ public function payment() */ public function transactionEvents() { - return $this->morphMany(ServiceConfig::find('checkout')->get('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); + return $this->morphMany(Checkout::config('models.' . TransactionEvent::class, TransactionEvent::class), 'transactionable'); } } diff --git a/src/Models/TransactionEvent.php b/src/Models/TransactionEvent.php index 366cb1e..f9108ea 100644 --- a/src/Models/TransactionEvent.php +++ b/src/Models/TransactionEvent.php @@ -3,7 +3,7 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; -use Payavel\Orchestration\ServiceConfig; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Traits\HasFactory; class TransactionEvent extends Model @@ -52,7 +52,7 @@ protected static function getFactoryNamespace() */ public function payment() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Payment::class, Payment::class)); + return $this->belongsTo(Checkout::config('models.' . Payment::class, Payment::class)); } /** diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 4dffa95..b068386 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -3,11 +3,11 @@ namespace Payavel\Checkout\Models; use Illuminate\Database\Eloquent\Model; +use Payavel\Checkout\Facades\Checkout; use Payavel\Orchestration\Contracts\Orchestrable; use Payavel\Orchestration\Traits\OrchestratesService; use Payavel\Orchestration\Models\Account; use Payavel\Orchestration\Models\Provider; -use Payavel\Orchestration\ServiceConfig; use Payavel\Orchestration\Traits\HasFactory; class Wallet extends Model implements Orchestrable @@ -63,7 +63,7 @@ public function billable() */ public function provider() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Provider::class, Provider::class)); + return $this->belongsTo(Checkout::config('models.' . Provider::class, Provider::class)); } /** @@ -73,7 +73,7 @@ public function provider() */ public function account() { - return $this->belongsTo(ServiceConfig::find('checkout')->get('models.' . Account::class, Account::class)); + return $this->belongsTo(Checkout::config('models.' . Account::class, Account::class)); } /** @@ -83,7 +83,7 @@ public function account() */ public function paymentInstruments() { - return $this->hasMany(ServiceConfig::find('checkout')->get('models.' . PaymentInstrument::class, PaymentInstrument::class)); + return $this->hasMany(Checkout::config('models.' . PaymentInstrument::class, PaymentInstrument::class)); } /** diff --git a/tests/Unit/TestDisputeModel.php b/tests/Unit/TestDisputeModel.php index d2d3c3e..d5cbfd7 100644 --- a/tests/Unit/TestDisputeModel.php +++ b/tests/Unit/TestDisputeModel.php @@ -8,7 +8,6 @@ use Payavel\Checkout\Tests\Models\TestPayment; use Payavel\Checkout\Tests\Models\TestTransactionEvent; use Payavel\Checkout\Tests\TestCase; -use Payavel\Orchestration\ServiceConfig; use Payavel\Orchestration\Tests\Contracts\CreatesServiceables; use PHPUnit\Framework\Attributes\Test;