-
Notifications
You must be signed in to change notification settings - Fork 3
/
merchant.go
116 lines (93 loc) · 3.13 KB
/
merchant.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package adapter
import (
"context"
"fmt"
"net/http"
)
type Merchant struct {
Client *Client
}
func (api *Merchant) CreateMerchantPos(ctx context.Context, request CreateMerchantPosRequest) (*MerchantPosResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/merchant/v1/merchant-poses", request)
if err != nil {
return nil, err
}
response := &Response[MerchantPosResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *Merchant) RetrieveMerchantPos(ctx context.Context, id int64) (*MerchantPosResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/merchant/v1/merchant-poses/%d", id), nil)
if err != nil {
return nil, err
}
response := &Response[MerchantPosResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *Merchant) SearchMerchantPos(ctx context.Context, request SearchMerchantPosRequest) (*DataResponse[MerchantPosResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/merchant/v1/merchant-poses", request)
if err != nil {
return nil, err
}
response := &Response[DataResponse[MerchantPosResponse]]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *Merchant) UpdateMerchantPosStatus(ctx context.Context, id int64, status PosStatus) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("/merchant/v1/merchant-poses/%d/status/%s", id, status), nil)
if err != nil {
return err
}
response := &Void{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return err
}
return nil
}
func (api *Merchant) DeleteMerchantPosStatus(ctx context.Context, id int64) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("/merchant/v1/merchant-poses/%d", id), nil)
if err != nil {
return err
}
response := &Void{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return err
}
return nil
}
func (api *Merchant) RetrieveMerchantPosCommissions(ctx context.Context, id int64) (*DataResponse[MerchantPosCommissionResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/merchant/v1/merchant-poses/%d/commissions", id), nil)
if err != nil {
return nil, err
}
response := &Response[DataResponse[MerchantPosCommissionResponse]]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *Merchant) UpdateMerchantPosCommissions(ctx context.Context, id int64, request CreateMerchantPosCommissionRequest) (*DataResponse[MerchantPosCommissionResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/merchant/v1/merchant-poses/%d/commissions", id), request)
if err != nil {
return nil, err
}
response := &Response[DataResponse[MerchantPosCommissionResponse]]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}