Fix: Bank transfer orders should stay in awaiting payment

This commit is contained in:
2026-09-28 10:15:23 +03:00
parent e5679afa25
commit ee4d9b7952
4 changed files with 100 additions and 47 deletions
+30 -17
View File
@@ -34,6 +34,7 @@ class OrderFulfillmentService
private readonly OrderStatusWriter $writer,
private readonly OrderStatusFlow $flow,
private readonly TransactionRecorder $transactions,
private readonly OrderPaymentResolutionService $resolution,
) {}
public function markReady(Order $order): OrderFulfillmentResult
@@ -114,9 +115,13 @@ class OrderFulfillmentService
}
/**
* Independent of `status` entirely — offered by the single "Update
* Status" action regardless of current status (see
* OrderStatusFlow::canMarkPaid()).
* For a COD order, independent of `status` entirely — offered by the
* single "Update Status" action regardless of current status (see
* OrderStatusFlow::canMarkPaid()). For a bank transfer order, status
* genuinely does advance here too (see below) — unlike COD, a bank
* transfer order has been sitting at 'awaiting_payment' since checkout
* (BankTransferPaymentDriver::pay() deliberately never advances it),
* and this click is the only thing that ever will.
*/
public function markPaid(Order $order): OrderFulfillmentResult
{
@@ -125,18 +130,20 @@ class OrderFulfillmentService
}
// canMarkPaid() only ever returns true for an order whose payment
// method resolves to the cash-on-delivery DRIVER (see
// OrderStatusFlow::isCod(), which checks PaymentMethod::driver,
// never the merchant-chosen `type` slug directly — a store could
// name that method "cod", "pay-on-delivery", anything). Such an
// order never runs through Payment's pay()/authorize() flow at
// checkout, so nothing else records a Transaction for it. Money
// changes hands right here, at this click, so this is the one
// place that write can happen; there is no earlier Payment event
// to hang it off of the way Modules\Core\Order\Listeners\
// RecordPaymentTransaction does for a gateway driver. See
// TransactionRecorder's own docblock — it already anticipated
// exactly this "manually-triggered ... from Filament" call site.
// method resolves to the cash-on-delivery or bank-transfer DRIVER
// (see OrderStatusFlow::isCod()/isBankTransfer(), which check
// PaymentMethod::driver, never the merchant-chosen `type` slug
// directly — a store could name that method "cod", "pay-on-delivery",
// "wire", anything). Neither ever runs a Transaction-recording event
// through to completion at checkout (COD dispatches nothing capture-
// shaped at all; bank transfer's pay() returns Pending with no event
// dispatched — see that driver's own docblock). Money changes hands
// right here, at this click, so this is the one place that write can
// happen; there is no earlier Payment event to hang it off of the way
// Modules\Core\Order\Listeners\RecordPaymentTransaction does for a
// gateway driver. See TransactionRecorder's own docblock — it already
// anticipated exactly this "manually-triggered ... from Filament"
// call site.
//
// $driver below is the payment method's own `type` slug (whatever
// the merchant named it, e.g. 'cash-on-delivery' or 'cod') —
@@ -146,19 +153,25 @@ class OrderFulfillmentService
// No fallback guess here: CheckoutService::initiatePayment() always
// writes Order.meta['payment_method'] before charging, and
// canMarkPaid() already guarantees this order got that far.
$type = (string) $order->meta['payment_method'];
$this->transactions->record(
$order,
type: 'capture',
driver: (string) $order->meta['payment_method'],
driver: $type,
result: new PaymentResult(
status: PaymentResultStatus::Succeeded,
reference: 'cod-manual-'.$order->id,
reference: "manual-{$type}-{$order->id}",
amount: $order->total,
),
);
$this->writer->markPaid($order, self::class.'::markPaid');
if ($this->flow->isBankTransfer($order)) {
$this->resolution->advancePastAwaitingPayment($order, self::class.'::markPaid');
}
return OrderFulfillmentResult::success('Order marked as paid.');
}