- The SDK returns signed business-failure responses (for example
ACQ.SYSTEM_ERROR) with a nil error and empty fields. QueryRefund now
checks the response code and returns an error, so the order stays
REFUND_PENDING instead of being read as "no refund record" and failed.
- A missing refund record is treated as failed only after a 10 minute
grace period from when the refund became pending. Alipay notes that a
query sent too soon can miss a refund that later succeeds. The pending
time comes from the REFUND_PENDING audit entry.
- Claim REFUND_PENDING -> REFUND_FAILED, return the held deduction and
write the audit in one transaction. If the deduction cannot be
returned, the order is still marked failed together with a
REFUND_ROLLBACK_FAILED audit so a retried refund skips the deduction.
- Return an error when the REFUND_PENDING audit cannot be loaded or
parsed instead of falling back to the legacy finalization path.
- Validate order_type (balance/subscription) at order creation and in
fulfillment; other values are rejected with INVALID_ORDER_TYPE.
- Keep the balance/subscription deduction while a gateway refund is
pending. The deduction is recorded in the REFUND_PENDING audit (written
in the same transaction as the status change), not applied again on
successful finalization, and returned once if the gateway reports
failure. Legacy pending audits keep the previous behaviour.
- REFUND_PENDING orders are finalized via refund query only;
PrepareRefund/ExecuteRefund no longer accept them.
- Invalidate the billing balance cache after refund deductions/returns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>