Skip to content

Commit

Permalink
Inherit from orchestration
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Apr 17, 2024
1 parent 78a2877 commit b7c5d70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 354 deletions.
141 changes: 2 additions & 139 deletions src/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,149 +2,12 @@

namespace Payavel\Checkout;

use BadMethodCallException;
use Payavel\Checkout\Contracts\Billable;
use Payavel\Checkout\Contracts\PaymentRequestor;
use Payavel\Checkout\Models\PaymentMethod;
use Payavel\Checkout\Models\PaymentTransaction;
use Payavel\Checkout\Models\Wallet;
use Payavel\Orchestration\Service;

class PaymentGateway extends Service implements PaymentRequestor
class PaymentGateway extends Service
{
public function __construct()
{
parent::__construct(Service::find('checkout'));
}

/**
* Retrieve the wallet's details from the provider.
*
* @param \Payavel\Checkout\Models\Wallet $wallet
* @return \Payavel\Checkout\PaymentResponse
*/
public function getWallet(Wallet $wallet)
{
return tap($this->gateway->getWallet($wallet))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Retrieve the payment method's details from the provider.
*
* @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod
* @return \Payavel\Checkout\PaymentResponse
*/
public function getPaymentMethod(PaymentMethod $paymentMethod)
{
return tap($this->gateway->getPaymentMethod($paymentMethod))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Store the payment method details at the provider.
*
* @param \Payavel\Checkout\Contracts\Billable $billable
* @param array|mixed $data
* @return \Payavel\Checkout\PaymentResponse
*/
public function tokenizePaymentMethod(Billable $billable, $data)
{
return tap($this->gateway->tokenizePaymentMethod($billable, $data))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Update the payment method's details at the provider.
*
* @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod
* @param array|mixed $data
* @return \Payavel\Checkout\PaymentResponse
*/
public function updatePaymentMethod(PaymentMethod $paymentMethod, $data)
{
return tap($this->gateway->updatePaymentMethod($paymentMethod, $data))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Delete the payment method at the provider.
*
* @param \Payavel\Checkout\Models\PaymentMethod $paymentMethod
* @return \Payavel\Checkout\PaymentResponse
*/
public function deletePaymentMethod(PaymentMethod $paymentMethod)
{
return tap($this->gateway->deletePaymentMethod($paymentMethod))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Authorize a transaction.
*
* @param array|mixed $data
* @param \Payavel\Checkout\Contracts\Billable|null $billable
* @return \Payavel\Checkout\PaymentResponse
*/
public function authorize($data, Billable $billable = null)
{
return tap($this->gateway->authorize($data, $billable))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Capture a previously authorized transaction.
*
* @param \Payavel\Checkout\Models\PaymentTransaction $transaction
* @param array|mixed $data
* @return \Payavel\Checkout\PaymentResponse
*/
public function capture(PaymentTransaction $transaction, $data = [])
{
return tap($this->gateway->capture($transaction, $data))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Retrieve the transaction details from the provider.
*
* @param \Payavel\Checkout\Models\PaymentTransaction $transaction
* @return \Payavel\Checkout\PaymentResponse
*/
public function getTransaction(PaymentTransaction $transaction)
{
return tap($this->gateway->getTransaction($transaction))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Void a previously authorized transaction.
*
* @param \Payavel\Checkout\Models\PaymentTransaction $transaction
* @param array|mixed $data
* @return \Payavel\Checkout\PaymentResponse
*/
public function void(PaymentTransaction $transaction, $data = [])
{
return tap($this->gateway->void($transaction, $data))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* Refund a previously captured transaction.
*
* @param \Payavel\Checkout\Models\PaymentTransaction $transaction
* @param array|mixed $data
* @return \Payavel\Checkout\PaymentResponse
*/
public function refund(PaymentTransaction $transaction, $data = [])
{
return tap($this->gateway->refund($transaction, $data))->configure(__FUNCTION__, $this->provider, $this->account);
}

/**
* @param string $method
* @param array $params
*
* @throws \BadMethodCallException
*/
public function __call($method, $params)
{
if (! method_exists($this->gateway, $method)) {
throw new BadMethodCallException(__CLASS__ . "::{$method}() not found.");
}

return tap($this->gateway->{$method}(...$params))->configure($method, $this->provider, $this->account);
parent::__construct('checkout');
}
}
40 changes: 5 additions & 35 deletions src/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,16 @@

use Payavel\Checkout\Contracts\PaymentRequestor;
use Payavel\Checkout\Traits\PaymentRequests;
use Payavel\Orchestration\Contracts\Accountable;
use Payavel\Orchestration\Contracts\Providable;
use Payavel\Orchestration\ServiceRequest;

abstract class PaymentRequest implements PaymentRequestor
abstract class PaymentRequest extends ServiceRequest implements PaymentRequestor
{
use PaymentRequests;

/**
* The payment provider.
* The service response class.
*
* @var \Payavel\Orchestration\Contracts\Providable
* @var \Payavel\Orchestration\ServiceResponse
*/
protected $provider;

/**
* The payment account.
*
* @var \Payavel\Orchestration\Contracts\Accountable
*/
protected $account;

/**
* @param \Payavel\Orchestration\Contracts\Providable $provider
* @param \Payavel\Orchestration\Contracts\Accountable $account
*/
public function __construct(Providable $provider, Accountable $account)
{
$this->provider = $provider;
$this->account = $account;

$this->setUp();
}

/**
* Set up the request.
*
* @return void
*/
protected function setUp()
{
//
}
protected $serviceResponse = PaymentResponse::class;
}
Loading

0 comments on commit b7c5d70

Please sign in to comment.