From 6f09fd0c80382def63fa60b59b9cedef1c1601af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Sun, 4 Feb 2024 18:50:49 +0100 Subject: [PATCH] add manual transaction handler --- src/Fields/Transactions.php | 15 +++++++++++++-- src/Gateway/Driver.php | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Fields/Transactions.php b/src/Fields/Transactions.php index 93abdca0..d1ed97d6 100644 --- a/src/Fields/Transactions.php +++ b/src/Fields/Transactions.php @@ -5,6 +5,7 @@ use Closure; use Cone\Bazar\Gateway\Driver; use Cone\Bazar\Models\Transaction; +use Cone\Bazar\Support\Currency; use Cone\Bazar\Support\Facades\Gateway; use Cone\Root\Fields\Date; use Cone\Root\Fields\HasMany; @@ -12,8 +13,8 @@ use Cone\Root\Fields\Select; use Cone\Root\Fields\Text; use Cone\Root\Fields\URL; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; -use Illuminate\Support\Number as NumberFormatter; class Transactions extends HasMany { @@ -50,7 +51,7 @@ public function fields(Request $request): array ->min(0) ->required() ->format(static function (Request $request, Transaction $transaction, ?float $value): string { - return NumberFormatter::currency($value, $transaction->order->currency); + return (new Currency($value ?: 0, $transaction->order->currency))->format(); }), Select::make(__('Driver'), 'driver') @@ -72,4 +73,14 @@ public function fields(Request $request): array ->withTime(), ]; } + + /** + * {@inheritdoc} + */ + public function saved(Request $request, Model $model): void + { + if ($model->wasRecentlyCreated) { + Gateway::driver($model->driver)->handleManualTransaction($model); + } + } } diff --git a/src/Gateway/Driver.php b/src/Gateway/Driver.php index 5786315e..e76292c4 100644 --- a/src/Gateway/Driver.php +++ b/src/Gateway/Driver.php @@ -158,4 +158,12 @@ public function handleNotification(Request $request): Response return new HttpResponse('', HttpResponse::HTTP_NO_CONTENT); }); } + + /** + * Handle the manual transaction creation. + */ + public function handleManualTransaction(Transaction $model): void + { + // + } }