-
Notifications
You must be signed in to change notification settings - Fork 4
/
createOrder_example_test.go
47 lines (44 loc) · 1.14 KB
/
createOrder_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Created by Du, Chengbin on 2022/6/15.
*/
package binancepay
import (
"fmt"
"github.com/shopspring/decimal"
"io/ioutil"
"net/http"
"strings"
)
func Example_createOrder() {
req := &CreateOrderV2Request{
Env: Env{
TerminalType: "WEB",
},
MerchantTradeNo: Nonce(),
Currency: "USDT",
OrderAmount: decimal.NewFromFloat(0.01),
Goods: Goods{
GoodsType: "02",
GoodsCategory: "Z000",
ReferenceGoodsId: "test_goods_id",
GoodsName: "test goods",
},
}
client := NewMerchant("", "", nil, logger)
client.httpClient = mockHttpClient(func(request *http.Request) (*http.Response, error) {
return &http.Response{
Body: ioutil.NopCloser(strings.NewReader(`{"status":"SUCCESS","code":"000000","data":{"prepayId":"1234","terminalType":"WEB","expireTime":1655859345000,"qrcodeLink":"","qrContent":"","checkoutUrl":"","deeplink":"","universalUrl":""}}`)),
}, nil
})
var resp Response[CreateOrderV2Result]
err := client.Do(req, &resp)
fmt.Println(err)
fmt.Println(resp.Status)
fmt.Println(resp.Data.TerminalType)
fmt.Println(resp.Data.PrepayId)
// Output:
// <nil>
// SUCCESS
// WEB
// 1234
}