forked from labring/FastGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
22 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
// @ts-ignore | ||
import Payment from 'wxpay-v3'; | ||
|
||
export const getPayment = () => { | ||
return new Payment({ | ||
export const getPayment = () => | ||
new Payment({ | ||
appid: process.env.WX_APPID, | ||
mchid: process.env.WX_MCHID, | ||
private_key: process.env.WX_PRIVATE_KEY?.replace(/\\n/g, '\n'), | ||
serial_no: process.env.WX_SERIAL_NO, | ||
apiv3_private_key: process.env.WX_V3_CODE, | ||
notify_url: process.env.WX_NOTIFY_URL | ||
}); | ||
}; | ||
|
||
export const nativePay = (amount: number, payId: string): Promise<string> => | ||
getPayment() | ||
.native({ | ||
export const nativePay = async (amount: number, payId: string) => { | ||
try { | ||
const res = await getPayment().native({ | ||
description: 'Fast GPT 余额充值', | ||
out_trade_no: payId, | ||
amount: { | ||
total: amount | ||
} | ||
}) | ||
.then((res: any) => JSON.parse(res.data).code_url); | ||
}); | ||
return JSON.parse(res.data).code_url as string; | ||
} catch (error) { | ||
return Promise.reject(error); | ||
} | ||
}; | ||
|
||
export const getPayResult = (payId: string) => | ||
getPayment() | ||
.getTransactionsByOutTradeNo({ | ||
export const getPayResult = async (payId: string) => { | ||
try { | ||
const res = await getPayment().getTransactionsByOutTradeNo({ | ||
out_trade_no: payId | ||
}) | ||
.then((res: any) => JSON.parse(res.data)); | ||
}); | ||
|
||
return JSON.parse(res.data); | ||
} catch (error) { | ||
return Promise.reject(error); | ||
} | ||
}; |