refactor(daxpay): 重构支付宝聚合支付功能

- 更新 AliAggregate.vue 组件,适配新的聚合支付接口和数据结构
- 修改 CheckoutPay.api.ts,统一支付相关 API 接口定义
- 新增 AggregateTypeEnum 枚举,用于区分不同的聚合支付类型
This commit is contained in:
bootx
2024-12-02 22:35:10 +08:00
parent 85d0bd852c
commit c022aa8650
3 changed files with 70 additions and 67 deletions

View File

@@ -26,3 +26,11 @@ export enum CashierTypeEnum {
WECHAT_PAY = 'wechat_pay',
ALIPAY = 'alipay',
}
/**
* 聚合支付方式
*/
export enum AggregateTypeEnum {
WECHAT = 'wechat',
ALIPAY = 'alipay',
}

View File

@@ -1,62 +1,62 @@
import { http } from '@/utils/http/axios'
import type { Result } from '#/axios'
import {AuthResult} from "@/views/daxpay/auth/ChannelAuth.api";
import type { AuthResult } from '@/views/daxpay/auth/ChannelAuth.api'
import {PayResult} from "@/views/daxpay/cashier/CashierCode.api";
/**
* 获取收银台订单和配置信息
*/
export function getOrderAndConfig(orderNo, checkoutType){
export function getOrderAndConfig(orderNo, checkoutType) {
return http.request({
url: '/unipay/checkout/getOrderAndConfig',
method: 'GET',
params: {
orderNo,
checkoutType
}
checkoutType,
},
})
}
/**
* 获取聚合支付配置
*/
export function getAggregateConfig(orderNo, aggregateType){
export function getAggregateConfig(orderNo, aggregateType) {
return http.request<Result<AggregateOrderAndConfigResult>>({
url: '/unipay/checkout/getAggregateConfig',
method: 'GET',
params: {
orderNo,
aggregateType
}
aggregateType,
},
})
}
/**
* 获取收银台所需授权链接, 用于获取OpenId一类的信息
*/
export function generateAuthUrl(param: CheckoutAuthUrlParam){
export function generateAuthUrl(param: CheckoutAuthUrlParam) {
return http.request<Result<string>>({
url: '/unipay/checkout/generateAuthUrl',
method: 'post',
data: param
data: param,
})
}
/**
* 获取授权结果
*/
export function auth(param: CheckoutAuthCodeParam){
export function auth(param: CheckoutAuthCodeParam) {
return http.request<AuthResult>({
url: '/unipay/checkout/auth',
method: 'post',
data: param
data: param,
})
}
/**
* 发起支付
*/
export function pay(param: CheckoutPayParam){
return http.request<Result<CheckoutPayResult>>({
export function checkoutPay(param: CheckoutPayParam) {
return http.request<Result<PayResult>>({
url: '/unipay/checkout/pay',
method: 'post',
data: param
data: param,
})
}
@@ -67,11 +67,11 @@ export interface CheckoutAuthUrlParam {
/**
* 要支付的订单号
*/
orderNo?: string;
orderNo?: string
/**
* 聚合支付类型
*/
aggregateType?: string;
aggregateType?: string
}
/**
* 获取收银台认证结果参数
@@ -80,11 +80,11 @@ export interface CheckoutAuthCodeParam {
/**
* 要支付的订单号
*/
orderNo?: string;
orderNo?: string
/**
* 聚合支付类型
*/
aggregateType?: string;
aggregateType?: string
/**
* 认证Code
*/
@@ -94,94 +94,94 @@ export interface CheckoutAuthCodeParam {
/**
* 收银台支付参数
*/
export interface CheckoutPayParam{
export interface CheckoutPayParam {
/**
* 订单号
*/
orderNo?: string;
orderNo?: string
/**
* 支付配置项ID
*/
itemId?: string;
itemId?: string
/**
* 唯一标识
*/
openId?: string;
openId?: string
/**
* 付款码
*/
barCode?: string;
barCode?: string
}
/**
* 收银台聚合支付配置
*/
export interface AggregateOrderAndConfigResult{
export interface AggregateOrderAndConfigResult {
/**
* 订单信息
*/
order: CheckoutOrderResult;
order: CheckoutOrderResult
/**
* 收银台配置信息
*/
config: CheckoutConfigResult;
config: CheckoutConfigResult
/**
* 收银台聚合配置信息
*/
aggregateConfig: AggregateConfigResult;
aggregateConfig: AggregateConfigResult
}
/**
* 订单信息
*/
export interface CheckoutOrderResult{
export interface CheckoutOrderResult {
/** 商户订单号 */
bizOrderNo?: string;
bizOrderNo?: string
/** 订单号 */
orderNo?: string;
orderNo?: string
/** 标题 */
title?: string;
title?: string
/** 描述 */
description?: string;
description?: string
/** 金额(元) */
amount?: string;
amount?: string
}
/**
* 收银台配置信息
*/
export interface CheckoutConfigResult{
export interface CheckoutConfigResult {
/** 收银台名称 */
name?: string;
name?: string
/** PC收银台是否同时显示聚合收银码 */
aggregateShow?: boolean;
aggregateShow?: boolean
/** h5收银台自动升级聚合支付 */
h5AutoUpgrade?: boolean;
h5AutoUpgrade?: boolean
}
/**
* 收银台聚合配置信息
*/
export interface AggregateConfigResult{
export interface AggregateConfigResult {
/** 支付类型 */
type?: string;
type?: string
/** 通道 */
channel?: string;
channel?: string
/** 支付方式 */
payMethod?: string;
payMethod?: string
/** 自动拉起支付 */
autoLaunch?: boolean;
autoLaunch?: boolean
}
/**
* 收银台支付结果
*/
export interface CheckoutPayResult{
export interface CheckoutPayResult {
/**
* 链接
*/
url?: string;
url?: string
/**
* 支付状态
*/
payStatus?: string;
payStatus?: string
}

View File

@@ -20,28 +20,28 @@
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { showNotify } from 'vant'
import type {
CashierPayParam,
CashierTypeConfigResult,
} from '@/views/daxpay/cashier/CashierCode.api'
import {
cashierPay,
getCashierTypeConfig,
} from '@/views/daxpay/cashier/CashierCode.api'
import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum'
import { AggregateTypeEnum } from '@/enums/daxpay/DaxPayEnum'
import router from '@/router'
import {getAggregateConfig} from "@/views/daxpay/checkout/CheckoutPay.api";
import {
AggregateOrderAndConfigResult, checkoutPay, CheckoutPayParam,
} from '@/views/daxpay/checkout/CheckoutPay.api'
import {
getAggregateConfig,
} from '@/views/daxpay/checkout/CheckoutPay.api'
const route = useRoute()
const { orderNo } = route.params
const loading = ref<boolean>(false)
const cashierInfo = ref<CashierTypeConfigResult>({})
const cashierInfo = ref<AggregateOrderAndConfigResult>({
aggregateConfig: {},
config: {},
order: {},
})
const amount = ref<string>('0')
const description = ref<string>('')
onMounted(() => {
initData()
})
@@ -50,7 +50,7 @@ onMounted(() => {
* 初始化数据
*/
function initData() {
getAggregateConfig(orderNo, wechat).then(({ data }) => {
getAggregateConfig(orderNo, AggregateTypeEnum.ALIPAY).then(({ data }) => {
cashierInfo.value = data
}).catch((res) => {
router.push({ name: 'ErrorResult', query: { msg: res.message } })
@@ -68,16 +68,11 @@ function pay() {
}
loading.value = true
const from = {
amount: amountValue,
Code: code,
cashierType: CashierTypeEnum.ALIPAY,
description: description.value,
} as CashierPayParam
cashierPay(from)
} as CheckoutPayParam
checkoutPay(from)
.then(({ data }) => {
loading.value = false
// 跳转到H5/付款码支付页面
location.replace(data.payBody)
})
}
</script>