fix(payment): honor only provider checkout expiration

go
codex 51 minutes ago
parent 0181179161
commit 5b8f29ae78

@ -155,8 +155,6 @@ class PaytaroController extends AdminController
'paytaro_method_uuid' => strtolower($methodUuid),
'paytaro_min_amount' => $minimum,
'paytaro_max_amount' => $maximum,
'paytaro_quote_minutes' => (string) max(5, min(1440, (int) ($payload['paytaro_quote_minutes']
?? $current['paytaro_quote_minutes']))),
'paytaro_request_timeout_seconds' => (string) max(3, min(60, (int) ($payload['paytaro_request_timeout_seconds'] ?? 15))),
];
}

@ -227,8 +227,6 @@ class YipayController extends AdminController
'yipay_min_amount' => $minimum,
'yipay_max_amount' => $maximum,
'yipay_cny_confirmed' => YipayConfig::truthy($payload['yipay_cny_confirmed'] ?? false) ? 'true' : 'false',
'yipay_quote_minutes' => (string) max(5, min(1440, (int) ($payload['yipay_quote_minutes']
?? $current['yipay_quote_minutes']))),
'yipay_request_timeout_seconds' => (string) max(3, min(60, (int) ($payload['yipay_request_timeout_seconds'] ?? 15))),
];
}

@ -19,7 +19,6 @@ class PaytaroConfig
'paytaro_method_uuid' => '',
'paytaro_min_amount' => '1.00',
'paytaro_max_amount' => '10000.00',
'paytaro_quote_minutes' => '30',
'paytaro_request_timeout_seconds' => '15',
];
@ -51,7 +50,6 @@ class PaytaroConfig
$values['paytaro_test_mode'] = self::truthy($values['paytaro_test_mode']);
$values['paytaro_min_amount'] = PaymentAmount::normalize($values['paytaro_min_amount']);
$values['paytaro_max_amount'] = PaymentAmount::normalize($values['paytaro_max_amount']);
$values['paytaro_quote_minutes'] = max(5, min(1440, (int) $values['paytaro_quote_minutes']));
$values['paytaro_request_timeout_seconds'] = max(3, min(60, (int) $values['paytaro_request_timeout_seconds']));
return $values;
}

@ -21,8 +21,7 @@ class PaytaroPaymentService
$amount = $this->validateAmount($rawAmount, $settings);
$orderNo = $this->orderNo();
$now = time();
$quote = PaymentCheckoutQuotes::prepare('paytaro', $amount, $now,
$now + (int) $settings['paytaro_quote_minutes'] * 60);
$quote = PaymentCheckoutQuotes::prepare('paytaro', $amount, $now, null);
if (PaytaroOrder::where('user_id', (int) $user->id)->where('created_at', '>=', $now - 60)->count() >= 5) {
throw new \RuntimeException('Paytaro 下单过于频繁,请稍后重试');
}

@ -21,7 +21,6 @@ class YipayConfig
'yipay_min_amount' => '1.00',
'yipay_max_amount' => '10000.00',
'yipay_cny_confirmed' => 'false',
'yipay_quote_minutes' => '30',
'yipay_request_timeout_seconds' => '15',
];
@ -53,7 +52,6 @@ class YipayConfig
$values['yipay_min_amount'] = PaymentAmount::normalize($values['yipay_min_amount']);
$values['yipay_max_amount'] = PaymentAmount::normalize($values['yipay_max_amount']);
$values['yipay_cny_confirmed'] = self::truthy($values['yipay_cny_confirmed']);
$values['yipay_quote_minutes'] = max(5, min(1440, (int) $values['yipay_quote_minutes']));
$values['yipay_request_timeout_seconds'] = max(3, min(60, (int) $values['yipay_request_timeout_seconds']));
return $values;
}

@ -22,8 +22,7 @@ class YipayPaymentService
$amount = $this->validateAmount($rawAmount, $settings);
$orderNo = $this->orderNo();
$now = time();
$quote = PaymentCheckoutQuotes::prepare('yipay_' . $method, $amount, $now,
$now + (int) $settings['yipay_quote_minutes'] * 60);
$quote = PaymentCheckoutQuotes::prepare('yipay_' . $method, $amount, $now, null);
if (YipayOrder::where('user_id', (int) $user->id)->where('created_at', '>=', $now - 60)->count() >= 5) {
throw new \RuntimeException('易支付下单过于频繁,请稍后重试');
}

@ -12,15 +12,15 @@
## 部署已有面板
1. 备份业务库,从三个受影响渠道关闭新单入口。保留商户配置和 USDT 扫链,记录在途订单及原交易凭证。Stripe 和余额支付可以继续使用。
2. 在业务库对当前 `go` 旧版结构运行一次 [payment_checkout_quotes.sql](../sql/payment_checkout_quotes.sql)。应用前应已有 `usdt_payment_orders`、`yipay_refunds` 和 `cloud_invoice_payments`。SQL 增加报价账本、退款币种及关单证据字段,保留历史金额和已入账余额。全新面板按 [部署文档](../../docs/DEPLOYMENT.md) 初始化。
2. 在业务库对当前 `go` 旧版结构运行一次 [payment_checkout_quotes.sql](../sql/payment_checkout_quotes.sql)。应用前应已有 `usdt_payment_orders`、`yipay_refunds` 和 `cloud_invoice_payments`。SQL 增加报价账本并保留历史金额和已入账余额。全新面板按 [部署文档](../../docs/DEPLOYMENT.md) 初始化。
3. 发布 PHP 代码并重新加载 PHP-FPM 和负责在线支付创建的任务 Worker,在原部署用户的定时任务中同步 [crontab](../crontab)。在汇率任务的私有运行环境配置有取价权限的 `WISE_PAYMENT_RATE_TOKEN`。手动执行一次 `php xcat paymentRateJob`,在后台确认两个币对的行情状态及有效时间。Stripe、易支付、Paytaro 和扫描器继续使用各自已有的凭据。
4. 在易支付设置确认已开通的支付宝和微信商户都用人民币收款,并按商户支持的支付期限填写报价时限。Paytaro 同样配置面板报价时限。按渠道用测试模式验收真实付款、原单查询、余额或账单入账以及易支付原路退款,再逐一打开新单。
4. 在易支付设置确认已开通的支付宝和微信商户都用人民币收款。面板不会为易支付或 Paytaro 自行设置二维码有效期;只有上游返回并由集成明确支持的期限才会显示为支付截止。按渠道用测试模式验收真实付款、原单查询、余额或账单入账以及易支付原路退款,再逐一打开新单。
## 核对未决记录
- 在任一渠道设置页进入「支付汇率与对账」,按 CNY、USDT 或 USD 查询与导出 CSV。待核对的回执有独立状态,金额汇总只计入已核实收款。易支付退款明细同时显示渠道实际退回的 CNY 和原 USD 入账的扣回。
- 历史错价、少付、渠道币种冲突,以及超过本地报价期限且缺少可信付款时间的 CNY 回执保留凭证,交由管理员逐笔核对。已结算历史余额按原流水保留。两笔独立有效款项对应同一账单时,账单只履约一次,另一笔保留在余额。
- 超过面板报价期限只会关闭面板的付款入口。商户平台确认 CNY 订单已经关闭且未收款后,超级管理员可登记原订单与商户凭据,释放该账单的同渠道重新报价。已有收款证据的订单留在对账中。关单后收到矛盾的签名来款时,系统保留回执并标为待核对。
- 历史错价、少付和渠道币种冲突的 CNY 回执保留凭证,交由管理员逐笔核对。已结算历史余额按原流水保留。两笔独立有效款项对应同一账单时,账单只履约一次,另一笔保留在余额。
- 易支付和 Paytaro 每次明确的新支付请求都会生成独立上游订单;面板不以账单截止时间代替上游二维码有效期,也不在本地关闭上游订单。旧订单的有效签名来款仍按其精确订单号结算。
- USDT 按链上确认的转账时间、合约、收款地址、精确尾数与订单自己的迟付宽限验款。没有唯一归属的转账继续出现在链上核对列表。
- 易支付退款渠道已确认时,可从原单继续完成本地记账。退款结果未知时,在商户平台核对原流水,保留当前退款凭证。

@ -48,6 +48,10 @@ test connectivity before enabling the payment method.
MAPI requests use the EPay MD5 signing rules and send the frozen CNY quote.
After verification, the panel applies the USD credit. Desktop browsers show
the Alipay QR code. Mobile browsers show the quote and an Alipay app link.
The MAPI response currently has no documented expiry field consumed by this
integration. The panel therefore does not invent a local QR deadline or use an
invoice deadline to close a Paytaro order. A later signed callback remains
authoritative for that exact upstream order.
Paytaro must be able to reach these public callback routes:

@ -46,6 +46,10 @@ Open `/admin/yipay`, enter the HTTPS gateway root URL, one public HTTPS panel
callback base URL, merchant PID and merchant key. Save and test the connection
before enabling the user-facing switch. Confirm that each enabled method
charges CNY. The panel presents the frozen CNY quote and accounts in USD.
The supported MAPI response has no documented expiry field consumed by this
integration. The panel does not invent a local QR deadline or use an invoice
deadline to close a Yipay order; a later valid callback remains attributable
to its exact upstream order.
The gateway must be able to send a GET request to the fixed
`/yipay/callback` URL. This route must bypass login and CDN caching. The browser

@ -458,17 +458,6 @@ function mergeInvoiceStatus(invoice, update) {
return merged;
}
function onlinePaymentFallbackExpiresAt(invoice = state.selectedInvoice) {
const now = Date.now();
const maximum = now + STATUS_POLL_MAX_LIFETIME_MS;
const invoiceDeadline = serviceTimestamp(
String(invoice?.purpose || '').toLowerCase() === 'renewal'
? invoice?.deletion_at : invoice?.payment_deadline_at,
);
return invoiceDeadline !== null && invoiceDeadline > now
? Math.min(invoiceDeadline, maximum) : maximum;
}
function clearOnlinePaymentExpiryTimer() {
if (state.onlinePaymentExpiryTimer !== null) {
clearTimeout(state.onlinePaymentExpiryTimer);
@ -753,9 +742,7 @@ function renderOnlinePayment(container, payment) {
state.onlinePaymentMethodId = firstText(payment.method,
state.selectedInvoicePaymentMethod);
const paymentExpiresAt = serviceTimestamp(payment.expires_at);
state.onlinePaymentExpiresAt = paymentExpiresAt === null
? onlinePaymentFallbackExpiresAt(state.selectedInvoice)
: paymentExpiresAt;
state.onlinePaymentExpiresAt = paymentExpiresAt ?? 0;
let qrValue = '';
if (payment.payment_kind === 'usdt') {
@ -1263,9 +1250,9 @@ function hydrateInvoiceDetail(payload, expectedInvoiceId = document.body.dataset
state.onlinePaymentPending = Boolean(serverPendingPayment);
if (state.onlinePaymentPending) {
state.onlinePaymentInvoiceId = String(payload.invoice.id);
if (state.onlinePaymentExpiresAt <= 0) {
state.onlinePaymentExpiresAt = onlinePaymentFallbackExpiresAt(payload.invoice);
}
state.onlinePaymentExpiresAt = serviceTimestamp(
state.activePayment?.payment?.expires_at,
) ?? 0;
}
if (entersProvisioningAfterPayment(previousInvoice, payload.invoice,
payload.presentation, wasAwaitingOnlinePayment)) {

@ -34,7 +34,7 @@
<div class="pt-field"><label for="ptMinimum">最低充值金额</label><input class="form-control" id="ptMinimum" name="paytaro_min_amount" type="number" min="0.01" max="1000000" step="0.01" value="{$paytaro_config.paytaro_min_amount|escape}"></div>
<div class="pt-field"><label for="ptMaximum">最高充值金额</label><input class="form-control" id="ptMaximum" name="paytaro_max_amount" type="number" min="0.01" max="1000000" step="0.01" value="{$paytaro_config.paytaro_max_amount|escape}"></div>
<div class="pt-field"><label for="ptTimeout">请求超时(秒)</label><input class="form-control" id="ptTimeout" name="paytaro_request_timeout_seconds" type="number" min="3" max="60" value="{$paytaro_config.paytaro_request_timeout_seconds|escape}"></div>
<div class="pt-field"><label for="ptQuoteMinutes">支付报价有效期(分钟)</label><input class="form-control" id="ptQuoteMinutes" name="paytaro_quote_minutes" type="number" min="5" max="1440" value="{$paytaro_config.paytaro_quote_minutes|escape}"></div>
<div class="pt-field"><label>支付链接有效期</label><strong>由 Paytaro 决定</strong><span class="pt-help">面板不会用本地时间提前关闭上游支付链接。</span></div>
</div>
<div class="pt-actions"><button class="btn btn-primary" id="ptSave" type="submit" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-content-save-outline me-1"></i>保存配置</button><button class="btn btn-light" id="ptTest" type="button" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-lan-connect me-1"></i>测试连接</button><div class="pt-notice" id="ptNotice" role="status" aria-live="polite"></div></div>
</form>

@ -82,8 +82,9 @@
<input class="form-control" id="ypTimeout" name="yipay_request_timeout_seconds" type="number" min="3" max="60" value="{$yipay_config.yipay_request_timeout_seconds|escape}">
</div>
<div class="yp-field">
<label for="ypQuoteMinutes">支付报价有效期(分钟)</label>
<input class="form-control" id="ypQuoteMinutes" name="yipay_quote_minutes" type="number" min="5" max="1440" value="{$yipay_config.yipay_quote_minutes|escape}">
<label>支付链接有效期</label>
<strong>由支付上游决定</strong>
<span class="yp-help">面板不会用本地时间提前关闭上游支付链接。</span>
</div>
</div>
<div class="yp-actions">

@ -283,7 +283,7 @@ $assert(str_contains($needsPolling, 'state.presentation?.polling_required === tr
&& !str_contains($invoiceDetailRuntime, 'function provisionFinished('),
'Invoice polling must consume the server projection instead of rebuilding task state.');
$paymentExpiry = $section($invoiceDetailRuntime,
'function onlinePaymentFallbackExpiresAt(', 'function invoiceNeedsPolling(');
'function clearOnlinePaymentExpiryTimer(', 'function invoiceNeedsPolling(');
$onlinePaymentRender = $section($invoiceDetailRuntime,
'function renderOnlinePayment(', 'async function payInvoiceBalance(');
$detailHydration = $section($invoiceDetailRuntime,
@ -295,25 +295,24 @@ $assert(!str_contains($invoiceDetailRuntime, 'function hasPendingInvoicePaymentK
&& str_contains($detailHydration,
'state.onlinePaymentPending = Boolean(serverPendingPayment);')
&& str_contains($invoiceDetailRuntime, 'resumeInvoicePolling();')
&& str_contains($paymentExpiry, 'STATUS_POLL_MAX_LIFETIME_MS')
&& str_contains($paymentExpiry, 'serviceTimestamp(')
&& str_contains($paymentExpiry, 'function onlinePaymentHasExpired(')
&& str_contains($paymentExpiry, 'function expireOnlinePaymentInstructions(')
&& str_contains($paymentExpiry, 'clearOnlinePaymentState(true);')
&& str_contains($paymentExpiry,
"makeElement('strong', '', t('billing.payment.expired.title'))")
&& str_contains($paymentExpiry, 'void refreshInvoiceDetail(invoiceId);')
&& str_contains($onlinePaymentRender, 'paymentExpiresAt === null')
&& str_contains($onlinePaymentRender,
'onlinePaymentFallbackExpiresAt(state.selectedInvoice)')
'state.onlinePaymentExpiresAt = paymentExpiresAt ?? 0;')
&& str_contains($onlinePaymentRender, 'scheduleOnlinePaymentExpiry(generation);')
&& str_contains($detailHydration,
'if (onlinePaymentHasExpired()) expireOnlinePaymentInstructions();')
&& str_contains($detailHydration, 'state.onlinePaymentExpiresAt <= 0')
&& str_contains($detailHydration,
'state.activePayment?.payment?.expires_at')
&& !str_contains($invoiceDetailRuntime, 'onlinePaymentFallbackExpiresAt')
&& !str_contains($detailHydration, 'state.onlinePaymentExpiresAt <= Date.now()')
&& str_contains($invoiceDetailRuntime, 'STATUS_POLL_SLOW_INTERVAL_MS')
&& str_contains($invoiceDetailRuntime, 'Date.now() < state.pollUntil'),
'Provider payments must recover through a bounded fallback expiry and disable stale instructions.');
'Provider payments must expire only from the durable provider deadline, never a local fallback.');
$assert(str_contains($invoiceDetailRuntime,
'function entersProvisioningAfterPayment(')
&& substr_count($invoiceDetailRuntime,

@ -46,7 +46,7 @@ $schema->create('yipay_refunds', static function (Blueprint $table): void {
$now = 1_770_000_000;
PaymentRateService::override('USD/CNY', '7.20', $now + 3600, 7, 'First acceptance quote', $now);
$draft = PaymentCheckoutQuotes::prepare('paytaro', '72.00', $now, $now + 900);
$draft = PaymentCheckoutQuotes::prepare('paytaro', '72.00', $now, null);
$connection->transaction(fn () => PaymentCheckoutQuotes::persist($draft, 'PT-QUOTE-A', 21));
PaymentRateService::override('USD/CNY', '7.30', $now + 3600, 7, 'Second acceptance quote', $now + 1);
$later = PaymentCheckoutQuotes::prepare('yipay_wxpay', '72.00', $now + 1, $now + 900);
@ -55,6 +55,16 @@ $connection->transaction(fn () => PaymentCheckoutQuotes::persist($later, 'YP-QUO
$old = PaymentCheckoutQuotes::find('paytaro', 'PT-QUOTE-A');
checkCheckoutQuote($old->expected_units === 51840 && $later->expected_units === 52560,
'Changing the rate affected an existing order or failed to price the next one.');
checkCheckoutQuote($old->provider_expires_at === null
&& $old->accept_until === null
&& PaymentCheckoutQuotes::checkout('paytaro', 'PT-QUOTE-A', 21, $now + 86400)
=== [
'checkout_state' => 'payable',
'amount' => '72.00',
'charge_amount' => '518.40',
'charge_currency' => 'CNY',
'expires_at' => null,
], 'A CNY checkout without upstream expiry was closed by local time.');
checkCheckoutQuote(PaymentCheckoutQuotes::find('yipay_wxpay', 'PT-QUOTE-A') === null,
'A quote was read using a different provider.');

@ -162,7 +162,6 @@ try {
(new PaytaroClient([
'paytaro_gateway_url' => PaytaroConfig::MAPI_GATEWAY_URL,
'paytaro_request_timeout_seconds' => 15,
'paytaro_quote_minutes' => 30,
PaytaroConfig::SECRET_KEY => 'merchant-secret',
], $httpClient))->createOrder($fixed);
fwrite(STDERR, 'Paytaro accepted a non-HTTPS payment URL.' . PHP_EOL);
@ -397,7 +396,13 @@ $createdInvoiceOrder = $invoiceCreateService->createOrder(
);
$createdAttempt = Capsule::table('cloud_invoice_payments')
->where('provider_order_no', (string) $createdInvoiceOrder->order_no)->first();
$createdQuote = PaymentCheckoutQuotes::find(
'paytaro', (string) $createdInvoiceOrder->order_no
);
if ($createdAttempt === null
|| $createdQuote === null
|| $createdQuote->provider_expires_at !== null
|| $createdQuote->accept_until !== null
|| (string) $createdAttempt->status !== 'creating'
|| (string) $createdAttempt->provider !== 'paytaro'
|| ($invoiceCreateGateway->outbound['money'] ?? '') !== '302.40'
@ -706,7 +711,6 @@ $smarty->assign([
'paytaro_min_amount' => '1.00',
'paytaro_max_amount' => '10000.00',
'paytaro_request_timeout_seconds' => 15,
'paytaro_quote_minutes' => 30,
],
'paytaro_orders' => null,
'paytaro_summary' => ['total' => 0, 'pending' => 0, 'paid' => 0, 'paid_amount' => '0.00'],

@ -273,7 +273,13 @@ $createdInvoiceOrder = $invoiceCreateService->createOrder(
);
$createdAttempt = Capsule::table('cloud_invoice_payments')
->where('provider_order_no', (string) $createdInvoiceOrder->order_no)->first();
$createdQuote = PaymentCheckoutQuotes::find(
'yipay_alipay', (string) $createdInvoiceOrder->order_no
);
if ($createdAttempt === null
|| $createdQuote === null
|| $createdQuote->provider_expires_at !== null
|| $createdQuote->accept_until !== null
|| (string) $createdAttempt->status !== 'creating'
|| (string) $createdAttempt->provider !== 'yipay_alipay'
|| ($invoiceCreateGateway->outbound['money'] ?? '') !== '302.40'

Loading…
Cancel
Save