Skip to content

Commit

Permalink
feat: 添加服务商创建电子发票模板接口
Browse files Browse the repository at this point in the history
  • Loading branch information
jay committed Aug 21, 2024
1 parent e339ac9 commit a7258a7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,14 @@ refundedCallbackOfPartner (certs: Map<string, string>, apiKey: string, req: Requ
#### 服务商电子发票
##### 服务商创建电子发票卡券模板
> [参考文档](https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-card-template/create-fapiao-card-template.html)
```javascript
createCardTemplateOfPartner (data: CreateCardTemplateRequestOfPartner, spMchId: string, serialNo: string, privateKey: Buffer | string);
```
##### 服务商配置开发选项
> [参考文档](https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-merchant/update-development-config.html)
Expand Down
8 changes: 8 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,14 @@ refundedCallbackOfPartner (certs: Map<string, string>, apiKey: string, req: Requ
#### 服务商电子发票
##### 服务商创建电子发票卡券模板
> [参考文档](https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-card-template/create-fapiao-card-template.html)
```javascript
createCardTemplateOfPartner (data: CreateCardTemplateRequestOfPartner, spMchId: string, serialNo: string, privateKey: Buffer | string);
```
##### 服务商配置开发选项
> [参考文档](https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-merchant/update-development-config.html)
Expand Down
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- [查询单笔退款](README.md#服务商查询单笔退款)
- [退款结果通知](README.md#服务商退款结果通知)
- [电子发票](README.md#服务商电子发票)
- [服务商创建电子发票卡券模板](README.md#服务商创建电子发票卡券模板)
- [配置开发选项](README.md#服务商配置开发选项)
- [查询商户配置的开发选项](README.md#服务商查询商户配置的开发选项)
- [微信发票通知](README.md#服务商微信发票通知)
Expand Down
6 changes: 5 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 { DevelopmentConfigRequest, FapiaoNotifyResult, IssueFapiaoRequest, RefundNotifyResult, RefundParameters, ReverseFapiaoRequest, Trade, TransactionOrder } from './wepay';
import { CreateCardTemplateRequest, DevelopmentConfigRequest, FapiaoNotifyResult, IssueFapiaoRequest, RefundNotifyResult, RefundParameters, ReverseFapiaoRequest, Trade, TransactionOrder } from './wepay';

/**
* 微信支付服务务下单数据结构
Expand Down Expand Up @@ -116,4 +116,8 @@ export interface ReverseFapiaoRequestOfPartner extends ReverseFapiaoRequest {
sub_mchid: string;
}

export interface CreateCardTemplateRequestOfPartner extends CreateCardTemplateRequest {
sub_mchid: string;
}

/** 电子发票 **/
17 changes: 16 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 { DevelopmentConfigRequestOfPartner, FapiaoNotifyResultOfPartner, IssueFapiaoRequestOfPartner, RefundNotifyResultOfPartner, RefundParametersOfPartner, ReverseFapiaoRequestOfPartner, TradeOfPartner, TransactionOrderOfPartner } from './types/wepay-partner';
import { CreateCardTemplateRequestOfPartner, DevelopmentConfigRequestOfPartner, FapiaoNotifyResultOfPartner, IssueFapiaoRequestOfPartner, RefundNotifyResultOfPartner, RefundParametersOfPartner, ReverseFapiaoRequestOfPartner, TradeOfPartner, TransactionOrderOfPartner } from './types/wepay-partner';
@Injectable()
export class WePayService {

Expand Down Expand Up @@ -473,6 +473,21 @@ export class WePayService {
});
}

/**
* 服务商创建电子发票卡券模板
*
* @link https://pay.weixin.qq.com/docs/partner/apis/fapiao/fapiao-card-template/create-fapiao-card-template.html
*/
async createCardTemplateOfPartner (data: CreateCardTemplateRequestOfPartner, spMchId: string, serialNo: string, privateKey: Buffer | string) {
const url = '/v3/new-tax-control-fapiao/card-template';
const nonceStr = createNonceStr();
const timestamp = Math.floor(Date.now() / 1000);
const signature = this.generateSignature('POST', url, timestamp, nonceStr, privateKey, data);
return axios.post<CreateCardTemplateResponse>(this.API_ROOT + url, data, {
headers: this.generateHeader(spMchId, nonceStr, timestamp, serialNo, signature),
});
}

/**
* 微信发票通知
* @link https://pay.weixin.qq.com/docs/merchant/apis/fapiao/fapiao-card-template/user-invoice-rise-write-notice.html
Expand Down

0 comments on commit a7258a7

Please sign in to comment.