Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 27, 2023
1 parent 82b2876 commit 6748ee6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Gateway/CashDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

class CashDriver extends Driver
{
/**
* The driver key.
*/
protected string $key = 'cash';

/**
* Process the payment.
*/
public function pay(Order $order, float $amount = null): Transaction
{
$transaction = $order->pay($amount, 'cash', [
$transaction = $this->createPayment($order, $amount, [
'completed_at' => time(),
]);

Expand All @@ -27,7 +32,7 @@ public function pay(Order $order, float $amount = null): Transaction
*/
public function refund(Order $order, float $amount = null): Transaction
{
$transaction = $order->refund($amount, 'cash', [
$transaction = $this->createRefund($order, $amount, [
'completed_at' => time(),
]);

Expand Down
16 changes: 16 additions & 0 deletions src/Gateway/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ public function getTransactionUrl(Transaction $transaction): ?string
return null;
}

/**
* Create a new payment transaction for the order.
*/
public function createPayment(Order $order, float $amount = null, array $attributes = []): Transaction
{
return $order->pay($amount, $this->key, $attributes);
}

/**
* Create a new refund transaction for the order.
*/
public function createRefund(Order $order, float $amount = null, array $attributes = []): Transaction
{
return $order->refund($amount, $this->key, $attributes);
}

/**
* Handle the checkout request.
*/
Expand Down
9 changes: 7 additions & 2 deletions src/Gateway/TransferDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@

class TransferDriver extends Driver
{
/**
* The driver key.
*/
protected string $key = 'transfer';

/**
* Process the payment.
*/
public function pay(Order $order, float $amount = null): Transaction
{
return $order->pay($amount, 'transfer');
return $this->createPayment($order, $amount);
}

/**
* Process the refund.
*/
public function refund(Order $order, float $amount = null): Transaction
{
return $order->refund($amount, 'transfer');
return $this->createRefund($order, $amount);
}
}
5 changes: 5 additions & 0 deletions src/Shipping/LocalPickupDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

class LocalPickupDriver extends Driver
{
/**
* The driver key.
*/
protected string $key = 'local-pickup';

/**
* Calculate the shipping cost.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Support/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ abstract class Driver
*/
protected array $config = [];

/**
* The driver key.
*/
protected string $key;

/**
* Create a new driver instance.
*/
Expand Down

0 comments on commit 6748ee6

Please sign in to comment.