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 (#121)
by
unknown
01:38
created

mollie.*PaymentsService.List   A

Complexity

Conditions 5

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 14
dl 0
loc 18
c 0
b 0
f 0
ccs 13
cts 13
cp 1
crap 5
rs 9.2333
nop 1
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"net/http"
7
	"time"
8
9
	"github.com/google/go-querystring/query"
10
)
11
12
// PaymentMethod is a payment method supported by Mollie.
13
type PaymentMethod string
14
15
// Supported payment methods
16
const (
17
	Bancontact     PaymentMethod = "bancontact"
18
	BankTransfer   PaymentMethod = "banktransfer"
19
	Belfius        PaymentMethod = "belfius"
20
	CreditCard     PaymentMethod = "creditcard"
21
	DirectDebit    PaymentMethod = "directdebit"
22
	EPS            PaymentMethod = "eps"
23
	GiftCard       PaymentMethod = "giftcard"
24
	GiroPay        PaymentMethod = "giropay"
25
	IDeal          PaymentMethod = "ideal"
26
	KBC            PaymentMethod = "kbc"
27
	KlarnaPayLater PaymentMethod = "klarnapaylater"
28
	KlarnaLiceit   PaymentMethod = "klarnaliceit"
29
	MyBank         PaymentMethod = "mybank"
30
	PayPal         PaymentMethod = "paypal"
31
	PaySafeCard    PaymentMethod = "paysafecard"
32
	PRZelewy24     PaymentMethod = "przelewy24"
33
	Sofort         PaymentMethod = "sofort"
34
)
35
36
// SequenceType indicates which type of payment this is in a recurring sequence.
37
type SequenceType string
38
39
// Valid sequence types
40
const (
41
	OneOffSequence    SequenceType = "oneoff"
42
	FirstSequence     SequenceType = "first"
43
	RecurringSequence SequenceType = "recurring"
44
)
45
46
// Payment describes a transaction between a customer and a merchant
47
type Payment struct {
48
	Resource                        string          `json:"resource,omitempty"`
49
	ID                              string          `json:"id,omitempty"`
50
	Testmode                        bool            `json:"testmode,omitempty"`
51
	CreatedAt                       *time.Time      `json:"createdAt,omitempty"`
52
	Status                          string          `json:"status,omitempty"`
53
	IsCancellable                   bool            `json:"isCancellable,omitempty"`
54
	AuthorizedAt                    *time.Time      `json:"authorizedAt,omitempty"`
55
	PaidAt                          *time.Time      `json:"paidAt,omitempty"`
56
	CanceledAt                      *time.Time      `json:"canceledAt,omitempty"`
57
	ExpiresAt                       *time.Time      `json:"expiresAt,omitempty"`
58
	ExpiredAt                       *time.Time      `json:"expiredAt,omitempty"`
59
	FailedAt                        *time.Time      `json:"failedAt,omitempty"`
60
	Amount                          *Amount         `json:"amount,omitempty"`
61
	AmountRefunded                  *Amount         `json:"amountRefunded,omitempty"`
62
	AmountRemaining                 *Amount         `json:"amountRemaining,omitempty"`
63
	AmountCaptured                  *Amount         `json:"amountCaptured,omitempty"`
64
	Description                     string          `json:"description,omitempty"`
65
	RedirectURL                     string          `json:"redirectUrl,omitempty"`
66
	WebhookURL                      string          `json:"webhookUrl,omitempty"`
67
	Method                          PaymentMethod   `json:"method,omitempty"`
68
	Metadata                        interface{}     `json:"metadata,omitempty"`
69
	Locale                          Locale          `json:"locale,omitempty"`
70
	CountryCode                     string          `json:"countryCode,omitempty"`
71
	ProfileID                       string          `json:"profileId,omitempty"`
72
	SettlementAmount                *Amount         `json:"settlementAmount,omitempty"`
73
	SettlementID                    string          `json:"settlementId,omitempty"`
74
	CustomerID                      string          `json:"customerId,omitempty"`
75
	SequenceType                    SequenceType    `json:"sequenceType,omitempty"`
76
	MandateID                       string          `json:"mandateId,omitempty"`
77
	OrderID                         string          `json:"orderId,omitempty"`
78
	ApplicationFee                  *ApplicationFee `json:"applicationFee,omitempty"`
79
	Links                           PaymentLinks    `json:"_links,omitempty"`
80
	Details                         *PaymentDetails `json:"details,omitempty"`
81
	RestrictPaymentMethodsToCountry Locale          `json:"restrictPaymentMethodsToCountry,omitempty"`
82
	SubscriptionID                  string          `json:"subscriptionId,omitempty"`
83
}
84
85
// PaymentLinks describes all the possible links to be returned with
86
// a payment object.
87
type PaymentLinks struct {
88
	Self               *URL `json:"self,omitempty"`
89
	Checkout           *URL `json:"checkout,omitempty"`
90
	ChangePaymentState *URL `json:"changePaymentState,omitempty"`
91
	Refunds            *URL `json:"refunds,omitempty"`
92
	ChargeBacks        *URL `json:"chargebacks,omitempty"`
93
	Captures           *URL `json:"captures,omitempty"`
94
	Settlement         *URL `json:"settlement,omitempty"`
95
	Documentation      *URL `json:"documentation,omitempty"`
96
	Mandate            *URL `json:"mandate,omitempty"`
97
	Subscription       *URL `json:"subscription,omitempty"`
98
	Customer           *URL `json:"customer,omitempty"`
99
	Order              *URL `json:"order,omitempty"`
100
	Dashboard          *URL `json:"dashboard,omitempty"`
101
}
102
103
// PaymentOptions describes payments endpoint valid query string parameters.
104
//
105
// See: https://docs.mollie.com/reference/v2/payments-api/get-payment
106
type PaymentOptions struct {
107
	Include string `url:"include,omitempty"`
108
	Embed   string `url:"embed,omitempty"`
109
}
110
111
// ListPaymentOptions describes list payments endpoint valid query string parameters.
112
type ListPaymentOptions struct {
113
	Include   string `url:"include,omitempty"`
114
	Embed     string `url:"embed,omitempty"`
115
	ProfileID string `url:"profileId,omitempty"`
116
	From      string `url:"from,omitempty"`
117
	Limit     int    `url:"limit,omitempty"`
118
}
119
120
// PaymentsService instance operates over payment resources
121
type PaymentsService service
122
123
// Get retrieves a single payment object by its payment token.
124
func (ps *PaymentsService) Get(id string, options *PaymentOptions) (p Payment, err error) {
125 1
	u := fmt.Sprintf("v2/payments/%s", id)
126 1
	if options != nil {
127 1
		v, _ := query.Values(options)
128 1
		if ps.client.config.testing {
129 1
			v["testmode"] = []string{"true"}
130
		}
131 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
132
	}
133 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
134 1
	if err != nil {
135 1
		return
136
	}
137 1
	res, err := ps.client.Do(req)
138 1
	if err != nil {
139 1
		return
140
	}
141 1
	if err = json.Unmarshal(res.content, &p); err != nil {
142 1
		return
143
	}
144 1
	return
145
}
146
147
// Create stores a new payment object attached to your Mollie account.
148
//
149
// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#
150
func (ps *PaymentsService) Create(p Payment) (np Payment, err error) {
151 1
	if ps.client.config.testing {
152 1
		p.Testmode = true
153
154
	}
155
156 1
	u := "v2/payments"
157 1
	req, err := ps.client.NewAPIRequest(http.MethodPost, u, p)
158 1
	if err != nil {
159 1
		return
160
	}
161
162 1
	res, err := ps.client.Do(req)
163 1
	if err != nil {
164 1
		return
165
	}
166 1
	if err = json.Unmarshal(res.content, &np); err != nil {
167 1
		return
168
	}
169 1
	return
170
}
171
172
// Cancel removes a payment (if possible) from your Mollie account.
173
//
174
// See: https://docs.mollie.com/reference/v2/payments-api/cancel-payment
175
func (ps *PaymentsService) Cancel(id string) (p Payment, err error) {
176 1
	u := fmt.Sprintf("v2/payments/%s", id)
177 1
	req, err := ps.client.NewAPIRequest(http.MethodDelete, u, nil)
178 1
	if err != nil {
179 1
		return
180
	}
181 1
	res, err := ps.client.Do(req)
182 1
	if err != nil {
183 1
		return
184
	}
185 1
	if err = json.Unmarshal(res.content, &p); err != nil {
186 1
		return
187
	}
188 1
	return
189
}
190
191
// Update can be used to update some details of a created payment.
192
//
193
// See: https://docs.mollie.com/reference/v2/payments-api/update-payment#
194
func (ps *PaymentsService) Update(id string, up Payment) (p Payment, err error) {
195 1
	u := fmt.Sprintf("v2/payments/%s", id)
196 1
	req, err := ps.client.NewAPIRequest(http.MethodPatch, u, up)
197 1
	if err != nil {
198 1
		return
199
	}
200 1
	res, err := ps.client.Do(req)
201 1
	if err != nil {
202 1
		return
203
	}
204 1
	if err = json.Unmarshal(res.content, &p); err != nil {
205 1
		return
206
	}
207 1
	return
208
}
209
210
// PaymentList describes how a list of payments will be retrieved by Mollie.
211
type PaymentList struct {
212
	Count    int `json:"count,omitempty"`
213
	Embedded struct {
214
		Payments []Payment
215
	} `json:"_embedded,omitempty"`
216
	Links PaginationLinks `json:"_links,omitempty"`
217
}
218
219
// List retrieves a list of payments associated with your account/organization.
220
//
221
// See: https://docs.mollie.com/reference/v2/payments-api/list-payments
222
func (ps *PaymentsService) List(options *ListPaymentOptions) (pl PaymentList, err error) {
223 1
	u := "v2/payments"
224 1
	if options != nil {
225 1
		v, _ := query.Values(options)
226 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
227
	}
228 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
229 1
	if err != nil {
230 1
		return
231
	}
232 1
	res, err := ps.client.Do(req)
233 1
	if err != nil {
234 1
		return
235
	}
236 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
237 1
		return
238
	}
239 1
	return
240
}
241