Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改支付退款结果回调url #7

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/service/CoaWxPayIsvService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class CoaWxPayIsvService {

// 微信支付统一下单
async unifiedOrder(data: {
accountId: string
orderId: string
price: number
appWxaId: string
Expand Down Expand Up @@ -68,7 +69,7 @@ export class CoaWxPayIsvService {
data.price ||
CoaError.message('CoaWxPayIsv.MissingField', '缺少order price'),
spbill_create_ip: '1.1.1.1',
notify_url: `${this.bin.config.notifyPay}.${data.orderId}`,
notify_url: `${this.bin.config.notifyPay}.${data.accountId || CoaError.message('CoaWxPayIsv.MissingField', '缺少accountId')}.${data.orderId}`,
trade_type: 'JSAPI',
}
const body = await this.bin.toSignedXmlParams(param)
Expand All @@ -77,6 +78,7 @@ export class CoaWxPayIsvService {

// 退款
async payRefund(data: {
accountId: string
refundId: string
orderId: string
totalPrice: number
Expand All @@ -85,6 +87,8 @@ export class CoaWxPayIsvService {
}) {
const rawData =
data.rawData || CoaError.message('CoaWxPayIsv.MissingField', '数据不存在')
const accountId =
data.accountId || CoaError.message('CoaWxPayIsv.MissingField', '缺少账户ID')
const refundId =
data.refundId ||
CoaError.message('CoaWxPayIsv.MissingField', '缺少退款ID')
Expand All @@ -96,6 +100,7 @@ export class CoaWxPayIsvService {
const refundPrice =
data.refundPrice ||
CoaError.message('CoaWxPayIsv.MissingField', '缺少退款价格')

const param = {
appid: this.bin.config.appId,
mch_id: this.bin.config.mchId,
Expand Down Expand Up @@ -124,7 +129,7 @@ export class CoaWxPayIsvService {
out_refund_no: refundId,
total_fee: totalPrice,
refund_fee: refundPrice,
notify_url: `${this.bin.config.notifyRefund}.${orderId}`,
notify_url: `${this.bin.config.notifyRefund}.${accountId}.${orderId}`,
}
const body = await this.bin.toSignedXmlParams(param)
return await this.bin.post('/secapi/pay/refund', body, {
Expand Down
2 changes: 2 additions & 0 deletions src/test/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const service = new CoaWxPayIsvService(bin)

// 统一下单
await service.unifiedOrder({
accountId: 'account000001',
orderId: 'order000001',
appWxaId: 'wx000000002',
subMchId: '1660000001',
Expand All @@ -41,6 +42,7 @@ await service.queryOrder({

// 退款
await service.payRefund({
accountId: 'account000001',
refundId: 'refund000001',
orderId: 'order000001',
price: 100,
Expand Down