Skip to content

Commit

Permalink
Move model traits
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Apr 20, 2024
1 parent c156ef8 commit 081e541
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 109 deletions.
35 changes: 33 additions & 2 deletions src/Models/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
36 changes: 34 additions & 2 deletions src/Models/PaymentTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
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;
use Payavel\Orchestration\Traits\HasFactory;

class PaymentTransaction extends Model
{
use ConfiguresCheckoutGateway;
use HasFactory;
use PaymentTransactionRequests;

/**
* The attributes that aren't mass assignable.
Expand Down Expand Up @@ -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);
}
}
39 changes: 0 additions & 39 deletions src/Models/Traits/PaymentMethodRequests.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/Models/Traits/PaymentTransactionRequests.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Models/Traits/WalletRequests.php

This file was deleted.

14 changes: 12 additions & 2 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
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;
use Payavel\Orchestration\Traits\HasFactory;

class Wallet extends Model
{
use ConfiguresCheckoutGateway;
use HasFactory;
use WalletRequests;

/**
* The attributes that aren't mass assignable.
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

namespace Payavel\Checkout\Models\Traits;
namespace Payavel\Checkout\Traits;

use Payavel\Checkout\CheckoutGateway;

trait ConfiguresCheckoutGateway
{
/**
* The payment method's pre-configured gateway.
* The checkout model's pre-configured gateway.
*
* @var \Payavel\Checkout\CheckoutGateway
*/
private $paymentGateway;
private $checkoutGateway;

/**
* Retrieve the payment method's configured gateway.
Expand All @@ -20,12 +20,12 @@ trait ConfiguresCheckoutGateway
*/
public function getGatewayAttribute()
{
if (! isset($this->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;
}
}

0 comments on commit 081e541

Please sign in to comment.