Commit d1795a92 by xuzhenzhao

feat(custom): payment

add appId params
parents 99791184 8ea52f9b
...@@ -98,6 +98,10 @@ export type ToPayParams = { ...@@ -98,6 +98,10 @@ export type ToPayParams = {
*/ */
openId?: string; openId?: string;
appId?: string; appId?: string;
/**
* 支付记录id, 采用余额支付的时候如果前端有此值就带过来
*/
payId?: number;
} }
export enum PayError { export enum PayError {
......
import {IS_PAY, MY_BALANCE, UNIT_PAY} from "./API"; import {UNIT_PAY, IS_PAY, MY_BALANCE} from "./API";
import md5 from 'blueimp-md5' import md5 from 'blueimp-md5'
import qs from 'qs' import qs from 'qs'
import {Utils} from "@/Utils/Utils"; import {Utils} from "@/Utils/Utils";
...@@ -145,8 +145,8 @@ export class Payment { ...@@ -145,8 +145,8 @@ export class Payment {
return {payAmount, payBalance} return {payAmount, payBalance}
} }
public async toPay(params: ToPayParams): Promise<ToPayReturns> { async toPay(params: ToPayParams): Promise<ToPayReturns> {
const {totalAmount, payType, returnUrl, orderId, redirectUrl, openId, appId,} = params const {totalAmount, payType, returnUrl, orderId, redirectUrl, openId, appId, payId,} = params
let quitUrl = params.quitUrl let quitUrl = params.quitUrl
// validate start >>> // validate start >>>
switch (payType) { switch (payType) {
...@@ -233,6 +233,7 @@ export class Payment { ...@@ -233,6 +233,7 @@ export class Payment {
payType, payType,
openId, openId,
appId, appId,
payId,
...this.computeAmount(totalAmount, this.balance), ...this.computeAmount(totalAmount, this.balance),
} }
if (payChannel !== null) { if (payChannel !== null) {
...@@ -240,8 +241,8 @@ export class Payment { ...@@ -240,8 +241,8 @@ export class Payment {
} }
const res = await requestForJava.post<DoUnifiedParams, DefaultResponse>(UNIT_PAY, doUnifiedParams) const res = await requestForJava.post<DoUnifiedParams, DefaultResponse>(UNIT_PAY, doUnifiedParams)
if (res.code !== '200') return {errorMessage: res.msg as any, success: false, errorType: PayError.BACKEND} if (res.code !== '200') return {errorMessage: res.msg as any, success: false, errorType: PayError.BACKEND}
if (params.payType === PayType.BALANCE && res.data.balancePayResult) { if (params.payType === PayType.BALANCE && res.data) {
return {success: res.data.balancePayResult === 'true', errorType: PayError.BALANCE} return {success: res.data.result, errorType: PayError.BALANCE}
} else if (payChannel === PayChannel.WX_JSAPI) { } else if (payChannel === PayChannel.WX_JSAPI) {
const isPaySucc = await this.wechatPayJSSDK(res.data) const isPaySucc = await this.wechatPayJSSDK(res.data)
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment