feat: expand merchant revenue statistics
This commit is contained in:
@@ -67,3 +67,55 @@ func TestSubmitPostsSignedForm(t *testing.T) {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatsDecodesDetailedResponse(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/pay/stats" {
|
||||
t.Fatalf("path = %s", r.URL.Path)
|
||||
}
|
||||
params := map[string]string{}
|
||||
for key, values := range r.URL.Query() {
|
||||
if len(values) > 0 {
|
||||
params[key] = values[0]
|
||||
}
|
||||
}
|
||||
if !VerifySign(params, "secret") {
|
||||
t.Fatalf("invalid sign: %s", params["sign"])
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"code": 200,
|
||||
"message": "Success",
|
||||
"data": map[string]any{
|
||||
"order_count": 3,
|
||||
"total_order_count": 5,
|
||||
"paid_order_count": 3,
|
||||
"unpaid_order_count": 2,
|
||||
"refunded_order_count": 1,
|
||||
"closed_order_count": 1,
|
||||
"manual_order_count": 1,
|
||||
"total_amount": 17000,
|
||||
"received_amount": 11000,
|
||||
"refund_amount": 6000,
|
||||
"refund_count": 2,
|
||||
"total_fee": 170,
|
||||
"net_amount": 10830,
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, err := NewClient(server.URL, "pid-1", "secret")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := client.Stats(context.Background(), StatsRequest{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resp.TotalOrderCount != 5 || resp.PaidOrderCount != 3 ||
|
||||
resp.RefundedOrderCount != 1 || resp.RefundCount != 2 ||
|
||||
resp.ReceivedAmount != 11000 || resp.NetAmount != 10830 {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user