Skip to content

Commit

Permalink
feat: 新增服务商配置电子发票开发选项
Browse files Browse the repository at this point in the history
  • Loading branch information
jay committed Jul 15, 2024
1 parent 8f78231 commit a82d7a9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/types/wepay-partner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequireOnlyOne } from '.';
import { RefundNotifyResult, RefundParameters, Trade, TransactionOrder } from './wepay';
import { DevelopmentConfigRequest, RefundNotifyResult, RefundParameters, Trade, TransactionOrder } from './wepay';

/**
* 微信支付服务务下单数据结构
Expand Down Expand Up @@ -88,3 +88,17 @@ export interface RefundNotifyResultOfPartner extends Omit<RefundNotifyResult, 'm
*/
sub_mchid: string;
}

/** 电子发票 **/

/**
* 配置开发选项
*/
export interface DevelopmentConfigRequestOfPartner extends DevelopmentConfigRequest {
/**
* 【子商户号】 微信支付分配的子商户号,服务商为子商户设置全部账单展示发票入口开关时必填
*/
sub_mch_code?: string;
}

/** 电子发票 **/
47 changes: 46 additions & 1 deletion lib/wepay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { createNonceStr } from './utils';

import type { Request, Response } from 'express';
import { XMLBuilder } from 'fast-xml-parser';
import { RefundNotifyResultOfPartner, RefundParametersOfPartner, TradeOfPartner, TransactionOrderOfPartner } from './types/wepay-partner';
import { DevelopmentConfigRequestOfPartner, RefundNotifyResultOfPartner, RefundParametersOfPartner, TradeOfPartner, TransactionOrderOfPartner } from './types/wepay-partner';
@Injectable()
export class WePayService {

Expand Down Expand Up @@ -413,6 +413,51 @@ export class WePayService {
});
}

/**
* 查询商户配置的开发选项
*
* @link https://pay.weixin.qq.com/docs/merchant/apis/fapiao/fapiao-merchant/query-development-config.html
*/
async getFapiaoDevConfig (mchId: string, serialNo: string, privateKey: Buffer | string) {
const url = '/v3/new-tax-control-fapiao/merchant/development-config';
const nonceStr = createNonceStr();
const timestamp = Math.floor(Date.now() / 1000);
const signature = this.generateSignature('GET', url, timestamp, nonceStr, privateKey);
return axios.get<DevelopmentConfigRequest>(this.API_ROOT + url, {
headers: this.generateHeader(mchId, nonceStr, timestamp, serialNo, signature),
});
}

/**
* 服务端为特约商户配置开发选项
*
* @link https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-merchant/update-development-config.html
*/
async fapiaoDevConfigOfPartner (data: DevelopmentConfigRequestOfPartner, spMchId: string, serialNo: string, privateKey: Buffer | string) {
const url = '/v3/new-tax-control-fapiao/merchant/development-config';
const nonceStr = createNonceStr();
const timestamp = Math.floor(Date.now() / 1000);
const signature = this.generateSignature('PATCH', url, timestamp, nonceStr, privateKey, data);
return axios.patch<DevelopmentConfigRequest>(this.API_ROOT + url, data, {
headers: this.generateHeader(spMchId, nonceStr, timestamp, serialNo, signature),
});
}

/**
* 服务商查询商户配置的开发选项
*
* @link https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-merchant/query-development-config.html
*/
async getFapiaoDevConfigOfPartner (spMchId: string, subMchId: string, serialNo: string, privateKey: Buffer | string) {
const url = `/v3/new-tax-control-fapiao/merchant/development-config?sub_mch_code=${subMchId}`;
const nonceStr = createNonceStr();
const timestamp = Math.floor(Date.now() / 1000);
const signature = this.generateSignature('GET', url, timestamp, nonceStr, privateKey);
return axios.get<DevelopmentConfigRequest>(this.API_ROOT + url, {
headers: this.generateHeader(spMchId, nonceStr, timestamp, serialNo, signature),
});
}

/**
* 创建电子发票卡券模板
*
Expand Down

0 comments on commit a82d7a9

Please sign in to comment.