添加文件: intelligence_finance_v1_ga/example_test.go
This commit is contained in:
parent
593169b85a
commit
38a9505a3b
|
|
@ -0,0 +1,136 @@
|
|||
package intelligence_finance_v1_ga_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
sdk "intelligence_finance_v1_ga"
|
||||
)
|
||||
|
||||
// TestOrderInvoice 演示订单开票接口的调用。
|
||||
func TestOrderInvoice(t *testing.T) {
|
||||
client := sdk.NewClient(
|
||||
"https://api.example.com",
|
||||
"your-tenant-id",
|
||||
"dd-ai-table",
|
||||
"your-client-secret",
|
||||
)
|
||||
|
||||
req := &sdk.OrderInvoiceRequest{
|
||||
OrderID: "ORDER-20240101-001",
|
||||
InvoiceType: sdk.InvoiceTypeDigitalSpecial,
|
||||
Purchaser: "示例科技有限公司",
|
||||
Taxnum: "91330100MA27XXXXXX",
|
||||
Email: "finance@example.com",
|
||||
Phone: "13800000000",
|
||||
Products: []sdk.Product{
|
||||
{
|
||||
ProductName: "软件开发服务",
|
||||
RevenueCode: "3040201000000000000",
|
||||
AmountIncludeTax: "10000.00",
|
||||
Quantity: "1",
|
||||
TaxSign: 1,
|
||||
TaxRate: "0.06",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.OrderInvoice(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("OrderInvoice failed: %v", err)
|
||||
}
|
||||
fmt.Printf("开票状态: %d, 错误信息: %s\n", resp.Status, resp.ErrorMsg)
|
||||
}
|
||||
|
||||
// TestQueryInvoiceStatus 演示开票状态查询接口的调用。
|
||||
func TestQueryInvoiceStatus(t *testing.T) {
|
||||
client := sdk.NewClient(
|
||||
"https://api.example.com",
|
||||
"your-tenant-id",
|
||||
"dd-ai-table",
|
||||
"your-client-secret",
|
||||
)
|
||||
|
||||
resp, err := client.QueryInvoiceStatus(context.Background(), &sdk.QueryInvoiceStatusRequest{
|
||||
OrderID: "ORDER-20240101-001",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("QueryInvoiceStatus failed: %v", err)
|
||||
}
|
||||
fmt.Printf("状态: %d, 描述: %s\n", resp.Status, resp.Message)
|
||||
}
|
||||
|
||||
// TestCreatePaymentOrder 演示创建付款单据接口的调用。
|
||||
func TestCreatePaymentOrder(t *testing.T) {
|
||||
client := sdk.NewClient(
|
||||
"https://api.example.com",
|
||||
"your-tenant-id",
|
||||
"dd-ai-table",
|
||||
"your-client-secret",
|
||||
)
|
||||
|
||||
req := &sdk.CreatePaymentOrderRequest{
|
||||
Code: "PAY-20240101-001",
|
||||
UserID: "user-001",
|
||||
Title: "供应商货款",
|
||||
Amount: "10000.00",
|
||||
Supplier: &sdk.Supplier{
|
||||
Name: "示例供应商",
|
||||
},
|
||||
Company: &sdk.Company{
|
||||
Name: "示例企业",
|
||||
},
|
||||
PaymentDetailList: []sdk.PaymentDetail{
|
||||
{
|
||||
Amount: "10000.00",
|
||||
Remark: "货款",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.CreatePaymentOrder(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePaymentOrder failed: %v", err)
|
||||
}
|
||||
fmt.Printf("单据编码: %s\n", resp.Code)
|
||||
}
|
||||
|
||||
// TestQueryPaymentStatus 演示支付状态查询接口的调用。
|
||||
func TestQueryPaymentStatus(t *testing.T) {
|
||||
client := sdk.NewClient(
|
||||
"https://api.example.com",
|
||||
"your-tenant-id",
|
||||
"dd-ai-table",
|
||||
"your-client-secret",
|
||||
)
|
||||
|
||||
resp, err := client.QueryPaymentStatus(context.Background(), &sdk.QueryPaymentStatusRequest{
|
||||
Code: "PAY-20240101-001",
|
||||
UserID: "user-001",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("QueryPaymentStatus failed: %v", err)
|
||||
}
|
||||
fmt.Printf("支付状态: %s, 支付时间: %s\n", resp.PaymentStatus, resp.PaymentTime)
|
||||
}
|
||||
|
||||
// TestParsePaymentNotify 演示支付完成通知的解析(客户回调接口中使用)。
|
||||
func TestParsePaymentNotify(t *testing.T) {
|
||||
body := []byte(`{
|
||||
"code": "PAY-20240101-001",
|
||||
"instanceId": "inst-001",
|
||||
"corpId": "corp-001",
|
||||
"paymentStatus": "SUCCESS",
|
||||
"paymentTime": "2024-01-01 12:00:00",
|
||||
"userId": "user-001",
|
||||
"source": "openapi",
|
||||
"amount": "10000.00"
|
||||
}`)
|
||||
|
||||
data, err := sdk.ParsePaymentNotify(body)
|
||||
if err != nil {
|
||||
t.Fatalf("ParsePaymentNotify failed: %v", err)
|
||||
}
|
||||
fmt.Printf("支付状态: %s\n", data.PaymentStatus)
|
||||
}
|
||||
Loading…
Reference in New Issue