|
|
|
|
@ -95,44 +95,6 @@ final class CloudInvoicePaymentService
|
|
|
|
|
409
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$sameMethodJob = CloudJobService::blockingQueryForInvoice(
|
|
|
|
|
(int) $locked->id
|
|
|
|
|
)->where('user_id', (int) $user->id)
|
|
|
|
|
->where('request_fingerprint', $fingerprint)
|
|
|
|
|
->orderByDesc('id')->lockForUpdate()->first();
|
|
|
|
|
if ($sameMethodJob !== null) {
|
|
|
|
|
CloudInvoicePayment::where('invoice_id', (int) $locked->id)
|
|
|
|
|
->where('user_id', (int) $user->id)
|
|
|
|
|
->where('idempotency_key',
|
|
|
|
|
(string) $sameMethodJob->request_idempotency_key)
|
|
|
|
|
->whereIn('status', [
|
|
|
|
|
'creating', 'pending', 'creation_unknown',
|
|
|
|
|
])->update(['updated_at' => time()]);
|
|
|
|
|
return $sameMethodJob;
|
|
|
|
|
}
|
|
|
|
|
$sameMethodPayment = CloudInvoicePayment::where(
|
|
|
|
|
'invoice_id', (int) $locked->id
|
|
|
|
|
)->where('user_id', (int) $user->id)
|
|
|
|
|
->where('provider', $method)
|
|
|
|
|
->whereIn('status',
|
|
|
|
|
['creating', 'pending', 'creation_unknown'])
|
|
|
|
|
->orderByDesc('updated_at')->orderByDesc('id')
|
|
|
|
|
->lockForUpdate()->first();
|
|
|
|
|
if ($sameMethodPayment !== null) {
|
|
|
|
|
$sameMethodPayment->updated_at = time();
|
|
|
|
|
$sameMethodPayment->save();
|
|
|
|
|
$sameMethodPaymentJob = \App\Models\CloudJob::where(
|
|
|
|
|
'invoice_id', (int) $locked->id
|
|
|
|
|
)->where('user_id', (int) $user->id)
|
|
|
|
|
->where('kind', 'payment_create')
|
|
|
|
|
->where('request_idempotency_key',
|
|
|
|
|
(string) $sameMethodPayment->idempotency_key)
|
|
|
|
|
->orderByDesc('id')->lockForUpdate()->first();
|
|
|
|
|
if ($sameMethodPaymentJob !== null) {
|
|
|
|
|
return $sameMethodPaymentJob;
|
|
|
|
|
}
|
|
|
|
|
throw new CloudError('该支付方式已有未完成订单,请刷新后继续', 409);
|
|
|
|
|
}
|
|
|
|
|
if (!PaymentCheckoutQuotes::canQuote($method)) {
|
|
|
|
|
throw new PaymentRateUnavailable();
|
|
|
|
|
}
|
|
|
|
|
@ -478,19 +440,6 @@ final class CloudInvoicePaymentService
|
|
|
|
|
string $orderNo, string $idempotency, string $amount, int $userId,
|
|
|
|
|
int $now): void
|
|
|
|
|
{
|
|
|
|
|
// The invoice row is already locked by recordAttempt(). Keep at most
|
|
|
|
|
// one unfinished order per provider, while allowing the customer to
|
|
|
|
|
// switch to another provider before either order is paid.
|
|
|
|
|
if (CloudInvoicePayment::where('invoice_id', $invoiceId)
|
|
|
|
|
->where('idempotency_key', '<>', $idempotency)
|
|
|
|
|
->where('provider', $provider)
|
|
|
|
|
->whereIn('status', ['creating', 'pending', 'creation_unknown'])
|
|
|
|
|
->lockForUpdate()->exists()) {
|
|
|
|
|
throw new CloudError(
|
|
|
|
|
'该支付方式已有未完成订单,请继续原订单或选择其他方式',
|
|
|
|
|
409
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$payment = new CloudInvoicePayment();
|
|
|
|
|
$payment->invoice_id = $invoiceId;
|
|
|
|
|
$payment->user_id = $userId;
|
|
|
|
|
|