|
1
|
|
|
package mollie |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"encoding/json" |
|
5
|
|
|
"fmt" |
|
6
|
|
|
"strings" |
|
7
|
|
|
"time" |
|
8
|
|
|
) |
|
9
|
|
|
|
|
10
|
|
|
// Amount represents a currency and value pair. |
|
11
|
|
|
type Amount struct { |
|
12
|
|
|
Currency string `json:"currency,omitempty"` |
|
13
|
|
|
Value string `json:"value,omitempty"` |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
// Address provides a human friendly representation of a geographical space. |
|
17
|
|
|
// |
|
18
|
|
|
// When providing an address object as parameter to a request, the following conditions must be met: |
|
19
|
|
|
// |
|
20
|
|
|
// If any of the fields is provided, all fields have to be provided with exception of the region field. |
|
21
|
|
|
// If only the region field is given, one should provide all the other fields as per the previous condition. |
|
22
|
|
|
// For certain PayPal payments the region field is required. |
|
23
|
|
|
type Address struct { |
|
24
|
|
|
StreetAndNumber string `json:"streetAndNumber,omitempty"` |
|
25
|
|
|
StreetAdditional string `json:"streetAdditional,omitempty"` |
|
26
|
|
|
PostalCode string `json:"postalCode,omitempty"` |
|
27
|
|
|
City string `json:"city,omitempty"` |
|
28
|
|
|
Region string `json:"region,omitempty"` |
|
29
|
|
|
Country string `json:"country,omitempty"` |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// ShortDate is a string representing a date in YYYY-MM-DD format. |
|
33
|
|
|
type ShortDate struct { |
|
34
|
|
|
time.Time |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// MarshalJSON overrides the default marshal action |
|
38
|
|
|
// for the Date struct. Returns date as YYYY-MM-DD formatted string. |
|
39
|
|
|
func (d *ShortDate) MarshalJSON() ([]byte, error) { |
|
40
|
1 |
|
bts, err := json.Marshal(d.Time.Format("2006-01-02")) |
|
41
|
1 |
|
if err != nil { |
|
42
|
|
|
return nil, fmt.Errorf("json_marshall_error: %w", err) |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
return bts, nil |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// UnmarshalJSON overrides the default unmarshal action |
|
49
|
|
|
// for the Date struct, as we need links to be pointers to the time.Time struct. |
|
50
|
|
|
func (d *ShortDate) UnmarshalJSON(b []byte) error { |
|
51
|
1 |
|
s := string(b) |
|
52
|
1 |
|
s = strings.Trim(s, "\"") |
|
53
|
1 |
|
date, err := time.Parse("2006-01-02", s) |
|
54
|
|
|
|
|
55
|
1 |
|
if err != nil { |
|
56
|
1 |
|
return fmt.Errorf("time_parse_error: %w", err) |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
d.Time = date |
|
60
|
|
|
|
|
61
|
1 |
|
return nil |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Locale represents a country and language in ISO-15897 format. |
|
65
|
|
|
type Locale string |
|
66
|
|
|
|
|
67
|
|
|
// Mollie supported locales. |
|
68
|
|
|
const ( |
|
69
|
|
|
English Locale = "en_US" |
|
70
|
|
|
Dutch Locale = "nl_NL" |
|
71
|
|
|
DutchBelgium Locale = "nl_BE" |
|
72
|
|
|
French Locale = "fr_FR" |
|
73
|
|
|
FrenchBelgium Locale = "fr_BE" |
|
74
|
|
|
German Locale = "de_DE" |
|
75
|
|
|
GermanAustria Locale = "de_AT" |
|
76
|
|
|
GermanSwiss Locale = "de_CH" |
|
77
|
|
|
Spanish Locale = "es_ES" |
|
78
|
|
|
Catalan Locale = "ca_ES" |
|
79
|
|
|
Portuguese Locale = "pt_PT" |
|
80
|
|
|
Italian Locale = "it_IT" |
|
81
|
|
|
Norwegian Locale = "nb_NO" |
|
82
|
|
|
Swedish Locale = "sv_SE" |
|
83
|
|
|
Finish Locale = "fi_FI" |
|
84
|
|
|
Danish Locale = "da_DK" |
|
85
|
|
|
Icelandic Locale = "is_IS" |
|
86
|
|
|
Hungarian Locale = "hu_HU" |
|
87
|
|
|
Polish Locale = "pl_PL" |
|
88
|
|
|
Latvian Locale = "lv_LV" |
|
89
|
|
|
Lithuanian Locale = "lt_LT" |
|
90
|
|
|
) |
|
91
|
|
|
|
|
92
|
|
|
// PhoneNumber represents a phone number in the E.164 format. |
|
93
|
|
|
type PhoneNumber string |
|
94
|
|
|
|
|
95
|
|
|
// QRCode object represents an image of a QR code. |
|
96
|
|
|
type QRCode struct { |
|
97
|
|
|
Height int `json:"height,omitempty"` |
|
98
|
|
|
Width int `json:"width,omitempty"` |
|
99
|
|
|
Src string `json:"src,omitempty"` |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// URL in Mollie are commonly represented as objects with an href and type field. |
|
103
|
|
|
type URL struct { |
|
104
|
|
|
Href string `json:"href,omitempty"` |
|
105
|
|
|
Type string `json:"type,omitempty"` |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
// PaginationLinks describes the hal component of paginated responses. |
|
109
|
|
|
type PaginationLinks struct { |
|
110
|
|
|
Self URL `json:"self,omitempty"` |
|
111
|
|
|
Previous URL `json:"previous,omitempty"` |
|
112
|
|
|
Next URL `json:"next,omitempty"` |
|
113
|
|
|
Documentation URL `json:"documentation,omitempty"` |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
// CategoryCode specifies an industry or category. |
|
117
|
|
|
type CategoryCode uint |
|
118
|
|
|
|
|
119
|
|
|
// Available category codes. |
|
120
|
|
|
const ( |
|
121
|
|
|
BookMagazinesAndNewspapers CategoryCode = 5192 |
|
122
|
|
|
GeneralMerchandise CategoryCode = 5399 |
|
123
|
|
|
FoodAndDrinks CategoryCode = 5499 |
|
124
|
|
|
AutomotiveProducts CategoryCode = 5533 |
|
125
|
|
|
ChildrenProducts CategoryCode = 5641 |
|
126
|
|
|
ClothingAndShoes CategoryCode = 5651 |
|
127
|
|
|
MarketplaceCrowdfundingAndDonations CategoryCode = 5262 |
|
128
|
|
|
ElectronicsComputersAndSoftware CategoryCode = 5732 |
|
129
|
|
|
HostingOrVpnServices CategoryCode = 5734 |
|
130
|
|
|
Entertainment CategoryCode = 5735 |
|
131
|
|
|
CreditsOrVouchersOrGiftCards CategoryCode = 5815 |
|
132
|
|
|
Alcohol CategoryCode = 5921 |
|
133
|
|
|
JewelryAndAccessories CategoryCode = 5944 |
|
134
|
|
|
HealthAndBeautyProducts CategoryCode = 5977 |
|
135
|
|
|
FinancialServices CategoryCode = 6012 |
|
136
|
|
|
Consultancy CategoryCode = 7299 |
|
137
|
|
|
TravelRentalAndTransportation CategoryCode = 7999 |
|
138
|
|
|
AdvisingOrCoachingOrTraining CategoryCode = 8299 |
|
139
|
|
|
CharityAndDonations CategoryCode = 8398 |
|
140
|
|
|
PoliticalParties CategoryCode = 8699 |
|
141
|
|
|
Others CategoryCode = 0 |
|
142
|
|
|
) |
|
143
|
|
|
|
|
144
|
|
|
// Mode contains information about the creation environment. |
|
145
|
|
|
type Mode string |
|
146
|
|
|
|
|
147
|
|
|
// Valid modes. |
|
148
|
|
|
const ( |
|
149
|
|
|
LiveMode Mode = "live" |
|
150
|
|
|
TestMode Mode = "test" |
|
151
|
|
|
) |
|
152
|
|
|
|
|
153
|
|
|
// EmbedValue describes the valid value of embed query string. |
|
154
|
|
|
type EmbedValue string |
|
155
|
|
|
|
|
156
|
|
|
// Valid Embed query string value. |
|
157
|
|
|
const ( |
|
158
|
|
|
EmbedPayment EmbedValue = "payment" |
|
159
|
|
|
EmbedRefund EmbedValue = "refund" |
|
160
|
|
|
EmbedShipments EmbedValue = "shipments" |
|
161
|
|
|
EmbedChangebacks EmbedValue = "chanrgebacks" |
|
162
|
|
|
) |
|
163
|
|
|
|
|
164
|
|
|
// Rate describes service rates, further divided into fixed and percentage costs. |
|
165
|
|
|
type Rate struct { |
|
166
|
|
|
Fixed *Amount `json:"fixed,omitempty"` |
|
167
|
|
|
Variable string `json:"variable,omitempty"` |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
// Image describes a generic image resource retrieved by Mollie. |
|
171
|
|
|
type Image struct { |
|
172
|
|
|
Size1x string `json:"size1X,omitempty"` |
|
173
|
|
|
Size2X string `json:"size2X,omitempty"` |
|
174
|
|
|
Svg string `json:"svg,omitempty"` |
|
175
|
|
|
} |
|
176
|
|
|
|