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:40
created

mollie.*PaymentsService.Get   B

Complexity

Conditions 7

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 18
dl 0
loc 23
ccs 17
cts 17
cp 1
crap 7
rs 8
c 0
b 0
f 0
nop 2
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 1
	} else if ps.client.config.testing {
133 1
		u = fmt.Sprintf("%s?testmode=true", u)
134
	}
135 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
136 1
	if err != nil {
137 1
		return
138
	}
139 1
	res, err := ps.client.Do(req)
140 1
	if err != nil {
141 1
		return
142
	}
143 1
	if err = json.Unmarshal(res.content, &p); err != nil {
144 1
		return
145
	}
146 1
	return
147
}
148
149
// Create stores a new payment object attached to your Mollie account.
150
//
151
// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#
152
func (ps *PaymentsService) Create(p Payment) (np Payment, err error) {
153 1
	if ps.client.config.testing {
154 1
		p.Testmode = true
155
156
	}
157
158 1
	u := "v2/payments"
159 1
	req, err := ps.client.NewAPIRequest(http.MethodPost, u, p)
160 1
	if err != nil {
161 1
		return
162
	}
163
164 1
	res, err := ps.client.Do(req)
165 1
	if err != nil {
166 1
		return
167
	}
168 1
	if err = json.Unmarshal(res.content, &np); err != nil {
169 1
		return
170
	}
171 1
	return
172
}
173
174
// Cancel removes a payment (if possible) from your Mollie account.
175
//
176
// See: https://docs.mollie.com/reference/v2/payments-api/cancel-payment
177
func (ps *PaymentsService) Cancel(id string) (p Payment, err error) {
178 1
	u := fmt.Sprintf("v2/payments/%s", id)
179 1
	if ps.client.config.testing {
180 1
		u = fmt.Sprintf("%s?testmode=true", u)
181
	}
182 1
	req, err := ps.client.NewAPIRequest(http.MethodDelete, u, nil)
183 1
	if err != nil {
184 1
		return
185
	}
186 1
	res, err := ps.client.Do(req)
187 1
	if err != nil {
188 1
		return
189
	}
190 1
	if err = json.Unmarshal(res.content, &p); err != nil {
191 1
		return
192
	}
193 1
	return
194
}
195
196
// Update can be used to update some details of a created payment.
197
//
198
// See: https://docs.mollie.com/reference/v2/payments-api/update-payment#
199
func (ps *PaymentsService) Update(id string, up Payment) (p Payment, err error) {
200 1
	u := fmt.Sprintf("v2/payments/%s", id)
201 1
	req, err := ps.client.NewAPIRequest(http.MethodPatch, u, up)
202 1
	if err != nil {
203 1
		return
204
	}
205 1
	res, err := ps.client.Do(req)
206 1
	if err != nil {
207 1
		return
208
	}
209 1
	if err = json.Unmarshal(res.content, &p); err != nil {
210 1
		return
211
	}
212 1
	return
213
}
214
215
// PaymentList describes how a list of payments will be retrieved by Mollie.
216
type PaymentList struct {
217
	Count    int `json:"count,omitempty"`
218
	Embedded struct {
219
		Payments []Payment
220
	} `json:"_embedded,omitempty"`
221
	Links PaginationLinks `json:"_links,omitempty"`
222
}
223
224
// List retrieves a list of payments associated with your account/organization.
225
//
226
// See: https://docs.mollie.com/reference/v2/payments-api/list-payments
227
func (ps *PaymentsService) List(options *ListPaymentOptions) (pl PaymentList, err error) {
228 1
	u := "v2/payments"
229 1
	if options != nil {
230 1
		v, _ := query.Values(options)
231 1
		if ps.client.config.testing {
232 1
			v["testmode"] = []string{"true"}
233
		}
234 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
235 1
	} else if ps.client.config.testing {
236 1
		u = fmt.Sprintf("%s?testmode=true", u)
237
	}
238 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
239 1
	if err != nil {
240 1
		return
241
	}
242 1
	res, err := ps.client.Do(req)
243 1
	if err != nil {
244 1
		return
245
	}
246 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
247 1
		return
248
	}
249 1
	return
250
}
251