From 6748ee69a6f3f60018d7837ade29ffeccf945a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Fri, 27 Oct 2023 10:16:53 +0200 Subject: [PATCH] wip --- src/Gateway/CashDriver.php | 9 +++++++-- src/Gateway/Driver.php | 16 ++++++++++++++++ src/Gateway/TransferDriver.php | 9 +++++++-- src/Shipping/LocalPickupDriver.php | 5 +++++ src/Support/Driver.php | 5 +++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Gateway/CashDriver.php b/src/Gateway/CashDriver.php index 5f031d42..2444a663 100644 --- a/src/Gateway/CashDriver.php +++ b/src/Gateway/CashDriver.php @@ -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(), ]); @@ -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(), ]); diff --git a/src/Gateway/Driver.php b/src/Gateway/Driver.php index 387c08c8..4a0ad4c4 100644 --- a/src/Gateway/Driver.php +++ b/src/Gateway/Driver.php @@ -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. */ diff --git a/src/Gateway/TransferDriver.php b/src/Gateway/TransferDriver.php index e6fd4927..4f71e2a6 100644 --- a/src/Gateway/TransferDriver.php +++ b/src/Gateway/TransferDriver.php @@ -7,12 +7,17 @@ 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); } /** @@ -20,6 +25,6 @@ public function pay(Order $order, float $amount = null): Transaction */ public function refund(Order $order, float $amount = null): Transaction { - return $order->refund($amount, 'transfer'); + return $this->createRefund($order, $amount); } } diff --git a/src/Shipping/LocalPickupDriver.php b/src/Shipping/LocalPickupDriver.php index 4e78318b..965b1ac2 100644 --- a/src/Shipping/LocalPickupDriver.php +++ b/src/Shipping/LocalPickupDriver.php @@ -6,6 +6,11 @@ class LocalPickupDriver extends Driver { + /** + * The driver key. + */ + protected string $key = 'local-pickup'; + /** * Calculate the shipping cost. */ diff --git a/src/Support/Driver.php b/src/Support/Driver.php index 571b71a7..d48c2113 100644 --- a/src/Support/Driver.php +++ b/src/Support/Driver.php @@ -17,6 +17,11 @@ abstract class Driver */ protected array $config = []; + /** + * The driver key. + */ + protected string $key; + /** * Create a new driver instance. */