feat(pay): 支持企业发票购方类型与税号传参
This commit is contained in:
parent
e0a30e6040
commit
f998dfec8c
@ -16,7 +16,9 @@ type InvoiceRequestOrder struct {
|
||||
// InvoiceRequestParam 申请开发票参数
|
||||
type InvoiceRequestParam struct {
|
||||
UserName string `json:"user_name"`
|
||||
BuyerType int64 `json:"buyer_type"` // 0/1=个人,2=企业
|
||||
BuyerName string `json:"buyer_name"`
|
||||
BuyerTaxNo string `json:"buyer_tax_no"` // 企业购方税号
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
RequestName string `json:"request_name"`
|
||||
@ -30,7 +32,9 @@ type InvoiceRequestParam struct {
|
||||
type InvoiceRequestRequest struct {
|
||||
*requests.JsonRequest
|
||||
UserName string `position:"Json" field:"user_name"`
|
||||
BuyerType int64 `position:"Json" field:"buyer_type"`
|
||||
BuyerName string `position:"Json" field:"buyer_name"`
|
||||
BuyerTaxNo string `position:"Json" field:"buyer_tax_no"`
|
||||
Email string `position:"Json" field:"email"`
|
||||
Phone string `position:"Json" field:"phone"`
|
||||
RequestName string `position:"Json" field:"request_name"`
|
||||
@ -52,7 +56,9 @@ func CreateInvoiceRequestRequest(param InvoiceRequestParam) *InvoiceRequestReque
|
||||
req := &InvoiceRequestRequest{
|
||||
JsonRequest: &requests.JsonRequest{},
|
||||
UserName: param.UserName,
|
||||
BuyerType: param.BuyerType,
|
||||
BuyerName: param.BuyerName,
|
||||
BuyerTaxNo: param.BuyerTaxNo,
|
||||
Email: param.Email,
|
||||
Phone: param.Phone,
|
||||
RequestName: param.RequestName,
|
||||
|
||||
54
services/pay/invoice_test.go
Normal file
54
services/pay/invoice_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||
)
|
||||
|
||||
func TestCreateInvoiceRequestRequestBuyerFields(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
buyerType int64
|
||||
buyerName string
|
||||
buyerTaxNo string
|
||||
}{
|
||||
{name: "企业抬头", buyerType: 2, buyerName: "测试企业", buyerTaxNo: "91310100MA1K123456"},
|
||||
{name: "个人抬头", buyerType: 1, buyerName: "张三"},
|
||||
{name: "旧版个人抬头", buyerName: "张三"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
req := CreateInvoiceRequestRequest(InvoiceRequestParam{
|
||||
BuyerType: tt.buyerType,
|
||||
BuyerName: tt.buyerName,
|
||||
BuyerTaxNo: tt.buyerTaxNo,
|
||||
})
|
||||
initErr := requests.InitParam(req)
|
||||
if initErr != nil {
|
||||
t.Fatal(initErr)
|
||||
}
|
||||
body, readErr := io.ReadAll(req.GetBodyReader())
|
||||
if readErr != nil {
|
||||
t.Fatal(readErr)
|
||||
}
|
||||
var payload map[string]any
|
||||
decodeErr := json.Unmarshal(body, &payload)
|
||||
if decodeErr != nil {
|
||||
t.Fatal(decodeErr)
|
||||
}
|
||||
if payload["buyer_type"] != float64(tt.buyerType) || payload["buyer_name"] != tt.buyerName {
|
||||
t.Fatalf("抬头字段不匹配:%s", body)
|
||||
}
|
||||
if tt.buyerTaxNo != "" && payload["buyer_tax_no"] != tt.buyerTaxNo {
|
||||
t.Fatalf("购方税号未透传:%s", body)
|
||||
}
|
||||
if tt.buyerTaxNo == "" && payload["buyer_tax_no"] != nil {
|
||||
t.Fatalf("个人抬头不应携带购方税号:%s", body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user