|
1
|
|
|
package mollie |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"encoding/json" |
|
6
|
|
|
"fmt" |
|
7
|
|
|
"time" |
|
8
|
|
|
) |
|
9
|
|
|
|
|
10
|
|
|
// DelayedRoutingDestinationType indicates the destination of the delayed routing. |
|
11
|
|
|
type DelayedRoutingDestinationType string |
|
12
|
|
|
|
|
13
|
|
|
// Possible values for DelayedRoutingDestination. |
|
14
|
|
|
const ( |
|
15
|
|
|
DelayedRoutingDestinationOrganization DelayedRoutingDestinationType = "organization" |
|
16
|
|
|
) |
|
17
|
|
|
|
|
18
|
|
|
// DelayedRoutingDestination represents the destination for delayed routing. |
|
19
|
|
|
type DelayedRoutingDestination struct { |
|
20
|
|
|
Type DelayedRoutingDestinationType `json:"type,omitempty"` |
|
21
|
|
|
OrganizationID string `json:"organizationId,omitempty"` |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
// Route represents a delayed routing associated with a payment. |
|
25
|
|
|
type Route struct { |
|
26
|
|
|
Resource string `json:"resource,omitempty"` |
|
27
|
|
|
ID string `json:"id,omitempty"` |
|
28
|
|
|
PaymentID string `json:"paymentId,omitempty"` |
|
29
|
|
|
Description string `json:"description,omitempty"` |
|
30
|
|
|
Amount Amount `json:"amount,omitempty"` |
|
31
|
|
|
Destination DelayedRoutingDestination `json:"destination,omitempty"` |
|
32
|
|
|
Links RouteLinks `json:"_links,omitempty"` |
|
33
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// RouteLinks represents the links related to a delayed routing. |
|
37
|
|
|
type RouteLinks struct { |
|
38
|
|
|
Self *URL `json:"self,omitempty"` |
|
39
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// PaymentRoutesList represents a list of delayed routings for a payment. |
|
43
|
|
|
type PaymentRoutesList struct { |
|
44
|
|
|
Count int `json:"count,omitempty"` |
|
45
|
|
|
Embedded struct { |
|
46
|
|
|
Routes []Route `json:"routes,omitempty"` |
|
47
|
|
|
} `json:"_embedded,omitempty"` |
|
48
|
|
|
Links RouteLinks `json:"_links,omitempty"` |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// CreateDelayedRouting represents the payload to create a delayed routing. |
|
52
|
|
|
type CreateDelayedRouting struct { |
|
53
|
|
|
TestMode bool `json:"testmode,omitempty"` |
|
54
|
|
|
Description string `json:"description,omitempty"` |
|
55
|
|
|
Amount Amount `json:"amount,omitempty"` |
|
56
|
|
|
Destination DelayedRoutingDestination `json:"destination,omitempty"` |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// DelayedRoutingService handles delayed routing related operations. |
|
60
|
|
|
type DelayedRoutingService service |
|
61
|
|
|
|
|
62
|
|
|
// Create creates a new delayed routing for a payment. |
|
63
|
|
|
// |
|
64
|
|
|
// See: https://docs.mollie.com/reference/payment-create-route |
|
65
|
|
|
func (s *DelayedRoutingService) Create(ctx context.Context, payment string, dr CreateDelayedRouting) ( |
|
66
|
|
|
res *Response, |
|
67
|
|
|
r *Route, |
|
68
|
|
|
err error, |
|
69
|
|
|
) { |
|
70
|
|
|
if s.client.HasAccessToken() && s.client.config.testing { |
|
71
|
|
|
dr.TestMode = true |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
u := fmt.Sprintf("/v2/payments/%s/routes", payment) |
|
75
|
|
|
|
|
76
|
|
|
res, err = s.client.post(ctx, u, dr, nil) |
|
77
|
|
|
if err != nil { |
|
78
|
|
|
return |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if err = json.Unmarshal(res.content, &r); err != nil { |
|
82
|
|
|
return |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// List retrieves all delayed routings for a specific payment. |
|
89
|
|
|
// |
|
90
|
|
|
// See: https://docs.mollie.com/reference/payment-list-routes |
|
91
|
|
|
func (s *DelayedRoutingService) List(ctx context.Context, payment string) ( |
|
92
|
|
|
res *Response, |
|
93
|
|
|
prl *PaymentRoutesList, |
|
94
|
|
|
err error, |
|
95
|
|
|
) { |
|
96
|
|
|
u := fmt.Sprintf("/v2/payments/%s/routes", payment) |
|
97
|
|
|
|
|
98
|
|
|
res, err = s.client.get(ctx, u, nil) |
|
99
|
|
|
if err != nil { |
|
100
|
|
|
return |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if err = json.Unmarshal(res.content, &prl); err != nil { |
|
104
|
|
|
return |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return |
|
108
|
|
|
} |
|
109
|
|
|
|