refactor: 微信支付命名从 Native 改为 PC扫码,统一术语
- WxpayNativeOrderParams → WxpayPcOrderParams - createNativeOrder → createPcOrder - 文档注释统一为「PC扫码 / H5」
This commit is contained in:
@@ -37,7 +37,7 @@ EASY_PAY_RETURN_URL="https://pay.example.com/pay/result"
|
|||||||
# ALIPAY_RETURN_URL=https://pay.example.com/pay/result
|
# ALIPAY_RETURN_URL=https://pay.example.com/pay/result
|
||||||
|
|
||||||
# ── 微信支付直连(PAYMENT_PROVIDERS 含 wxpay 时必填) ────────────────────
|
# ── 微信支付直连(PAYMENT_PROVIDERS 含 wxpay 时必填) ────────────────────
|
||||||
# 前端自动检测设备类型:PC 端使用 Native 扫码支付,移动端使用 H5 跳转微信 APP 支付
|
# 前端自动检测设备类型:PC 端扫码支付,移动端 H5 跳转微信 APP 支付
|
||||||
# 不在 PAYMENT_PROVIDERS 中配置 wxpay 则不启用微信支付
|
# 不在 PAYMENT_PROVIDERS 中配置 wxpay 则不启用微信支付
|
||||||
# WXPAY_APP_ID= # 公众号或移动应用 AppID
|
# WXPAY_APP_ID= # 公众号或移动应用 AppID
|
||||||
# WXPAY_MCH_ID= # 商户号(10位数字)
|
# WXPAY_MCH_ID= # 商户号(10位数字)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import WxPay from 'wechatpay-node-v3';
|
import WxPay from 'wechatpay-node-v3';
|
||||||
import { getEnv } from '@/lib/config';
|
import { getEnv } from '@/lib/config';
|
||||||
import type { WxpayNativeOrderParams, WxpayH5OrderParams, WxpayRefundParams } from './types';
|
import type { WxpayPcOrderParams, WxpayH5OrderParams, WxpayRefundParams } from './types';
|
||||||
|
|
||||||
const BASE_URL = 'https://api.mch.weixin.qq.com';
|
const BASE_URL = 'https://api.mch.weixin.qq.com';
|
||||||
|
|
||||||
@@ -76,7 +76,8 @@ async function request<T>(method: string, url: string, body?: Record<string, unk
|
|||||||
return data as T;
|
return data as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createNativeOrder(params: WxpayNativeOrderParams): Promise<string> {
|
/** PC 扫码支付(微信官方 API: /v3/pay/transactions/native) */
|
||||||
|
export async function createPcOrder(params: WxpayPcOrderParams): Promise<string> {
|
||||||
const env = assertWxpayEnv(getEnv());
|
const env = assertWxpayEnv(getEnv());
|
||||||
const result = await request<{ code_url: string }>('POST', '/v3/pay/transactions/native', {
|
const result = await request<{ code_url: string }>('POST', '/v3/pay/transactions/native', {
|
||||||
appid: env.WXPAY_APP_ID,
|
appid: env.WXPAY_APP_ID,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import type {
|
|||||||
RefundResponse,
|
RefundResponse,
|
||||||
} from '@/lib/payment/types';
|
} from '@/lib/payment/types';
|
||||||
import {
|
import {
|
||||||
createNativeOrder,
|
createPcOrder,
|
||||||
createH5Order,
|
createH5Order,
|
||||||
queryOrder,
|
queryOrder,
|
||||||
closeOrder,
|
closeOrder,
|
||||||
@@ -49,7 +49,7 @@ export class WxpayProvider implements PaymentProvider {
|
|||||||
return { tradeNo: request.orderId, payUrl: h5Url };
|
return { tradeNo: request.orderId, payUrl: h5Url };
|
||||||
}
|
}
|
||||||
|
|
||||||
const codeUrl = await createNativeOrder({
|
const codeUrl = await createPcOrder({
|
||||||
out_trade_no: request.orderId,
|
out_trade_no: request.orderId,
|
||||||
description: request.subject,
|
description: request.subject,
|
||||||
notify_url: notifyUrl,
|
notify_url: notifyUrl,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export interface WxpayNativeOrderParams {
|
export interface WxpayPcOrderParams {
|
||||||
out_trade_no: string;
|
out_trade_no: string;
|
||||||
description: string;
|
description: string;
|
||||||
notify_url: string;
|
notify_url: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user