Feat: Recording Payment Transactions
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Payment\Services;
|
||||
|
||||
use Lunar\Models\Order;
|
||||
use Lunar\Models\Transaction;
|
||||
use Modules\Core\Payment\DTOs\CaptureResult;
|
||||
use Modules\Core\Payment\DTOs\RefundResult;
|
||||
|
||||
/**
|
||||
* Writes the Transaction row a SupportsRefunds/SupportsCaptures driver's
|
||||
* result becomes — the one place that translates a gateway-agnostic
|
||||
* RefundResult/CaptureResult into Lunar's own transactions table, in the
|
||||
* same shape lunarphp/stripe's StoreCharges already writes (type, success,
|
||||
* amount, reference, driver, notes). Kept here rather than inside each
|
||||
* driver so every driver's rows land in a consistent shape that
|
||||
* Order::paymentStatus() and TransactionObserver both already understand,
|
||||
* without any driver needing to know about either.
|
||||
*/
|
||||
class TransactionRecorder
|
||||
{
|
||||
public function recordRefund(Order $order, string $driver, RefundResult $result, ?string $notes = null): Transaction
|
||||
{
|
||||
return $order->transactions()->create([
|
||||
'success' => $result->success,
|
||||
'type' => 'refund',
|
||||
'driver' => $driver,
|
||||
'amount' => $result->amount,
|
||||
'reference' => $result->reference,
|
||||
'status' => $result->success ? 'succeeded' : 'failed',
|
||||
'notes' => $notes ?? $result->message,
|
||||
'meta' => $result->meta,
|
||||
]);
|
||||
}
|
||||
|
||||
public function recordCapture(Order $order, string $driver, CaptureResult $result, ?string $notes = null): Transaction
|
||||
{
|
||||
return $order->transactions()->create([
|
||||
'success' => $result->success,
|
||||
'type' => 'capture',
|
||||
'driver' => $driver,
|
||||
'amount' => $result->amount,
|
||||
'reference' => $result->reference,
|
||||
'status' => $result->success ? 'succeeded' : 'failed',
|
||||
'notes' => $notes ?? $result->message,
|
||||
'meta' => $result->meta,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user