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
Push — master ( e85afa...c66c0b )
by Victor Hugo
01:09 queued 11s
created

mollie.*ChargebacksService.list   A

Complexity

Conditions 4

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 10
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 4
rs 9.9
c 0
b 0
f 0
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
// Chargeback describes a forced transaction reversal initiated by the cardholder's bank
13
type Chargeback struct {
14
	Resource         string           `json:"resource,omitempty"`
15
	ID               string           `json:"id,omitempty"`
16
	Amount           *Amount          `json:"amount,omitempty"`
17
	SettlementAmount *Amount          `json:"settlementAmount,omitempty"`
18
	CreatedAt        *time.Time       `json:"createdAt,omitempty"`
19
	ReversedAt       *time.Time       `json:"reversedAt,omitempty"`
20
	ChargebackID     string           `json:"chargebackId,omitempty"`
21
	Links            *ChargebackLinks `json:"_links,omitempty"`
22
}
23
24
// ChargebackLinks describes all the possible links to be returned with
25
// a chargeback object.
26
type ChargebackLinks struct {
27
	Self          URL `json:"self,omitempty"`
28
	Chargeback    URL `json:"chargeback,omitempty"`
29
	Settlement    URL `json:"settlement,omitempty"`
30
	Documentation URL `json:"documentation,omitempty"`
31
}
32
33
// ChargebackOptions describes chargeback endpoint valid query string parameters.
34
type ChargebackOptions struct {
35
	Include string `url:"include,omitempty"`
36
	Embed   string `url:"embed,omitempty"`
37
}
38
39
// ListChargebackOptions describes list chargebacks endpoint valid query string parameters.
40
type ListChargebackOptions struct {
41
	Include   string `url:"include,omitempty"`
42
	Embed     string `url:"embed,omitempty"`
43
	ProfileID string `url:"profileId,omitempty"`
44
}
45
46
// ChargebackList describes how a list of chargebacks will be retrieved by Mollie.
47
type ChargebackList struct {
48
	Count    int `json:"count,omitempty"`
49
	Embedded struct {
50
		Chargebacks []Chargeback
51
	} `json:"_embedded,omitempty"`
52
	Links PaginationLinks `json:"_links,omitempty"`
53
}
54
55
// ChargebacksService instance operates over chargeback resources
56
type ChargebacksService service
57
58
// Get retrieves a single chargeback by its ID.
59
// Note the original payment’s ID is needed as well.
60
//
61
// See: https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback
62
func (cs *ChargebacksService) Get(paymentID, chargebackID string, options *ChargebackOptions) (p Chargeback, err error) {
63 1
	u := fmt.Sprintf("v2/payments/%s/chargebacks/%s", paymentID, chargebackID)
64 1
	if options != nil {
65 1
		v, _ := query.Values(options)
66 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
67
	}
68 1
	req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil)
69 1
	if err != nil {
70 1
		return
71
	}
72 1
	res, err := cs.client.Do(req)
73 1
	if err != nil {
74 1
		return
75
	}
76 1
	if err = json.Unmarshal(res.content, &p); err != nil {
77 1
		return
78
	}
79 1
	return
80
}
81
82
// List retrieves a list of chargebacks associated with your account/organization.
83
//
84
// See: https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks
85
func (cs *ChargebacksService) List(options *ListChargebackOptions) (cl *ChargebackList, err error) {
86 1
	u := fmt.Sprint("v2/chargebacks")
87 1
	if options != nil {
88 1
		v, _ := query.Values(options)
89 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
90
	}
91 1
	return cs.list(u)
92
}
93
94
// ListForPayment retrieves a list of chargebacks associated with a single payment.
95
//
96
// See: https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks
97
func (cs *ChargebacksService) ListForPayment(paymentID string, options *ListChargebackOptions) (cl *ChargebackList, err error) {
98 1
	u := fmt.Sprintf("v2/payments/%s/chargebacks", paymentID)
99 1
	if options != nil {
100 1
		v, _ := query.Values(options)
101 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
102
	}
103 1
	return cs.list(u)
104
}
105
106
// encapsulates the shared list methods logic
107
func (cs *ChargebacksService) list(uri string) (cl *ChargebackList, err error) {
108 1
	req, err := cs.client.NewAPIRequest(http.MethodGet, uri, nil)
109 1
	if err != nil {
110 1
		return
111
	}
112 1
	res, err := cs.client.Do(req)
113 1
	if err != nil {
114 1
		return
115
	}
116 1
	if err = json.Unmarshal(res.content, &cl); err != nil {
117 1
		return
118
	}
119 1
	return
120
}
121