From f998dfec8c7b845cc6d05ea003300a9e88627419 Mon Sep 17 00:00:00 2001 From: huangqz Date: Tue, 10 Nov 2026 11:04:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(pay):=20=E6=94=AF=E6=8C=81=E4=BC=81?= =?UTF-8?q?=E4=B8=9A=E5=8F=91=E7=A5=A8=E8=B4=AD=E6=96=B9=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=8E=E7=A8=8E=E5=8F=B7=E4=BC=A0=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/pay/invoice.go | 6 ++++ services/pay/invoice_test.go | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 services/pay/invoice_test.go diff --git a/services/pay/invoice.go b/services/pay/invoice.go index db4d8e7..323cbf4 100644 --- a/services/pay/invoice.go +++ b/services/pay/invoice.go @@ -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, diff --git a/services/pay/invoice_test.go b/services/pay/invoice_test.go new file mode 100644 index 0000000..a4c05c2 --- /dev/null +++ b/services/pay/invoice_test.go @@ -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) + } + }) + } +}