Skip to content

Commit

Permalink
Implement Checkout::config fucntion
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Jun 29, 2024
1 parent 5289872 commit 238f35c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 32 deletions.
20 changes: 20 additions & 0 deletions src/CheckoutGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 25 in src/CheckoutGateway.php

View check run for this annotation

Codecov / codecov/patch

src/CheckoutGateway.php#L24-L25

Added lines #L24 - L25 were not covered by tests
}

return;

Check warning on line 28 in src/CheckoutGateway.php

View check run for this annotation

Codecov / codecov/patch

src/CheckoutGateway.php#L28

Added line #L28 was not covered by tests
}

return $this->config->get($key, $default);
}
}
3 changes: 2 additions & 1 deletion src/Facades/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
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)
* @method static string|int|\Payavel\Orchestration\Contracts\Providable getDefaultProvider()
* @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)
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Dispute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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');
}
}
14 changes: 7 additions & 7 deletions src/Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Models/PaymentInstrument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Models/PaymentRail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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');
}
}
6 changes: 3 additions & 3 deletions src/Models/PaymentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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');
}
}
6 changes: 3 additions & 3 deletions src/Models/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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');
}
}
4 changes: 2 additions & 2 deletions src/Models/TransactionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/TestDisputeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 238f35c

Please sign in to comment.