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.
Completed
Pull Request — master (#37)
by Victor Hugo
01:26
created

mollie/captures.go   A

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 8
eloc 52
dl 0
loc 86
c 0
b 0
f 0
ccs 20
cts 20
cp 1
crap 8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mollie.*CapturesService.List 0 16 4
A mollie.*CapturesService.Get 0 16 4
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"net/http"
7
	"time"
8
)
9
10
// CapturesService operates over captures resource
11
type CapturesService service
12
13
// CaptureLinks contains relevant links for a capture object
14
type CaptureLinks struct {
15
	Self          URL `json:"self,omitempty"`
16
	Payment       URL `json:"payment,omitempty"`
17
	Shipment      URL `json:"shipment,omitempty"`
18
	Settlement    URL `json:"settlement,omitempty"`
19
	Documentation URL `json:"documentation,omitempty"`
20
}
21
22
// Capture describes a single capture
23
// Captures are used for payments that have the authorize-then-capture flow
24
type Capture struct {
25
	Resource         string       `json:"resource,omitempty"`
26
	ID               string       `json:"id,omitempty"`
27
	Mode             Mode         `json:"mode,omitempty"`
28
	Amount           Amount       `json:"amount,omitempty"`
29
	SettlementAmount Amount       `json:"settlementAmount,omitempty"`
30
	PaymentID        string       `json:"paymentId,omitempty"`
31
	ShipmentID       string       `json:"shipmentId,omitempty"`
32
	SettlementID     string       `json:"settlementId,omitempty"`
33
	CreatedAt        *time.Time   `json:"createdAt,omitempty"`
34
	Links            CaptureLinks `json:"links,omitempty"`
35
}
36
37
// CapturesList describes a list of captures
38
type CapturesList struct {
39
	Count    int `json:"count,omitempty"`
40
	Embedded struct {
41
		Captures []Capture
42
	} `json:"_embedded,omitempty"`
43
	Links PaginationLinks `json:"_links,omitempty"`
44
}
45
46
// Get retrieves a single capture by its ID.
47
// Note the original payment’s ID is needed as well.
48
//
49
// See: https://docs.mollie.com/reference/v2/captures-api/get-capture
50
func (cs *CapturesService) Get(pID, cID string) (c *Capture, err error) {
51 1
	u := fmt.Sprintf("v2/payments/%s/captures/%s", pID, cID)
52 1
	req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil)
53 1
	if err != nil {
54 1
		return
55
	}
56
57 1
	res, err := cs.client.Do(req)
58 1
	if err != nil {
59 1
		return
60
	}
61
62 1
	if err = json.Unmarshal(res.content, &c); err != nil {
63 1
		return
64
	}
65 1
	return
66
}
67
68
// List retrieves all captures for a certain payment
69
//
70
// See: https://docs.mollie.com/reference/v2/captures-api/list-captures
71
func (cs *CapturesService) List(pID string) (cl *CapturesList, err error) {
72 1
	u := fmt.Sprintf("v2/payments/%s/captures", pID)
73 1
	req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil)
74 1
	if err != nil {
75 1
		return
76
	}
77
78 1
	res, err := cs.client.Do(req)
79 1
	if err != nil {
80 1
		return
81
	}
82
83 1
	if err = json.Unmarshal(res.content, &cl); err != nil {
84 1
		return
85
	}
86 1
	return
87
}
88