-
Notifications
You must be signed in to change notification settings - Fork 3
/
pay_by_link.go
86 lines (69 loc) · 2.09 KB
/
pay_by_link.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
package adapter
import (
"context"
"fmt"
"net/http"
)
type PayByLink struct {
Client *Client
}
func (api *PayByLink) CreateProduct(ctx context.Context, request CreateProductRequest) (*ProductResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, "/craftlink/v1/products", request)
if err != nil {
return nil, err
}
response := &Response[ProductResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *PayByLink) UpdateProduct(ctx context.Context, id int64, request UpdateProductRequest) (*ProductResponse, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodPut, fmt.Sprintf("/craftlink/v1/products/%d", id), request)
if err != nil {
return nil, err
}
response := &Response[ProductResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *PayByLink) RetrieveProduct(ctx context.Context, id int64) (interface{}, error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("/craftlink/v1/products/%d", id), nil)
if err != nil {
return nil, err
}
response := &Response[ProductResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}
func (api *PayByLink) DeleteProduct(ctx context.Context, id int64) error {
newRequest, err := api.Client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("/craftlink/v1/products/%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 *PayByLink) SearchProducts(ctx context.Context, request SearchProductsRequest) (*DataResponse[ProductResponse], error) {
newRequest, err := api.Client.NewRequest(ctx, http.MethodGet, "/craftlink/v1/products", request)
if err != nil {
return nil, err
}
response := &Response[DataResponse[ProductResponse]]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return nil, err
}
return response.Data, nil
}