Skip to content

Commit

Permalink
add manual transaction handler
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 4, 2024
1 parent b63e785 commit 6f09fd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Fields/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
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;
use Cone\Root\Fields\Number;
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
{
Expand Down Expand Up @@ -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')
Expand All @@ -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);
}
}
}
8 changes: 8 additions & 0 deletions src/Gateway/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
//
}
}

0 comments on commit 6f09fd0

Please sign in to comment.