-
Notifications
You must be signed in to change notification settings - Fork 10
/
payment_gateway.go
68 lines (57 loc) · 1.9 KB
/
payment_gateway.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
package woocommerce
import (
"fmt"
"github.com/hiscaler/woocommerce-go/entity"
jsoniter "github.com/json-iterator/go"
)
type paymentGatewayService service
func (s paymentGatewayService) All() (items []entity.PaymentGateway, err error) {
resp, err := s.httpClient.R().Get("/payment_gateways")
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &items)
}
return
}
// One retrieve a payment gateway
func (s paymentGatewayService) One(id string) (item entity.PaymentGateway, err error) {
resp, err := s.httpClient.R().Get(fmt.Sprintf("/payment_gateways/%s", id))
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &item)
}
return
}
// Update
type UpdatePaymentGatewayRequest struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Order int `json:"order,omitempty"`
Enabled bool `json:"enabled,omitempty"`
MethodTitle string `json:"method_title,omitempty"`
MethodDescription string `json:"method_description,omitempty"`
MethodSupports []string `json:"method_supports,omitempty"`
Settings map[string]entity.PaymentGatewaySetting `json:"settings,omitempty"`
}
func (m UpdatePaymentGatewayRequest) Validate() error {
return nil
}
func (s paymentGatewayService) Update(id string, req UpdatePaymentGatewayRequest) (item entity.PaymentGateway, err error) {
if err = req.Validate(); err != nil {
return
}
resp, err := s.httpClient.R().
SetBody(req).
Put(fmt.Sprintf("/payment_gateways/%s", id))
if err != nil {
return
}
if resp.IsSuccess() {
err = jsoniter.Unmarshal(resp.Body(), &item)
}
return
}