GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#46)
by Victor Hugo
01:28
created

mollie/methods.go   A

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 13
eloc 79
dl 0
loc 135
ccs 32
cts 32
cp 1
crap 13
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mollie.*MethodsService.Get 0 18 5
A mollie.*MethodsService.list 0 13 4
A mollie.*MethodsService.All 0 8 2
A mollie.*MethodsService.List 0 8 2
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"net/http"
7
8
	"github.com/google/go-querystring/query"
9
)
10
11
// PaymentMethodInfo describes a single method with details.
12
type PaymentMethodInfo struct {
13
	Resource      string                 `json:"resource,omitempty"`
14
	ID            string                 `json:"id,omitempty"`
15
	Description   string                 `json:"description,omitempty"`
16
	MinimumAmount *Amount                `json:"minimumAmount,omitempty"`
17
	MaximumAmount *Amount                `json:"maximumAmount,omitempty"`
18
	Image         Image                  `json:"image,omitempty"`
19
	Pricing       []PaymentMethodPricing `json:"pricing,omitempty"`
20
	Links         MethodsLinks           `json:"_links,omitempty"`
21
}
22
23
// MethodsLinks describes links attached to methods service responses.
24
type MethodsLinks struct {
25
	Self URL `json:"self,omitempty"`
26
	Docs URL `json:"documentation,omitempty"`
27
}
28
29
// Image describes a generic image resource retrieved by Mollie.
30
type Image struct {
31
	Size1x string `json:"size1X,omitempty"`
32
	Size2X string `json:"size2X,omitempty"`
33
	Svg    string `json:"svg,omitempty"`
34
}
35
36
// PaymentMethodPricing contains information about commissions and fees
37
// applicable to a payment method.
38
type PaymentMethodPricing struct {
39
	Description string  `json:"description,omitempty"`
40
	Fixed       *Amount `json:"fixed,omitempty"`
41
	Variable    string  `json:"variable,omitempty"`
42
}
43
44
// ListMethods describes a list of paginated payment methods.
45
type ListMethods struct {
46
	Count    int `json:"count,omitempty"`
47
	Embedded struct {
48
		Methods []PaymentMethodInfo
49
	} `json:"_embedded,omitempty"`
50
	Links PaginationLinks `json:"_links,omitempty"`
51
}
52
53
// MethodsOptions are applicable query string parameters to methods
54
// service endpoints.
55
type MethodsOptions struct {
56
	Locale    Locale `url:"locale,omitempty"`
57
	Currency  string `url:"currency,omitempty"`
58
	ProfileID string `url:"profileId,omitempty"`
59
	Include   string `url:"include,omitempty"`
60
	// Use for List method only
61
	SequenceType   SequenceType `url:"sequenceType,omitempty"`
62
	Amount         Amount       `url:"amount,omitempty"`
63
	Resource       string       `url:"resource,omitempty"`
64
	BillingCountry string       `url:"billingCountry,omitempty"`
65
	IncludeWallets string       `json:"includeWallets,omitempty"`
66
}
67
68
// MethodsService operates on methods endpoints
69
type MethodsService service
70
71
// Get returns information about the payment method specified by id,
72
// it also receives a pointer to the method options containing applicable
73
// query string parameters
74
//
75
// See: https://docs.mollie.com/reference/v2/methods-api/get-method
76
func (ms *MethodsService) Get(id string, options *MethodsOptions) (pmi *PaymentMethodInfo, err error) {
77 1
	u := fmt.Sprintf("v2/methods/%s", id)
78 1
	if options != nil {
79 1
		v, _ := query.Values(options)
80 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
81
	}
82 1
	req, err := ms.client.NewAPIRequest(http.MethodGet, u, nil)
83 1
	if err != nil {
84 1
		return
85
	}
86 1
	res, err := ms.client.Do(req)
87 1
	if err != nil {
88 1
		return
89
	}
90 1
	if err = json.Unmarshal(res.content, &pmi); err != nil {
91 1
		return
92
	}
93 1
	return
94
}
95
96
// All retrieves all the payment methods enabled for your account/organization
97
//
98
// See: https://docs.mollie.com/reference/v2/methods-api/list-all-methods
99
func (ms *MethodsService) All(options *MethodsOptions) (pm *ListMethods, err error) {
100 1
	u := fmt.Sprintf("v2/methods/all")
101 1
	if options != nil {
102 1
		v, _ := query.Values(options)
103 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
104
	}
105
106 1
	return ms.list(u)
107
}
108
109
// List retrieves all enabled payment methods.
110
// The results are not paginated.
111
//
112
// See: https://docs.mollie.com/reference/v2/methods-api/list-methods
113
func (ms *MethodsService) List(options *MethodsOptions) (pm *ListMethods, err error) {
114 1
	u := fmt.Sprintf("v2/methods")
115 1
	if options != nil {
116 1
		v, _ := query.Values(options)
117 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
118
	}
119
120 1
	return ms.list(u)
121
}
122
123
func (ms *MethodsService) list(uri string) (pm *ListMethods, err error) {
124 1
	req, err := ms.client.NewAPIRequest(http.MethodGet, uri, nil)
125 1
	if err != nil {
126 1
		return
127
	}
128 1
	res, err := ms.client.Do(req)
129 1
	if err != nil {
130 1
		return
131
	}
132 1
	if err = json.Unmarshal(res.content, &pm); err != nil {
133 1
		return
134
	}
135 1
	return
136
}
137