From 137dc32f3dc11c0c4b9e2e9769ca8b5f29c818c5 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Sun, 3 Mar 2024 12:31:51 +0100
Subject: [PATCH 01/23] check payments resources against api reference. (#326)
---
docs/README.md | 423 ++++++++++++++++++++++++++++++---------
docs/v4-upgrade.md | 21 ++
mollie/captures.go | 9 +
mollie/common_types.go | 10 +
mollie/customers.go | 2 +-
mollie/customers_test.go | 26 ++-
mollie/payments.go | 262 ++++++++++++++++++------
mollie/payments_test.go | 35 ++--
8 files changed, 609 insertions(+), 179 deletions(-)
create mode 100644 docs/v4-upgrade.md
diff --git a/docs/README.md b/docs/README.md
index 6ae5cf9b..748164cc 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -20,6 +20,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [Constants](<#constants>)
- [func CheckResponse\(r \*Response\) error](<#CheckResponse>)
+- [type AccessTokenPaymentFields](<#AccessTokenPaymentFields>)
- [type Address](<#Address>)
- [type Amount](<#Amount>)
- [type ApplePaymentSession](<#ApplePaymentSession>)
@@ -54,6 +55,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type BusinessCategory](<#BusinessCategory>)
- [type Capture](<#Capture>)
- [type CaptureLinks](<#CaptureLinks>)
+- [type CaptureMode](<#CaptureMode>)
- [type CapturesList](<#CapturesList>)
- [type CapturesService](<#CapturesService>)
- [func \(cs \*CapturesService\) Get\(ctx context.Context, payment, capture string\) \(res \*Response, c \*Capture, err error\)](<#CapturesService.Get>)
@@ -96,6 +98,11 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(c \*Config\) ToggleTesting\(\) bool](<#Config.ToggleTesting>)
- [type ContextValue](<#ContextValue>)
- [type ContextValues](<#ContextValues>)
+- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
+- [type CreatePayment](<#CreatePayment>)
+- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
+- [type CreatePreAuthorizedPaymentFields](<#CreatePreAuthorizedPaymentFields>)
+- [type CreateRecurrentPaymentFields](<#CreateRecurrentPaymentFields>)
- [type CreateShipmentRequest](<#CreateShipmentRequest>)
- [type Customer](<#Customer>)
- [type CustomerLinks](<#CustomerLinks>)
@@ -103,7 +110,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type CustomersListOptions](<#CustomersListOptions>)
- [type CustomersService](<#CustomersService>)
- [func \(cs \*CustomersService\) Create\(ctx context.Context, c Customer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Create>)
- - [func \(cs \*CustomersService\) CreatePayment\(ctx context.Context, id string, p Payment\) \(res \*Response, pp \*Payment, err error\)](<#CustomersService.CreatePayment>)
+ - [func \(cs \*CustomersService\) CreatePayment\(ctx context.Context, id string, p CreatePayment\) \(res \*Response, pp \*Payment, err error\)](<#CustomersService.CreatePayment>)
- [func \(cs \*CustomersService\) Delete\(ctx context.Context, id string\) \(res \*Response, err error\)](<#CustomersService.Delete>)
- [func \(cs \*CustomersService\) Get\(ctx context.Context, id string\) \(res \*Response, c \*Customer, err error\)](<#CustomersService.Get>)
- [func \(cs \*CustomersService\) GetPayments\(ctx context.Context, id string, options \*CustomersListOptions\) \(res \*Response, pl \*PaymentList, err error\)](<#CustomersService.GetPayments>)
@@ -121,6 +128,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type GiftCardIssuerStatus](<#GiftCardIssuerStatus>)
- [type GiftCardLinks](<#GiftCardLinks>)
- [type Image](<#Image>)
+- [type IncludeValue](<#IncludeValue>)
- [type Invoice](<#Invoice>)
- [type InvoiceLinks](<#InvoiceLinks>)
- [type InvoiceStatus](<#InvoiceStatus>)
@@ -149,6 +157,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type MiscellaneousService](<#MiscellaneousService>)
- [func \(ms \*MiscellaneousService\) ApplePaymentSession\(ctx context.Context, asr \*ApplePaymentSessionRequest\) \(res \*Response, aps \*ApplePaymentSession, err error\)](<#MiscellaneousService.ApplePaymentSession>)
- [type Mode](<#Mode>)
+- [type MollieConnectPaymentFields](<#MollieConnectPaymentFields>)
- [type Onboarding](<#Onboarding>)
- [type OnboardingData](<#OnboardingData>)
- [type OnboardingDataOrganization](<#OnboardingDataOrganization>)
@@ -206,6 +215,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ps \*PartnerService\) List\(ctx context.Context, opts \*ListPartnerClientsOptions\) \(res \*Response, pc \*PartnerClientList, err error\)](<#PartnerService.List>)
- [type PartnerType](<#PartnerType>)
- [type Payment](<#Payment>)
+- [type PaymentDestination](<#PaymentDestination>)
- [type PaymentDetails](<#PaymentDetails>)
- [type PaymentDetailsAddress](<#PaymentDetailsAddress>)
- [type PaymentLink](<#PaymentLink>)
@@ -231,12 +241,13 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ms \*PaymentMethodsService\) Get\(ctx context.Context, id PaymentMethod, options \*PaymentMethodOptions\) \(res \*Response, pmd \*PaymentMethodDetails, err error\)](<#PaymentMethodsService.Get>)
- [func \(ms \*PaymentMethodsService\) List\(ctx context.Context, options \*PaymentMethodsListOptions\) \(res \*Response, pm \*PaymentMethodsList, err error\)](<#PaymentMethodsService.List>)
- [type PaymentOptions](<#PaymentOptions>)
+- [type PaymentRouting](<#PaymentRouting>)
- [type PaymentsService](<#PaymentsService>)
- [func \(ps \*PaymentsService\) Cancel\(ctx context.Context, id string\) \(res \*Response, p \*Payment, err error\)](<#PaymentsService.Cancel>)
- - [func \(ps \*PaymentsService\) Create\(ctx context.Context, p Payment, opts \*PaymentOptions\) \(res \*Response, np \*Payment, err error\)](<#PaymentsService.Create>)
+ - [func \(ps \*PaymentsService\) Create\(ctx context.Context, p CreatePayment, opts \*PaymentOptions\) \(res \*Response, np \*Payment, err error\)](<#PaymentsService.Create>)
- [func \(ps \*PaymentsService\) Get\(ctx context.Context, id string, opts \*PaymentOptions\) \(res \*Response, p \*Payment, err error\)](<#PaymentsService.Get>)
- [func \(ps \*PaymentsService\) List\(ctx context.Context, opts \*ListPaymentOptions\) \(res \*Response, pl \*PaymentList, err error\)](<#PaymentsService.List>)
- - [func \(ps \*PaymentsService\) Update\(ctx context.Context, id string, up Payment\) \(res \*Response, p \*Payment, err error\)](<#PaymentsService.Update>)
+ - [func \(ps \*PaymentsService\) Update\(ctx context.Context, id string, up UpdatePayment\) \(res \*Response, p \*Payment, err error\)](<#PaymentsService.Update>)
- [type Permission](<#Permission>)
- [type PermissionGrant](<#PermissionGrant>)
- [type PermissionLinks](<#PermissionLinks>)
@@ -245,6 +256,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ps \*PermissionsService\) Get\(ctx context.Context, id PermissionGrant\) \(res \*Response, p \*Permission, err error\)](<#PermissionsService.Get>)
- [func \(ps \*PermissionsService\) List\(ctx context.Context\) \(res \*Response, pl \*PermissionsList, err error\)](<#PermissionsService.List>)
- [type PhoneNumber](<#PhoneNumber>)
+- [type PreAuthorizedPaymentFields](<#PreAuthorizedPaymentFields>)
- [type ProductType](<#ProductType>)
- [type Profile](<#Profile>)
- [type ProfileLinks](<#ProfileLinks>)
@@ -266,6 +278,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ps \*ProfilesService\) Update\(ctx context.Context, id string, up \*Profile\) \(res \*Response, p \*Profile, err error\)](<#ProfilesService.Update>)
- [type QRCode](<#QRCode>)
- [type Rate](<#Rate>)
+- [type RecurrentPaymentFields](<#RecurrentPaymentFields>)
- [type Refund](<#Refund>)
- [type RefundLinks](<#RefundLinks>)
- [type RefundList](<#RefundList>)
@@ -334,6 +347,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type TransferDestination](<#TransferDestination>)
- [type TransferFrequency](<#TransferFrequency>)
- [type URL](<#URL>)
+- [type UpdatePayment](<#UpdatePayment>)
- [type UsedGiftCard](<#UsedGiftCard>)
- [type UserAgentToken](<#UserAgentToken>)
@@ -365,6 +379,17 @@ func CheckResponse(r *Response) error
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body.
+
+## type [AccessTokenPaymentFields]()
+
+AccessTokenPaymentFields describes the fields specific to payments created using an access token.
+
+```go
+type AccessTokenPaymentFields struct {
+ Testmode bool `json:"testmode,omitempty"`
+}
+```
+
## type [Address]()
@@ -961,7 +986,7 @@ const (
```
-## type [Capture]()
+## type [Capture]()
Capture describes a single capture. Captures are used for payments that have the authorize\-then\-capture flow.
@@ -981,7 +1006,7 @@ type Capture struct {
```
-## type [CaptureLinks]()
+## type [CaptureLinks]()
CaptureLinks contains relevant links for a capture object.
@@ -995,8 +1020,26 @@ type CaptureLinks struct {
}
```
+
+## type [CaptureMode]()
+
+CaptureMode describes the mode of a capture.
+
+```go
+type CaptureMode string
+```
+
+CaptureMode possible values.
+
+```go
+const (
+ AutomaticCapture CaptureMode = "automatic"
+ ManualCapture CaptureMode = "manual"
+)
+```
+
-## type [CapturesList]()
+## type [CapturesList]()
CapturesList describes a list of captures.
@@ -1011,7 +1054,7 @@ type CapturesList struct {
```
-## type [CapturesService]()
+## type [CapturesService]()
CapturesService operates over captures resource.
@@ -1020,7 +1063,7 @@ type CapturesService service
```
-### func \(\*CapturesService\) [Get]()
+### func \(\*CapturesService\) [Get]()
```go
func (cs *CapturesService) Get(ctx context.Context, payment, capture string) (res *Response, c *Capture, err error)
@@ -1031,7 +1074,7 @@ Get retrieves a single capture by its ID. Note the original payment’s ID is ne
See: https://docs.mollie.com/reference/v2/captures-api/get-capture
-### func \(\*CapturesService\) [List]()
+### func \(\*CapturesService\) [List]()
```go
func (cs *CapturesService) List(ctx context.Context, payment string) (res *Response, cl *CapturesList, err error)
@@ -1667,6 +1710,111 @@ ContextValues is a map of TransactionType to ContextValue.
type ContextValues map[TransactionType]ContextValue
```
+
+## type [CreateMollieConnectPaymentFields]()
+
+CreateMollieConnectPaymentFields describes the fields to be sent to the Mollie API when creating a new payment using Mollie Connect.
+
+See: https://docs.mollie.com/reference/v2/payments-api/create-payment#mollie-connect-parameters
+
+```go
+type CreateMollieConnectPaymentFields struct {
+ ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
+ Routing []*PaymentRouting `json:"routing,omitempty"`
+}
+```
+
+
+## type [CreatePayment]()
+
+CreatePayment describes the payload to be sent to the Mollie API when creating or updating a new payment.
+
+Some fields are only valid for specific payment methods, and are documented in the Mollie API reference.
+
+See: https://docs.mollie.com/reference/v2/payments-api/create-payment#payment-method-specific-parameters
+
+```go
+type CreatePayment struct {
+ Description string `json:"description,omitempty"`
+ RedirectURL string `json:"redirectUrl,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ RestrictPaymentMethodsToCountry string `json:"restrictPaymentMethodsToCountry,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Method []PaymentMethod `json:"method,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+
+ // PaymentMethods specific fields
+ DigitalGoods bool `json:"digitalGoods,omitempty"`
+ ApplePayPaymentToken string `json:"applePayPaymentToken,omitempty"`
+ BillingEmail string `json:"billingEmail,omitempty"`
+ CardToken string `json:"cardToken,omitempty"`
+ VoucherNumber string `json:"voucherNumber,omitempty"`
+ VoucherPin string `json:"voucherPin,omitempty"`
+ Issuer string `json:"issuer,omitempty"`
+ ExtraMerchantData string `json:"extraMerchantData,omitempty"`
+ SessionID string `json:"sessionId,omitempty"`
+ CustomerReference string `json:"customerReference,omitempty"`
+ TerminalID string `json:"terminalId,omitempty"`
+ ConsumerName string `json:"consumerName,omitempty"`
+ ConsumerAccount string `json:"consumerAccount,omitempty"`
+ DueDate *ShortDate `json:"dueDate,omitempty"`
+ ShippingAddress *Address `json:"shippingAddress,omitempty"`
+ BillingAddress *Address `json:"billingAddress,omitempty"`
+ Company *Company `json:"company,omitempty"`
+
+ // Other case specific fields
+ CreateRecurrentPaymentFields
+ CreatePreAuthorizedPaymentFields
+ CreatePaymentAccessTokenFields
+ CreateMollieConnectPaymentFields
+}
+```
+
+
+## type [CreatePaymentAccessTokenFields]()
+
+CreatePaymentAccessTokenFields describes the fields to be sent to the Mollie API when creating a new payment using an access token.
+
+See: https://docs.mollie.com/reference/v2/payments-api/create-payment#access-token-parameters
+
+```go
+type CreatePaymentAccessTokenFields struct {
+ ProfileID string `json:"profileId,omitempty"`
+ Testmode bool `json:"testmode,omitempty"`
+}
+```
+
+
+## type [CreatePreAuthorizedPaymentFields]()
+
+CreatePreAuthorizedPaymentFields describes the fields to be sent to the Mollie API when creating a new pre\-authorized payment.
+
+See: https://docs.mollie.com/reference/v2/payments-api/create-payment#parameters-for-pre-authorized-payments
+
+```go
+type CreatePreAuthorizedPaymentFields struct {
+ CaptureDelay string `json:"captureDelay,omitempty"`
+ CaptureMode CaptureMode `json:"captureMode,omitempty"`
+}
+```
+
+
+## type [CreateRecurrentPaymentFields]()
+
+CreateRecurrentPaymentFields describes the fields to be sent to the Mollie API when creating a new recurrent payment.
+
+See: https://docs.mollie.com/reference/v2/payments-api/create-payment#parameters-for-recurring-payments
+
+```go
+type CreateRecurrentPaymentFields struct {
+ CustomerID string `json:"customerId,omitempty"`
+ MandateID string `json:"mandateId,omitempty"`
+ SequenceType SequenceType `json:"sequenceType,omitempty"`
+}
+```
+
## type [CreateShipmentRequest]()
@@ -1769,7 +1917,7 @@ See: https://docs.mollie.com/reference/v2/customers-api/create-customer
### func \(\*CustomersService\) [CreatePayment]()
```go
-func (cs *CustomersService) CreatePayment(ctx context.Context, id string, p Payment) (res *Response, pp *Payment, err error)
+func (cs *CustomersService) CreatePayment(ctx context.Context, id string, p CreatePayment) (res *Response, pp *Payment, err error)
```
CreatePayment creates a payment for the customer.
@@ -1857,7 +2005,7 @@ const (
```
-## type [EmbedValue]()
+## type [EmbedValue]()
EmbedValue describes the valid value of embed query string.
@@ -1873,6 +2021,7 @@ const (
EmbedRefund EmbedValue = "refunds"
EmbedShipments EmbedValue = "shipments"
EmbedChargebacks EmbedValue = "chargebacks"
+ EmbedCaptures EmbedValue = "captures"
)
```
@@ -2069,7 +2218,7 @@ type GiftCardLinks struct {
```
-## type [Image]()
+## type [Image]()
Image describes a generic image resource retrieved by Mollie.
@@ -2081,6 +2230,24 @@ type Image struct {
}
```
+
+## type [IncludeValue]()
+
+IncludeValue is a valid value for the Include query string parameter.
+
+```go
+type IncludeValue string
+```
+
+Supported Include values.
+
+```go
+const (
+ IncludeQrCode IncludeValue = "details.qrCode"
+ IncludeRemainderDetails IncludeValue = "details.remainderDetails"
+)
+```
+
## type [Invoice]()
@@ -2222,17 +2389,17 @@ type ListPartnerClientsOptions struct {
```
-## type [ListPaymentOptions]()
+## type [ListPaymentOptions]()
ListPaymentOptions describes list payments endpoint valid query string parameters.
```go
type ListPaymentOptions struct {
- Limit int `url:"limit,omitempty"`
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
- ProfileID string `url:"profileId,omitempty"`
- From string `url:"from,omitempty"`
+ Limit int `url:"limit,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
+ ProfileID string `url:"profileId,omitempty"`
+ From string `url:"from,omitempty"`
}
```
@@ -2499,6 +2666,17 @@ const (
)
```
+
+## type [MollieConnectPaymentFields]()
+
+MollieConnectPaymentFields describes the fields specific to Mollie Connect payments.
+
+```go
+type MollieConnectPaymentFields struct {
+ ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
+}
+```
+
## type [Onboarding]()
@@ -3218,7 +3396,7 @@ GetPartnerStatus retrieves details about the partner status of the currently aut
See: https://docs.mollie.com/reference/v2/organizations-api/get-partner
-## type [Owner]()
+## type [Owner]()
Personal data of your customer.
@@ -3340,66 +3518,63 @@ const (
```
-## type [Payment]()
+## type [Payment]()
Payment describes a transaction between a customer and a merchant.
```go
type Payment struct {
- IsCancellable bool `json:"isCancellable,omitempty"`
- TestMode bool `json:"testmode,omitempty"`
- DigitalGoods bool `json:"digitalGoods,omitempty"`
- ApplePayPaymentToken string `json:"applePayPaymentToken,omitempty"`
- BillingEmail string `json:"billingEmail,omitempty"`
- CardToken string `json:"cardToken,omitempty"`
- Issuer string `json:"issuer,omitempty"`
- VoucherNumber string `json:"voucherNumber,omitempty"`
- VoucherPin string `json:"voucherPin,omitempty"`
- ExtraMerchantData string `json:"extraMerchantData,omitempty"`
- SessionID string `json:"sessionId,omitempty"`
- CustomerReference string `json:"customerReference,omitempty"`
- ConsumerName string `json:"consumerName,omitempty"`
- ConsumerAccount string `json:"consumerAccount,omitempty"`
- WebhookURL string `json:"webhookUrl,omitempty"`
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- MandateID string `json:"mandateId,omitempty"`
- OrderID string `json:"orderId,omitempty"`
- ProfileID string `json:"profileId,omitempty"`
- SettlementID string `json:"settlementId,omitempty"`
- CustomerID string `json:"customerId,omitempty"`
- Status string `json:"status,omitempty"`
- Description string `json:"description,omitempty"`
- RedirectURL string `json:"redirectUrl,omitempty"`
- CountryCode string `json:"countryCode,omitempty"`
- SubscriptionID string `json:"subscriptionId,omitempty"`
- CancelURL string `json:"cancelUrl,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- AmountRefunded *Amount `json:"amountRefunded,omitempty"`
- AmountRemaining *Amount `json:"amountRemaining,omitempty"`
- AmountCaptured *Amount `json:"amountCaptured,omitempty"`
- AmountChargedBack *Amount `json:"amountChargedBack,omitempty"`
- SettlementAmount *Amount `json:"settlementAmount,omitempty"`
- ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
- Details *PaymentDetails `json:"details,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
- AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
- PaidAt *time.Time `json:"paidAt,omitempty"`
- CanceledAt *time.Time `json:"canceledAt,omitempty"`
- ExpiresAt *time.Time `json:"expiresAt,omitempty"`
- ExpiredAt *time.Time `json:"expiredAt,omitempty"`
- FailedAt *time.Time `json:"failedAt,omitempty"`
- DueDate *ShortDate `json:"dueDate,omitempty"`
- BillingAddress *Address `json:"billingAddress,omitempty"`
- ShippingAddress *PaymentDetailsAddress `json:"shippingAddress,omitempty"`
- Mode Mode `json:"mode,omitempty"`
- Locale Locale `json:"locale,omitempty"`
- RestrictPaymentMethodsToCountry Locale `json:"restrictPaymentMethodsToCountry,omitempty"`
- Method PaymentMethod `json:"method,omitempty"`
- Links PaymentLinks `json:"_links,omitempty"`
- SequenceType SequenceType `json:"sequenceType,omitempty"`
- Company Company `json:"company,omitempty"`
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ Status string `json:"status,omitempty"`
+ Description string `json:"description,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ CountryCode string `json:"countryCode,omitempty"`
+ RestrictPaymentMethodsToCountry string `json:"restrictPaymentMethodsToCountry,omitempty"`
+ ProfileID string `json:"profileId,omitempty"`
+ SettlementID string `json:"settlementId,omitempty"`
+ OrderID string `json:"orderId,omitempty"`
+ IsCancelable bool `json:"isCancelable,omitempty"`
+ Mode Mode `json:"mode,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Links PaymentLinks `json:"_links,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
+ PaidAt *time.Time `json:"paidAt,omitempty"`
+ CanceledAt *time.Time `json:"canceledAt,omitempty"`
+ ExpiresAt *time.Time `json:"expiresAt,omitempty"`
+ ExpiredAt *time.Time `json:"expiredAt,omitempty"`
+ FailedAt *time.Time `json:"failedAt,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ AmountRefunded *Amount `json:"amountRefunded,omitempty"`
+ AmountRemaining *Amount `json:"amountRemaining,omitempty"`
+ AmountCaptured *Amount `json:"amountCaptured,omitempty"`
+ AmountChargedBack *Amount `json:"amountChargeback,omitempty"`
+ SettlementAmount *Amount `json:"settlementAmount,omitempty"`
+
+ // PaymentMethods specific fields
+ Details PaymentDetails `json:"details,omitempty"`
+
+ // Other case specific fields
+ RecurrentPaymentFields
+ PreAuthorizedPaymentFields
+ MollieConnectPaymentFields
+ AccessTokenPaymentFields
+}
+```
+
+
+## type [PaymentDestination]()
+
+PaymentDestination describes the destination of a payment.
+
+```go
+type PaymentDestination struct {
+ Kind string `json:"type,omitempty"`
+ OrganizationID string `json:"organizationId,omitempty"`
}
```
@@ -3533,7 +3708,7 @@ type PaymentLinkOptions struct {
```
-## type [PaymentLinks]()
+## type [PaymentLinks]()
PaymentLinks describes all the possible links to be returned with a payment object.
@@ -3552,6 +3727,8 @@ type PaymentLinks struct {
Customer *URL `json:"customer,omitempty"`
Order *URL `json:"order,omitempty"`
Dashboard *URL `json:"dashboard,omitempty"`
+ MobileAppCheckout *URL `json:"mobileAppCheckout,omitempty"`
+ Terminal *URL `json:"terminal,omitempty"`
}
```
@@ -3613,7 +3790,7 @@ List retrieves all payments links created with the current website profile, orde
See: https://docs.mollie.com/reference/v2/payment-links-api/list-payment-links
-## type [PaymentList]()
+## type [PaymentList]()
PaymentList describes how a list of payments will be retrieved by Mollie.
@@ -3643,6 +3820,7 @@ const (
Bancontact PaymentMethod = "bancontact"
BankTransfer PaymentMethod = "banktransfer"
Belfius PaymentMethod = "belfius"
+ CBC PaymentMethod = "cbc"
CreditCard PaymentMethod = "creditcard"
DirectDebit PaymentMethod = "directdebit"
EPS PaymentMethod = "eps"
@@ -3822,7 +4000,7 @@ The results are not paginated.
See: https://docs.mollie.com/reference/v2/methods-api/list-methods
-## type [PaymentOptions]()
+## type [PaymentOptions]()
PaymentOptions describes payments endpoint valid query string parameters.
@@ -3830,13 +4008,26 @@ See: https://docs.mollie.com/reference/v2/payments-api/get-payment
```go
type PaymentOptions struct {
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
+}
+```
+
+
+## type [PaymentRouting]()
+
+PaymentRouting describes the routing of a payment.
+
+```go
+type PaymentRouting struct {
+ Destination PaymentDestination `json:"destination,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ ReleaseDate *ShortDate `json:"releaseDate,omitempty"`
}
```
-## type [PaymentsService]()
+## type [PaymentsService]()
PaymentsService instance operates over payment resources.
@@ -3845,7 +4036,7 @@ type PaymentsService service
```
-### func \(\*PaymentsService\) [Cancel]()
+### func \(\*PaymentsService\) [Cancel]()
```go
func (ps *PaymentsService) Cancel(ctx context.Context, id string) (res *Response, p *Payment, err error)
@@ -3856,10 +4047,10 @@ Cancel removes a payment \(if possible\) from your Mollie account.
See: https://docs.mollie.com/reference/v2/payments-api/cancel-payment
-### func \(\*PaymentsService\) [Create]()
+### func \(\*PaymentsService\) [Create]()
```go
-func (ps *PaymentsService) Create(ctx context.Context, p Payment, opts *PaymentOptions) (res *Response, np *Payment, err error)
+func (ps *PaymentsService) Create(ctx context.Context, p CreatePayment, opts *PaymentOptions) (res *Response, np *Payment, err error)
```
Create stores a new payment object attached to your Mollie account.
@@ -3867,7 +4058,7 @@ Create stores a new payment object attached to your Mollie account.
See: https://docs.mollie.com/reference/v2/payments-api/create-payment#
-### func \(\*PaymentsService\) [Get]()
+### func \(\*PaymentsService\) [Get]()
```go
func (ps *PaymentsService) Get(ctx context.Context, id string, opts *PaymentOptions) (res *Response, p *Payment, err error)
@@ -3876,7 +4067,7 @@ func (ps *PaymentsService) Get(ctx context.Context, id string, opts *PaymentOpti
Get retrieves a single payment object by its payment token.
-### func \(\*PaymentsService\) [List]()
+### func \(\*PaymentsService\) [List]()
```go
func (ps *PaymentsService) List(ctx context.Context, opts *ListPaymentOptions) (res *Response, pl *PaymentList, err error)
@@ -3887,15 +4078,15 @@ List retrieves a list of payments associated with your account/organization.
See: https://docs.mollie.com/reference/v2/payments-api/list-payments
-### func \(\*PaymentsService\) [Update]()
+### func \(\*PaymentsService\) [Update]()
```go
-func (ps *PaymentsService) Update(ctx context.Context, id string, up Payment) (res *Response, p *Payment, err error)
+func (ps *PaymentsService) Update(ctx context.Context, id string, up UpdatePayment) (res *Response, p *Payment, err error)
```
Update can be used to update some details of a created payment.
-See: https://docs.mollie.com/reference/v2/payments-api/update-payment#
+See: https://docs.mollie.com/reference/v2/payments-api/update-payment
## type [Permission]()
@@ -4016,6 +4207,19 @@ PhoneNumber represents a phone number in the E.164 format.
type PhoneNumber string
```
+
+## type [PreAuthorizedPaymentFields]()
+
+PreAuthorizedPaymentFields describes the fields specific to pre\-authorized payments.
+
+```go
+type PreAuthorizedPaymentFields struct {
+ CaptureDelay string `json:"captureDelay,omitempty"`
+ CaptureMode CaptureMode `json:"captureMode,omitempty"`
+ CaptureBefore *time.Time `json:"captureBefore,omitempty"`
+}
+```
+
## type [ProductType]()
@@ -4265,7 +4469,7 @@ type QRCode struct {
```
-## type [Rate]()
+## type [Rate]()
Rate describes service rates, further divided into fixed and percentage costs.
@@ -4276,6 +4480,20 @@ type Rate struct {
}
```
+
+## type [RecurrentPaymentFields]()
+
+RecurrentPaymentFields describes the fields specific to recurrent payments.
+
+```go
+type RecurrentPaymentFields struct {
+ SequenceType SequenceType `json:"sequenceType,omitempty"`
+ CustomerID string `json:"customerId,omitempty"`
+ MandateID string `json:"mandateId,omitempty"`
+ SubscriptionID string `json:"subscriptionId,omitempty"`
+}
+```
+
## type [Refund]()
@@ -4439,7 +4657,7 @@ type Response struct {
```
-## type [SequenceType]()
+## type [SequenceType]()
SequenceType indicates which type of payment this is in a recurring sequence.
@@ -5212,6 +5430,31 @@ type URL struct {
}
```
+
+## type [UpdatePayment]()
+
+UpdatePayment describes the payload to be sent to the Mollie API when updating a payment.
+
+See: https://docs.mollie.com/reference/v2/payments-api/update-payment See: https://docs.mollie.com/reference/v2/payments-api/update-payment#payment-method-specific-parameters
+
+```go
+type UpdatePayment struct {
+ Description string `json:"description,omitempty"`
+ RedirectURL string `json:"redirectUrl,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ RestrictPaymentMethodsToCountry string `json:"restrictPaymentMethodsToCountry,omitempty"`
+
+ // PaymentMethods specific fields
+ BillingEmail string `json:"billingEmail,omitempty"`
+ DueDate *ShortDate `json:"dueDate,omitempty"`
+ Issuer string `json:"issuer,omitempty"`
+}
+```
+
## type [UsedGiftCard]()
diff --git a/docs/v4-upgrade.md b/docs/v4-upgrade.md
new file mode 100644
index 00000000..72153fe5
--- /dev/null
+++ b/docs/v4-upgrade.md
@@ -0,0 +1,21 @@
+# Notable changes included in v4
+
+## Breaking changes
+
+- `idempotency` package has moved from the `mollie` directory to the `pkg` directory.
+- `pagination` package has moved from the`mollie` directory to the `pkg` directory.
+- `connect` package has moved from the `mollie` directory to the `pkg` directory.
+- root namespace is not `github.com/VictorAvelar/mollie-api-go/v4/`.
+- Changes for payments resource
+ - Added `CreatePayment` type to use when creating a payment.
+ - Added `UpdatePayment` type to use when updating a payment.
+ - Ensured `Payment` object (used for read operations) contains all the available fields.
+ - Created types specific for fields that are conditional given the payment values, both to create new payments and to list existing payments.
+
+## Other changes
+
+- `testify.Suite` was removed from all testing.
+- Improvements for devcontainer files
+- Major versions of multiple github actions updated
+- Base `Dockerfile` using Go 1.22.x
+- Tests related to payments were update to use the new types.
diff --git a/mollie/captures.go b/mollie/captures.go
index d069c457..ea690e58 100644
--- a/mollie/captures.go
+++ b/mollie/captures.go
@@ -7,6 +7,15 @@ import (
"time"
)
+// CaptureMode describes the mode of a capture.
+type CaptureMode string
+
+// CaptureMode possible values.
+const (
+ AutomaticCapture CaptureMode = "automatic"
+ ManualCapture CaptureMode = "manual"
+)
+
// CapturesService operates over captures resource.
type CapturesService service
diff --git a/mollie/common_types.go b/mollie/common_types.go
index e990df68..9d797caa 100644
--- a/mollie/common_types.go
+++ b/mollie/common_types.go
@@ -321,6 +321,15 @@ const (
TestMode Mode = "test"
)
+// IncludeValue is a valid value for the Include query string parameter.
+type IncludeValue string
+
+// Supported Include values.
+const (
+ IncludeQrCode IncludeValue = "details.qrCode"
+ IncludeRemainderDetails IncludeValue = "details.remainderDetails"
+)
+
// EmbedValue describes the valid value of embed query string.
type EmbedValue string
@@ -330,6 +339,7 @@ const (
EmbedRefund EmbedValue = "refunds"
EmbedShipments EmbedValue = "shipments"
EmbedChargebacks EmbedValue = "chargebacks"
+ EmbedCaptures EmbedValue = "captures"
)
// Rate describes service rates, further divided into fixed and percentage costs.
diff --git a/mollie/customers.go b/mollie/customers.go
index 72fae6c3..486aa377 100644
--- a/mollie/customers.go
+++ b/mollie/customers.go
@@ -170,7 +170,7 @@ func (cs *CustomersService) GetPayments(ctx context.Context, id string, options
// CreatePayment creates a payment for the customer.
//
// See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
-func (cs *CustomersService) CreatePayment(ctx context.Context, id string, p Payment) (
+func (cs *CustomersService) CreatePayment(ctx context.Context, id string, p CreatePayment) (
res *Response,
pp *Payment,
err error,
diff --git a/mollie/customers_test.go b/mollie/customers_test.go
index e97a6474..9863ab29 100644
--- a/mollie/customers_test.go
+++ b/mollie/customers_test.go
@@ -621,7 +621,7 @@ func TestCustomerService_CreatePayment(t *testing.T) {
type args struct {
ctx context.Context
customer string
- payment Payment
+ payment CreatePayment
}
cases := []struct {
@@ -637,7 +637,11 @@ func TestCustomerService_CreatePayment(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Payment{TestMode: true},
+ CreatePayment{
+ CreatePaymentAccessTokenFields: CreatePaymentAccessTokenFields{
+ Testmode: true,
+ },
+ },
},
false,
nil,
@@ -657,7 +661,11 @@ func TestCustomerService_CreatePayment(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Payment{TestMode: true},
+ CreatePayment{
+ CreatePaymentAccessTokenFields: CreatePaymentAccessTokenFields{
+ Testmode: true,
+ },
+ },
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -669,7 +677,11 @@ func TestCustomerService_CreatePayment(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Payment{TestMode: true},
+ CreatePayment{
+ CreatePaymentAccessTokenFields: CreatePaymentAccessTokenFields{
+ Testmode: true,
+ },
+ },
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -681,7 +693,11 @@ func TestCustomerService_CreatePayment(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Payment{TestMode: true},
+ CreatePayment{
+ CreatePaymentAccessTokenFields: CreatePaymentAccessTokenFields{
+ Testmode: true,
+ },
+ },
},
true,
errBadBaseURL,
diff --git a/mollie/payments.go b/mollie/payments.go
index 7ca57ff1..67af858d 100644
--- a/mollie/payments.go
+++ b/mollie/payments.go
@@ -15,6 +15,7 @@ const (
Bancontact PaymentMethod = "bancontact"
BankTransfer PaymentMethod = "banktransfer"
Belfius PaymentMethod = "belfius"
+ CBC PaymentMethod = "cbc"
CreditCard PaymentMethod = "creditcard"
DirectDebit PaymentMethod = "directdebit"
EPS PaymentMethod = "eps"
@@ -41,62 +42,187 @@ const (
RecurringSequence SequenceType = "recurring"
)
+// PaymentRouting describes the routing of a payment.
+type PaymentRouting struct {
+ Destination PaymentDestination `json:"destination,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ ReleaseDate *ShortDate `json:"releaseDate,omitempty"`
+}
+
+// PaymentDestination describes the destination of a payment.
+type PaymentDestination struct {
+ Kind string `json:"type,omitempty"`
+ OrganizationID string `json:"organizationId,omitempty"`
+}
+
+// CreatePayment describes the payload to be sent to the Mollie API when
+// creating or updating a new payment.
+//
+// Some fields are only valid for specific payment methods, and are
+// documented in the Mollie API reference.
+//
+// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#payment-method-specific-parameters
+type CreatePayment struct {
+ Description string `json:"description,omitempty"`
+ RedirectURL string `json:"redirectUrl,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ RestrictPaymentMethodsToCountry string `json:"restrictPaymentMethodsToCountry,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Method []PaymentMethod `json:"method,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+
+ // PaymentMethods specific fields
+ DigitalGoods bool `json:"digitalGoods,omitempty"`
+ ApplePayPaymentToken string `json:"applePayPaymentToken,omitempty"`
+ BillingEmail string `json:"billingEmail,omitempty"`
+ CardToken string `json:"cardToken,omitempty"`
+ VoucherNumber string `json:"voucherNumber,omitempty"`
+ VoucherPin string `json:"voucherPin,omitempty"`
+ Issuer string `json:"issuer,omitempty"`
+ ExtraMerchantData string `json:"extraMerchantData,omitempty"`
+ SessionID string `json:"sessionId,omitempty"`
+ CustomerReference string `json:"customerReference,omitempty"`
+ TerminalID string `json:"terminalId,omitempty"`
+ ConsumerName string `json:"consumerName,omitempty"`
+ ConsumerAccount string `json:"consumerAccount,omitempty"`
+ DueDate *ShortDate `json:"dueDate,omitempty"`
+ ShippingAddress *Address `json:"shippingAddress,omitempty"`
+ BillingAddress *Address `json:"billingAddress,omitempty"`
+ Company *Company `json:"company,omitempty"`
+
+ // Other case specific fields
+ CreateRecurrentPaymentFields
+ CreatePreAuthorizedPaymentFields
+ CreatePaymentAccessTokenFields
+ CreateMollieConnectPaymentFields
+}
+
+// CreateRecurrentPaymentFields describes the fields to be sent to the Mollie API when
+// creating a new recurrent payment.
+//
+// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#parameters-for-recurring-payments
+type CreateRecurrentPaymentFields struct {
+ CustomerID string `json:"customerId,omitempty"`
+ MandateID string `json:"mandateId,omitempty"`
+ SequenceType SequenceType `json:"sequenceType,omitempty"`
+}
+
+// CreatePreAuthorizedPaymentFields describes the fields to be sent to the Mollie API when
+// creating a new pre-authorized payment.
+//
+// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#parameters-for-pre-authorized-payments
+type CreatePreAuthorizedPaymentFields struct {
+ CaptureDelay string `json:"captureDelay,omitempty"`
+ CaptureMode CaptureMode `json:"captureMode,omitempty"`
+}
+
+// CreatePaymentAccessTokenFields describes the fields to be sent to the Mollie API when
+// creating a new payment using an access token.
+//
+// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#access-token-parameters
+type CreatePaymentAccessTokenFields struct {
+ ProfileID string `json:"profileId,omitempty"`
+ Testmode bool `json:"testmode,omitempty"`
+}
+
+// CreateMollieConnectPaymentFields describes the fields to be sent to the Mollie API when
+// creating a new payment using Mollie Connect.
+//
+// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#mollie-connect-parameters
+type CreateMollieConnectPaymentFields struct {
+ ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
+ Routing []*PaymentRouting `json:"routing,omitempty"`
+}
+
+// UpdatePayment describes the payload to be sent to the Mollie API when
+// updating a payment.
+//
+// See: https://docs.mollie.com/reference/v2/payments-api/update-payment
+// See: https://docs.mollie.com/reference/v2/payments-api/update-payment#payment-method-specific-parameters
+type UpdatePayment struct {
+ Description string `json:"description,omitempty"`
+ RedirectURL string `json:"redirectUrl,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ RestrictPaymentMethodsToCountry string `json:"restrictPaymentMethodsToCountry,omitempty"`
+
+ // PaymentMethods specific fields
+ BillingEmail string `json:"billingEmail,omitempty"`
+ DueDate *ShortDate `json:"dueDate,omitempty"`
+ Issuer string `json:"issuer,omitempty"`
+}
+
// Payment describes a transaction between a customer and a merchant.
type Payment struct {
- IsCancellable bool `json:"isCancellable,omitempty"`
- TestMode bool `json:"testmode,omitempty"`
- DigitalGoods bool `json:"digitalGoods,omitempty"`
- ApplePayPaymentToken string `json:"applePayPaymentToken,omitempty"`
- BillingEmail string `json:"billingEmail,omitempty"`
- CardToken string `json:"cardToken,omitempty"`
- Issuer string `json:"issuer,omitempty"`
- VoucherNumber string `json:"voucherNumber,omitempty"`
- VoucherPin string `json:"voucherPin,omitempty"`
- ExtraMerchantData string `json:"extraMerchantData,omitempty"`
- SessionID string `json:"sessionId,omitempty"`
- CustomerReference string `json:"customerReference,omitempty"`
- ConsumerName string `json:"consumerName,omitempty"`
- ConsumerAccount string `json:"consumerAccount,omitempty"`
- WebhookURL string `json:"webhookUrl,omitempty"`
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- MandateID string `json:"mandateId,omitempty"`
- OrderID string `json:"orderId,omitempty"`
- ProfileID string `json:"profileId,omitempty"`
- SettlementID string `json:"settlementId,omitempty"`
- CustomerID string `json:"customerId,omitempty"`
- Status string `json:"status,omitempty"`
- Description string `json:"description,omitempty"`
- RedirectURL string `json:"redirectUrl,omitempty"`
- CountryCode string `json:"countryCode,omitempty"`
- SubscriptionID string `json:"subscriptionId,omitempty"`
- CancelURL string `json:"cancelUrl,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- AmountRefunded *Amount `json:"amountRefunded,omitempty"`
- AmountRemaining *Amount `json:"amountRemaining,omitempty"`
- AmountCaptured *Amount `json:"amountCaptured,omitempty"`
- AmountChargedBack *Amount `json:"amountChargedBack,omitempty"`
- SettlementAmount *Amount `json:"settlementAmount,omitempty"`
- ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
- Details *PaymentDetails `json:"details,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
- AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
- PaidAt *time.Time `json:"paidAt,omitempty"`
- CanceledAt *time.Time `json:"canceledAt,omitempty"`
- ExpiresAt *time.Time `json:"expiresAt,omitempty"`
- ExpiredAt *time.Time `json:"expiredAt,omitempty"`
- FailedAt *time.Time `json:"failedAt,omitempty"`
- DueDate *ShortDate `json:"dueDate,omitempty"`
- BillingAddress *Address `json:"billingAddress,omitempty"`
- ShippingAddress *PaymentDetailsAddress `json:"shippingAddress,omitempty"`
- Mode Mode `json:"mode,omitempty"`
- Locale Locale `json:"locale,omitempty"`
- RestrictPaymentMethodsToCountry Locale `json:"restrictPaymentMethodsToCountry,omitempty"`
- Method PaymentMethod `json:"method,omitempty"`
- Links PaymentLinks `json:"_links,omitempty"`
- SequenceType SequenceType `json:"sequenceType,omitempty"`
- Company Company `json:"company,omitempty"`
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ Status string `json:"status,omitempty"`
+ Description string `json:"description,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ CountryCode string `json:"countryCode,omitempty"`
+ RestrictPaymentMethodsToCountry string `json:"restrictPaymentMethodsToCountry,omitempty"`
+ ProfileID string `json:"profileId,omitempty"`
+ SettlementID string `json:"settlementId,omitempty"`
+ OrderID string `json:"orderId,omitempty"`
+ IsCancelable bool `json:"isCancelable,omitempty"`
+ Mode Mode `json:"mode,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Links PaymentLinks `json:"_links,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
+ PaidAt *time.Time `json:"paidAt,omitempty"`
+ CanceledAt *time.Time `json:"canceledAt,omitempty"`
+ ExpiresAt *time.Time `json:"expiresAt,omitempty"`
+ ExpiredAt *time.Time `json:"expiredAt,omitempty"`
+ FailedAt *time.Time `json:"failedAt,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ AmountRefunded *Amount `json:"amountRefunded,omitempty"`
+ AmountRemaining *Amount `json:"amountRemaining,omitempty"`
+ AmountCaptured *Amount `json:"amountCaptured,omitempty"`
+ AmountChargedBack *Amount `json:"amountChargeback,omitempty"`
+ SettlementAmount *Amount `json:"settlementAmount,omitempty"`
+
+ // PaymentMethods specific fields
+ Details PaymentDetails `json:"details,omitempty"`
+
+ // Other case specific fields
+ RecurrentPaymentFields
+ PreAuthorizedPaymentFields
+ MollieConnectPaymentFields
+ AccessTokenPaymentFields
+}
+
+// RecurrentPaymentFields describes the fields specific to recurrent payments.
+type RecurrentPaymentFields struct {
+ SequenceType SequenceType `json:"sequenceType,omitempty"`
+ CustomerID string `json:"customerId,omitempty"`
+ MandateID string `json:"mandateId,omitempty"`
+ SubscriptionID string `json:"subscriptionId,omitempty"`
+}
+
+// PreAuthorizedPaymentFields describes the fields specific to pre-authorized payments.
+type PreAuthorizedPaymentFields struct {
+ CaptureDelay string `json:"captureDelay,omitempty"`
+ CaptureMode CaptureMode `json:"captureMode,omitempty"`
+ CaptureBefore *time.Time `json:"captureBefore,omitempty"`
+}
+
+// MollieConnectPaymentFields describes the fields specific to Mollie Connect payments.
+type MollieConnectPaymentFields struct {
+ ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
+}
+
+// AccessTokenPaymentFields describes the fields specific to payments created using an access token.
+type AccessTokenPaymentFields struct {
+ Testmode bool `json:"testmode,omitempty"`
}
// PaymentLinks describes all the possible links to be returned with
@@ -115,23 +241,25 @@ type PaymentLinks struct {
Customer *URL `json:"customer,omitempty"`
Order *URL `json:"order,omitempty"`
Dashboard *URL `json:"dashboard,omitempty"`
+ MobileAppCheckout *URL `json:"mobileAppCheckout,omitempty"`
+ Terminal *URL `json:"terminal,omitempty"`
}
// PaymentOptions describes payments endpoint valid query string parameters.
//
// See: https://docs.mollie.com/reference/v2/payments-api/get-payment
type PaymentOptions struct {
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
}
// ListPaymentOptions describes list payments endpoint valid query string parameters.
type ListPaymentOptions struct {
- Limit int `url:"limit,omitempty"`
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
- ProfileID string `url:"profileId,omitempty"`
- From string `url:"from,omitempty"`
+ Limit int `url:"limit,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
+ ProfileID string `url:"profileId,omitempty"`
+ From string `url:"from,omitempty"`
}
// PaymentsService instance operates over payment resources.
@@ -158,13 +286,13 @@ func (ps *PaymentsService) Get(ctx context.Context, id string, opts *PaymentOpti
// Create stores a new payment object attached to your Mollie account.
//
// See: https://docs.mollie.com/reference/v2/payments-api/create-payment#
-func (ps *PaymentsService) Create(ctx context.Context, p Payment, opts *PaymentOptions) (
+func (ps *PaymentsService) Create(ctx context.Context, p CreatePayment, opts *PaymentOptions) (
res *Response,
np *Payment,
err error,
) {
if ps.client.HasAccessToken() && ps.client.config.testing {
- p.TestMode = true
+ p.Testmode = true
}
res, err = ps.client.post(ctx, "v2/payments", p, opts)
@@ -197,8 +325,12 @@ func (ps *PaymentsService) Cancel(ctx context.Context, id string) (res *Response
// Update can be used to update some details of a created payment.
//
-// See: https://docs.mollie.com/reference/v2/payments-api/update-payment#
-func (ps *PaymentsService) Update(ctx context.Context, id string, up Payment) (res *Response, p *Payment, err error) {
+// See: https://docs.mollie.com/reference/v2/payments-api/update-payment
+func (ps *PaymentsService) Update(ctx context.Context, id string, up UpdatePayment) (
+ res *Response,
+ p *Payment,
+ err error,
+) {
res, err = ps.client.patch(ctx, fmt.Sprintf("v2/payments/%s", id), up, nil)
if err != nil {
return
diff --git a/mollie/payments_test.go b/mollie/payments_test.go
index 6c8a77c7..7e911d6a 100644
--- a/mollie/payments_test.go
+++ b/mollie/payments_test.go
@@ -33,7 +33,7 @@ func TestPaymentsService_Get(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
&PaymentOptions{
- Include: "settlements",
+ Include: []IncludeValue{IncludeQrCode},
},
},
false,
@@ -42,7 +42,7 @@ func TestPaymentsService_Get(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
testMethod(t, r, "GET")
- testQuery(t, r, "include=settlements")
+ testQuery(t, r, "include=details.qrCode")
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
@@ -209,7 +209,7 @@ func TestPaymentsService_Create(t *testing.T) {
type args struct {
ctx context.Context
- payment Payment
+ payment CreatePayment
options *PaymentOptions
}
cases := []struct {
@@ -224,11 +224,11 @@ func TestPaymentsService_Create(t *testing.T) {
"create payments works as expected.",
args{
context.Background(),
- Payment{
+ CreatePayment{
BillingEmail: "test@example.com",
},
&PaymentOptions{
- Include: "settlements",
+ Include: []IncludeValue{},
},
},
false,
@@ -237,7 +237,6 @@ func TestPaymentsService_Create(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
testMethod(t, r, "POST")
- testQuery(t, r, "include=settlements")
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
@@ -249,11 +248,11 @@ func TestPaymentsService_Create(t *testing.T) {
"create payments with access token works as expected.",
args{
context.Background(),
- Payment{
+ CreatePayment{
BillingEmail: "test@example.com",
},
&PaymentOptions{
- Include: "settlements",
+ Include: []IncludeValue{},
},
},
false,
@@ -262,7 +261,7 @@ func TestPaymentsService_Create(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer access_token_test")
testMethod(t, r, "POST")
- testQuery(t, r, "include=settlements&testmode=true")
+ testQuery(t, r, "testmode=true")
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
@@ -274,7 +273,7 @@ func TestPaymentsService_Create(t *testing.T) {
"create payments, an error is returned from the server",
args{
context.Background(),
- Payment{},
+ CreatePayment{},
nil,
},
true,
@@ -286,7 +285,7 @@ func TestPaymentsService_Create(t *testing.T) {
"create payments, an error occurs when parsing json",
args{
context.Background(),
- Payment{},
+ CreatePayment{},
nil,
},
true,
@@ -298,7 +297,7 @@ func TestPaymentsService_Create(t *testing.T) {
"create payments, invalid url when building request",
args{
context.Background(),
- Payment{},
+ CreatePayment{},
nil,
},
true,
@@ -336,7 +335,7 @@ func TestPaymentsService_Update(t *testing.T) {
type args struct {
ctx context.Context
id string
- payment Payment
+ payment UpdatePayment
}
cases := []struct {
name string
@@ -351,7 +350,7 @@ func TestPaymentsService_Update(t *testing.T) {
args{
context.Background(),
"tr_WDqYK6vllg",
- Payment{
+ UpdatePayment{
BillingEmail: "test@example.com",
},
},
@@ -373,7 +372,7 @@ func TestPaymentsService_Update(t *testing.T) {
args{
context.Background(),
"tr_WDqYK6vllg",
- Payment{
+ UpdatePayment{
BillingEmail: "test@example.com",
},
},
@@ -398,7 +397,7 @@ func TestPaymentsService_Update(t *testing.T) {
args{
context.Background(),
"tr_WDqYK6vllg",
- Payment{},
+ UpdatePayment{},
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -410,7 +409,7 @@ func TestPaymentsService_Update(t *testing.T) {
args{
context.Background(),
"tr_WDqYK6vllg",
- Payment{},
+ UpdatePayment{},
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -422,7 +421,7 @@ func TestPaymentsService_Update(t *testing.T) {
args{
context.Background(),
"tr_WDqYK6vllg",
- Payment{},
+ UpdatePayment{},
},
true,
errBadBaseURL,
From b22b15a6b972dd28e0b2ebedff9bc0a35f2fb50c Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Sun, 3 Mar 2024 14:32:43 +0100
Subject: [PATCH 02/23] balances resource api parity (#328)
---
docs/README.md | 32 +++++++++++-----
mollie/balances.go | 3 --
mollie/custom_types.go | 29 +++++++++++++++
mollie/custom_types_test.go | 73 +++++++++++++++++++++++++++++++++++++
4 files changed, 124 insertions(+), 13 deletions(-)
create mode 100644 mollie/custom_types.go
create mode 100644 mollie/custom_types_test.go
diff --git a/docs/README.md b/docs/README.md
index 748164cc..729dab67 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -98,6 +98,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(c \*Config\) ToggleTesting\(\) bool](<#Config.ToggleTesting>)
- [type ContextValue](<#ContextValue>)
- [type ContextValues](<#ContextValues>)
+ - [func \(cv \*ContextValues\) UnmarshalJSON\(data \[\]byte\) error](<#ContextValues.UnmarshalJSON>)
- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
- [type CreatePayment](<#CreatePayment>)
- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
@@ -676,7 +677,7 @@ type BalanceTransaction struct {
```
-## type [BalanceTransactionsList]()
+## type [BalanceTransactionsList]()
BalanceTransactionsList contains an array of embedded transactions.
@@ -691,7 +692,7 @@ type BalanceTransactionsList struct {
```
-## type [BalanceTransactionsListOptions]()
+## type [BalanceTransactionsListOptions]()
BalanceTransactionsListOptions are valid query parameters for list balance transactions requests.
@@ -733,7 +734,7 @@ type BalancesService service
```
-### func \(\*BalancesService\) [Get]()
+### func \(\*BalancesService\) [Get]()
```go
func (bs *BalancesService) Get(ctx context.Context, balance string) (res *Response, b *Balance, err error)
@@ -744,7 +745,7 @@ GetBalance retrieves a balance by its id.
See: https://docs.mollie.com/reference/v2/balances-api/get-balance
-### func \(\*BalancesService\) [GetPrimaryReport]()
+### func \(\*BalancesService\) [GetPrimaryReport]()
```go
func (bs *BalancesService) GetPrimaryReport(ctx context.Context, options *BalanceReportOptions) (res *Response, br *BalanceReport, err error)
@@ -755,7 +756,7 @@ GetPrimaryReport returns the report for the primary balance.
See: https://docs.mollie.com/reference/v2/balances-api/get-primary-balance-report
-### func \(\*BalancesService\) [GetPrimaryTransactionsList]()
+### func \(\*BalancesService\) [GetPrimaryTransactionsList]()
```go
func (bs *BalancesService) GetPrimaryTransactionsList(ctx context.Context, options *BalanceTransactionsListOptions) (res *Response, btl *BalanceTransactionsList, err error)
@@ -766,7 +767,7 @@ GetPrimaryTransactionsList retrieves the list of movements \(transactions\) for
See: https://docs.mollie.com/reference/v2/balances-api/list-primary-balance-transactions
-### func \(\*BalancesService\) [GetReport]()
+### func \(\*BalancesService\) [GetReport]()
```go
func (bs *BalancesService) GetReport(ctx context.Context, balance string, options *BalanceReportOptions) (res *Response, br *BalanceReport, err error)
@@ -777,7 +778,7 @@ GetReport returns the balance report for the specified balance id.
See: https://docs.mollie.com/reference/v2/balances-api/get-balance-report
-### func \(\*BalancesService\) [GetTransactionsList]()
+### func \(\*BalancesService\) [GetTransactionsList]()
```go
func (bs *BalancesService) GetTransactionsList(ctx context.Context, balance string, options *BalanceTransactionsListOptions) (res *Response, btl *BalanceTransactionsList, err error)
@@ -788,7 +789,7 @@ GetTransactionsList retrieves a list of movements \(transactions\) for the speci
See: https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions
-### func \(\*BalancesService\) [List]()
+### func \(\*BalancesService\) [List]()
```go
func (bs *BalancesService) List(ctx context.Context, options *BalanceListOptions) (res *Response, bl *BalancesList, err error)
@@ -799,7 +800,7 @@ List retrieves all the organization’s balances, including the primary balance,
See: https://docs.mollie.com/reference/v2/balances-api/list-balances
-### func \(\*BalancesService\) [Primary]()
+### func \(\*BalancesService\) [Primary]()
```go
func (bs *BalancesService) Primary(ctx context.Context) (res *Response, b *Balance, err error)
@@ -1702,7 +1703,7 @@ type ContextValue string
```
-## type [ContextValues]()
+## type [ContextValues]()
ContextValues is a map of TransactionType to ContextValue.
@@ -1710,6 +1711,17 @@ ContextValues is a map of TransactionType to ContextValue.
type ContextValues map[TransactionType]ContextValue
```
+
+### func \(\*ContextValues\) [UnmarshalJSON]()
+
+```go
+func (cv *ContextValues) UnmarshalJSON(data []byte) error
+```
+
+UnmarshalJSON implements the json.Unmarshaler interface on ContextValues.
+
+See: https://github.com/VictorAvelar/mollie-api-go/issues/251
+
## type [CreateMollieConnectPaymentFields]()
diff --git a/mollie/balances.go b/mollie/balances.go
index 631accfa..01b50498 100644
--- a/mollie/balances.go
+++ b/mollie/balances.go
@@ -208,9 +208,6 @@ const (
PlatformPaymentChargeback TransactionType = "platform-payment-chargeback"
)
-// ContextValues is a map of TransactionType to ContextValue.
-type ContextValues map[TransactionType]ContextValue
-
// BalanceTransactionsList contains an array of embedded transactions.
type BalanceTransactionsList struct {
Count int `json:"count,omitempty"`
diff --git a/mollie/custom_types.go b/mollie/custom_types.go
new file mode 100644
index 00000000..82abbf24
--- /dev/null
+++ b/mollie/custom_types.go
@@ -0,0 +1,29 @@
+package mollie
+
+import (
+ "encoding/json"
+)
+
+// ContextValues is a map of TransactionType to ContextValue.
+type ContextValues map[TransactionType]ContextValue
+
+// UnmarshalJSON implements the json.Unmarshaler interface on ContextValues.
+//
+// See: https://github.com/VictorAvelar/mollie-api-go/issues/251
+func (cv *ContextValues) UnmarshalJSON(data []byte) error {
+ var d map[TransactionType]ContextValue
+
+ if err := json.Unmarshal(data, &d); err != nil {
+ if _, ok := err.(*json.UnmarshalTypeError); ok {
+ *cv = make(ContextValues)
+
+ return nil
+ }
+
+ return err
+ }
+
+ *cv = ContextValues(d)
+
+ return nil
+}
diff --git a/mollie/custom_types_test.go b/mollie/custom_types_test.go
new file mode 100644
index 00000000..e7f3cc7e
--- /dev/null
+++ b/mollie/custom_types_test.go
@@ -0,0 +1,73 @@
+package mollie
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestContextValues_UnmarshalJSON(t *testing.T) {
+ tests := []struct {
+ name string
+ data []byte
+ want ContextValues
+ wantErr bool
+ }{
+ // Add test cases here
+ {
+ name: "Correct decoding JSON",
+ data: []byte(`{"type1": "value1", "type2": "value2"}`),
+ want: ContextValues{
+ "type1": "value1",
+ "type2": "value2",
+ },
+ wantErr: false,
+ },
+ {
+ name: "Handle empty JSON",
+ data: []byte(`{}`),
+ want: ContextValues{},
+ wantErr: false,
+ },
+ {
+ name: "Invalid JSON",
+ data: []byte(`{"type1": "value1", "type2": "value2"`),
+ want: make(ContextValues),
+ wantErr: true,
+ },
+ {
+ name: "Incorrect type in json returns an empty map",
+ data: []byte(`{"type1":["value1", "value2"]}`),
+ want: make(ContextValues),
+ wantErr: false,
+ },
+ {
+ name: "Test correct case described on issue #251",
+ data: []byte(`{"context": {
+ "paymentId": "tr_xxxxxxxx"
+ }}`),
+ want: make(ContextValues),
+ wantErr: false,
+ },
+ {
+ name: "Test failing case described on issue #251",
+ data: []byte(`{"context": []}`),
+ want: make(ContextValues),
+ wantErr: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var cv ContextValues
+ err := cv.UnmarshalJSON(tt.data)
+
+ if tt.wantErr {
+ assert.Error(t, err)
+ } else {
+ assert.NoError(t, err)
+ assert.Equal(t, tt.want, cv)
+ }
+ })
+ }
+}
From f7975316bc7340cd173c89a61fc20f4000bc3379 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
Date: Sun, 3 Mar 2024 13:36:30 +0000
Subject: [PATCH 03/23] fix(scrutinizer): use latest go version
---
.scrutinizer.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index 9cde2516..6327ab5a 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -12,7 +12,7 @@ build:
- "true"
environment:
go:
- version: go1.17
+ version: go1.22
tests:
override:
- go-scrutinizer-run
From 8a6c0e17e1db3ddae2e04f3e59476fabe915ce52 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Sun, 3 Mar 2024 20:35:50 +0100
Subject: [PATCH 04/23] check captures resource against api reference. (#330)
---
.github/workflows/golangci-lint.yml | 4 +
docs/README.md | 112 ++++++++++++++---
mollie/captures.go | 105 +++++++++++++---
mollie/captures_test.go | 188 +++++++++++++++++++++++++++-
testdata/captures.go | 57 +++++++++
5 files changed, 427 insertions(+), 39 deletions(-)
diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml
index f6425887..a0a3d888 100644
--- a/.github/workflows/golangci-lint.yml
+++ b/.github/workflows/golangci-lint.yml
@@ -35,11 +35,15 @@ jobs:
permissions:
contents: read
pull-requests: read
+ checks: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
+ with:
+ fetch-depth: '0'
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: 1.22.X
- uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804
with:
version: latest
+ install-mode: binary
diff --git a/docs/README.md b/docs/README.md
index 729dab67..81da279a 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -54,11 +54,15 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(be \*BaseError\) Error\(\) string](<#BaseError.Error>)
- [type BusinessCategory](<#BusinessCategory>)
- [type Capture](<#Capture>)
+- [type CaptureAccessTokenFields](<#CaptureAccessTokenFields>)
- [type CaptureLinks](<#CaptureLinks>)
- [type CaptureMode](<#CaptureMode>)
+- [type CaptureOptions](<#CaptureOptions>)
+- [type CaptureStatus](<#CaptureStatus>)
- [type CapturesList](<#CapturesList>)
- [type CapturesService](<#CapturesService>)
- - [func \(cs \*CapturesService\) Get\(ctx context.Context, payment, capture string\) \(res \*Response, c \*Capture, err error\)](<#CapturesService.Get>)
+ - [func \(cs \*CapturesService\) Create\(ctx context.Context, payment string, capture CreateCapture\) \(res \*Response, c \*Capture, err error\)](<#CapturesService.Create>)
+ - [func \(cs \*CapturesService\) Get\(ctx context.Context, payment, capture string, options \*CaptureOptions\) \(res \*Response, c \*Capture, err error\)](<#CapturesService.Get>)
- [func \(cs \*CapturesService\) List\(ctx context.Context, payment string\) \(res \*Response, cl \*CapturesList, err error\)](<#CapturesService.List>)
- [type CardLabel](<#CardLabel>)
- [type CategoryCode](<#CategoryCode>)
@@ -99,6 +103,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type ContextValue](<#ContextValue>)
- [type ContextValues](<#ContextValues>)
- [func \(cv \*ContextValues\) UnmarshalJSON\(data \[\]byte\) error](<#ContextValues.UnmarshalJSON>)
+- [type CreateCapture](<#CreateCapture>)
- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
- [type CreatePayment](<#CreatePayment>)
- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
@@ -987,27 +992,41 @@ const (
```
-## type [Capture]()
+## type [Capture]()
Capture describes a single capture. Captures are used for payments that have the authorize\-then\-capture flow.
```go
type Capture struct {
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- Mode Mode `json:"mode,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- SettlementAmount *Amount `json:"settlementAmount,omitempty"`
- PaymentID string `json:"paymentId,omitempty"`
- ShipmentID string `json:"shipmentId,omitempty"`
- SettlementID string `json:"settlementId,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
- Links CaptureLinks `json:"_links,omitempty"`
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ Mode Mode `json:"mode,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ Status CaptureStatus `json:"status,omitempty"`
+ SettlementAmount *Amount `json:"settlementAmount,omitempty"`
+ PaymentID string `json:"paymentId,omitempty"`
+ ShipmentID string `json:"shipmentId,omitempty"`
+ SettlementID string `json:"settlementId,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Links CaptureLinks `json:"_links,omitempty"`
+ AccessTokenPaymentFields
+}
+```
+
+
+## type [CaptureAccessTokenFields]()
+
+CaptureAccessTokenFields describes the payload for creating a capture with an access token.
+
+```go
+type CaptureAccessTokenFields struct {
+ Testmode bool `json:"testmode,omitempty"`
}
```
-## type [CaptureLinks]()
+## type [CaptureLinks]()
CaptureLinks contains relevant links for a capture object.
@@ -1039,8 +1058,40 @@ const (
)
```
+
+## type [CaptureOptions]()
+
+CaptureOptions describes the query params available to use when retrieving captures.
+
+See: https://docs.mollie.com/reference/v2/captures-api/get-capture#embedding-of-related-resources
+
+```go
+type CaptureOptions struct {
+ Embed []EmbedValue `url:"embed,omitempty"`
+}
+```
+
+
+## type [CaptureStatus]()
+
+CaptureStatus describes the status of a capture.
+
+```go
+type CaptureStatus string
+```
+
+CaptureStatus possible values.
+
+```go
+const (
+ CaptureStatusPending CaptureStatus = "pending"
+ CaptureStatusSucceeded CaptureStatus = "succeeded"
+ CaptureStatusFailed CaptureStatus = "failed"
+)
+```
+
-## type [CapturesList]()
+## type [CapturesList]()
CapturesList describes a list of captures.
@@ -1055,7 +1106,7 @@ type CapturesList struct {
```
-## type [CapturesService]()
+## type [CapturesService]()
CapturesService operates over captures resource.
@@ -1063,11 +1114,22 @@ CapturesService operates over captures resource.
type CapturesService service
```
+
+### func \(\*CapturesService\) [Create]()
+
+```go
+func (cs *CapturesService) Create(ctx context.Context, payment string, capture CreateCapture) (res *Response, c *Capture, err error)
+```
+
+Create creates a new capture for a payment.
+
+See: https://docs.mollie.com/reference/v2/captures-api/create-capture
+
-### func \(\*CapturesService\) [Get]()
+### func \(\*CapturesService\) [Get]()
```go
-func (cs *CapturesService) Get(ctx context.Context, payment, capture string) (res *Response, c *Capture, err error)
+func (cs *CapturesService) Get(ctx context.Context, payment, capture string, options *CaptureOptions) (res *Response, c *Capture, err error)
```
Get retrieves a single capture by its ID. Note the original payment’s ID is needed as well.
@@ -1075,7 +1137,7 @@ Get retrieves a single capture by its ID. Note the original payment’s ID is ne
See: https://docs.mollie.com/reference/v2/captures-api/get-capture
-### func \(\*CapturesService\) [List]()
+### func \(\*CapturesService\) [List]()
```go
func (cs *CapturesService) List(ctx context.Context, payment string) (res *Response, cl *CapturesList, err error)
@@ -1722,6 +1784,20 @@ UnmarshalJSON implements the json.Unmarshaler interface on ContextValues.
See: https://github.com/VictorAvelar/mollie-api-go/issues/251
+
+## type [CreateCapture]()
+
+CreateCapture describes the payload for creating a capture.
+
+```go
+type CreateCapture struct {
+ Description string `json:"description,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ CaptureAccessTokenFields
+}
+```
+
## type [CreateMollieConnectPaymentFields]()
diff --git a/mollie/captures.go b/mollie/captures.go
index ea690e58..50936be0 100644
--- a/mollie/captures.go
+++ b/mollie/captures.go
@@ -16,8 +16,46 @@ const (
ManualCapture CaptureMode = "manual"
)
-// CapturesService operates over captures resource.
-type CapturesService service
+// CaptureStatus describes the status of a capture.
+type CaptureStatus string
+
+// CaptureStatus possible values.
+const (
+ CaptureStatusPending CaptureStatus = "pending"
+ CaptureStatusSucceeded CaptureStatus = "succeeded"
+ CaptureStatusFailed CaptureStatus = "failed"
+)
+
+// CreateCapture describes the payload for creating a capture.
+type CreateCapture struct {
+ Description string `json:"description,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ CaptureAccessTokenFields
+}
+
+// CaptureAccessTokenFields describes the payload for creating a capture with an access token.
+type CaptureAccessTokenFields struct {
+ Testmode bool `json:"testmode,omitempty"`
+}
+
+// Capture describes a single capture.
+// Captures are used for payments that have the authorize-then-capture flow.
+type Capture struct {
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ Mode Mode `json:"mode,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ Status CaptureStatus `json:"status,omitempty"`
+ SettlementAmount *Amount `json:"settlementAmount,omitempty"`
+ PaymentID string `json:"paymentId,omitempty"`
+ ShipmentID string `json:"shipmentId,omitempty"`
+ SettlementID string `json:"settlementId,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ Links CaptureLinks `json:"_links,omitempty"`
+ AccessTokenPaymentFields
+}
// CaptureLinks contains relevant links for a capture object.
type CaptureLinks struct {
@@ -28,19 +66,11 @@ type CaptureLinks struct {
Documentation *URL `json:"documentation,omitempty"`
}
-// Capture describes a single capture.
-// Captures are used for payments that have the authorize-then-capture flow.
-type Capture struct {
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- Mode Mode `json:"mode,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- SettlementAmount *Amount `json:"settlementAmount,omitempty"`
- PaymentID string `json:"paymentId,omitempty"`
- ShipmentID string `json:"shipmentId,omitempty"`
- SettlementID string `json:"settlementId,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
- Links CaptureLinks `json:"_links,omitempty"`
+// CaptureOptions describes the query params available to use when retrieving captures.
+//
+// See: https://docs.mollie.com/reference/v2/captures-api/get-capture#embedding-of-related-resources
+type CaptureOptions struct {
+ Embed []EmbedValue `url:"embed,omitempty"`
}
// CapturesList describes a list of captures.
@@ -52,14 +82,47 @@ type CapturesList struct {
Links PaginationLinks `json:"_links,omitempty"`
}
+// CapturesService operates over captures resource.
+type CapturesService service
+
// Get retrieves a single capture by its ID.
// Note the original payment’s ID is needed as well.
//
// See: https://docs.mollie.com/reference/v2/captures-api/get-capture
-func (cs *CapturesService) Get(ctx context.Context, payment, capture string) (res *Response, c *Capture, err error) {
+func (cs *CapturesService) Get(ctx context.Context, payment, capture string, options *CaptureOptions) (
+ res *Response,
+ c *Capture,
+ err error,
+) {
u := fmt.Sprintf("v2/payments/%s/captures/%s", payment, capture)
- res, err = cs.client.get(ctx, u, nil)
+ res, err = cs.client.get(ctx, u, options)
+ if err != nil {
+ return
+ }
+
+ if err = json.Unmarshal(res.content, &c); err != nil {
+ return
+ }
+
+ return
+}
+
+// Create creates a new capture for a payment.
+//
+// See: https://docs.mollie.com/reference/v2/captures-api/create-capture
+func (cs *CapturesService) Create(ctx context.Context, payment string, capture CreateCapture) (
+ res *Response,
+ c *Capture,
+ err error,
+) {
+ u := fmt.Sprintf("v2/payments/%s/captures", payment)
+
+ if cs.client.HasAccessToken() && cs.client.config.testing {
+ capture.Testmode = true
+ }
+
+ res, err = cs.client.post(ctx, u, capture, nil)
if err != nil {
return
}
@@ -74,10 +137,14 @@ func (cs *CapturesService) Get(ctx context.Context, payment, capture string) (re
// List retrieves all captures for a certain payment.
//
// See: https://docs.mollie.com/reference/v2/captures-api/list-captures
-func (cs *CapturesService) List(ctx context.Context, payment string) (res *Response, cl *CapturesList, err error) {
+func (cs *CapturesService) List(ctx context.Context, payment string, options *CaptureOptions) (
+ res *Response,
+ cl *CapturesList,
+ err error,
+) {
u := fmt.Sprintf("v2/payments/%s/captures", payment)
- res, err = cs.client.get(ctx, u, nil)
+ res, err = cs.client.get(ctx, u, options)
if err != nil {
return
}
diff --git a/mollie/captures_test.go b/mollie/captures_test.go
index 4c0a939c..b2617e1d 100644
--- a/mollie/captures_test.go
+++ b/mollie/captures_test.go
@@ -18,6 +18,7 @@ func TestCapturesService_Get(t *testing.T) {
ctx context.Context
payment string
capture string
+ options *CaptureOptions
}
cases := []struct {
@@ -34,6 +35,7 @@ func TestCapturesService_Get(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ nil,
},
false,
nil,
@@ -48,12 +50,37 @@ func TestCapturesService_Get(t *testing.T) {
},
noPre,
},
+ {
+ "get captures works expands query params correctly",
+ args{
+ context.Background(),
+ "tr_WDqYK6vllg",
+ "cpt_4qqhO89gsT",
+ &CaptureOptions{
+ Embed: []EmbedValue{EmbedPayment},
+ },
+ },
+ false,
+ nil,
+ func(w http.ResponseWriter, r *http.Request) {
+ testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
+ testMethod(t, r, "GET")
+ testQuery(t, r, "embed=payments")
+ if _, ok := r.Header[AuthHeader]; !ok {
+ w.WriteHeader(http.StatusUnauthorized)
+ }
+
+ _, _ = w.Write([]byte(testdata.GetCaptureResponse))
+ },
+ noPre,
+ },
{
"get captures returns an http error from the server",
args{
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ nil,
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -66,6 +93,7 @@ func TestCapturesService_Get(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ nil,
},
true,
errBadBaseURL,
@@ -78,6 +106,7 @@ func TestCapturesService_Get(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ nil,
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -102,7 +131,7 @@ func TestCapturesService_Get(t *testing.T) {
c.handler,
)
- res, capture, err := tClient.Captures.Get(c.args.ctx, c.args.payment, c.args.capture)
+ res, capture, err := tClient.Captures.Get(c.args.ctx, c.args.payment, c.args.capture, c.args.options)
if c.wantErr {
assert.NotNil(t, err)
assert.EqualError(t, err, c.err.Error())
@@ -116,6 +145,152 @@ func TestCapturesService_Get(t *testing.T) {
}
}
+func TestCapturesService_Create(t *testing.T) {
+ setEnv()
+ defer unsetEnv()
+
+ type args struct {
+ ctx context.Context
+ payment string
+ capture CreateCapture
+ options *CaptureOptions
+ }
+
+ cases := []struct {
+ name string
+ args args
+ wantErr bool
+ err error
+ handler http.HandlerFunc
+ pre func()
+ }{
+ {
+ "create captures works as expected",
+ args{
+ context.Background(),
+ "tr_WDqYK6vllg",
+ CreateCapture{
+ Amount: &Amount{
+ Value: "20.00",
+ Currency: "EUR",
+ },
+ Description: "Order #12345",
+ },
+ nil,
+ },
+ false,
+ nil,
+ func(w http.ResponseWriter, r *http.Request) {
+ testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
+ testMethod(t, r, "POST")
+ if _, ok := r.Header[AuthHeader]; !ok {
+ w.WriteHeader(http.StatusUnauthorized)
+ }
+
+ _, _ = w.Write([]byte(testdata.CreateCaptureResponse))
+ },
+ noPre,
+ },
+ {
+ "create captures works as with access token expected",
+ args{
+ context.Background(),
+ "tr_WDqYK6vllg",
+ CreateCapture{
+ Amount: &Amount{
+ Value: "20.00",
+ Currency: "EUR",
+ },
+ Description: "Order #12345",
+ },
+ nil,
+ },
+ false,
+ nil,
+ func(w http.ResponseWriter, r *http.Request) {
+ testHeader(t, r, AuthHeader, "Bearer access_token_test")
+ testMethod(t, r, "POST")
+ if _, ok := r.Header[AuthHeader]; !ok {
+ w.WriteHeader(http.StatusUnauthorized)
+ }
+
+ _, _ = w.Write([]byte(testdata.CreateCaptureWithAccessTokenResponse))
+ },
+ setAccessToken,
+ },
+ {
+ "create captures returns an http error from the server",
+ args{
+ context.Background(),
+ "tr_WDqYK6vllg",
+ CreateCapture{},
+ nil,
+ },
+ true,
+ fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
+ errorHandler,
+ noPre,
+ },
+ {
+ "create captures returns an error when creating the request",
+ args{
+ context.Background(),
+ "tr_WDqYK6vllg",
+ CreateCapture{},
+ nil,
+ },
+ true,
+ errBadBaseURL,
+ errorHandler,
+ crashSrv,
+ },
+ {
+ "create captures returns an error when trying to parse the json response",
+ args{
+ context.Background(),
+ "tr_WDqYK6vllg",
+ CreateCapture{},
+ nil,
+ },
+ true,
+ fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
+ encodingHandler,
+ noPre,
+ },
+ }
+
+ for _, c := range cases {
+ setup()
+ defer teardown()
+
+ t.Run(c.name, func(t *testing.T) {
+ c.pre()
+
+ tMux.HandleFunc(
+ fmt.Sprintf(
+ "/v2/payments/%s/captures",
+ c.args.payment,
+ ),
+ c.handler,
+ )
+
+ res, capture, err := tClient.Captures.Create(c.args.ctx, c.args.payment, c.args.capture)
+ if c.wantErr {
+ assert.NotNil(t, err)
+ assert.EqualError(t, err, c.err.Error())
+ if tClient.HasAccessToken() {
+ assert.True(t, capture.Testmode)
+ }
+ } else {
+ assert.Nil(t, err)
+ assert.IsType(t, &Capture{}, capture)
+ assert.EqualValues(t, c.args.ctx, res.Request.Context())
+ assert.IsType(t, &http.Response{}, res.Response)
+ }
+ })
+ }
+}
+
func TestCapturesService_List(t *testing.T) {
setEnv()
defer unsetEnv()
@@ -124,6 +299,7 @@ func TestCapturesService_List(t *testing.T) {
ctx context.Context
payment string
capture string
+ options *CaptureOptions
}
type key string
@@ -142,12 +318,17 @@ func TestCapturesService_List(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ &CaptureOptions{
+ Embed: []EmbedValue{EmbedPayment},
+ },
},
false,
nil,
func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
testMethod(t, r, "GET")
+ testQuery(t, r, "embed=payments")
+
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
}
@@ -162,6 +343,7 @@ func TestCapturesService_List(t *testing.T) {
context.WithValue(context.Background(), key("test"), "test-value"),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ &CaptureOptions{},
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -174,6 +356,7 @@ func TestCapturesService_List(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ &CaptureOptions{},
},
true,
errBadBaseURL,
@@ -186,6 +369,7 @@ func TestCapturesService_List(t *testing.T) {
context.Background(),
"tr_WDqYK6vllg",
"cpt_4qqhO89gsT",
+ &CaptureOptions{},
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -209,7 +393,7 @@ func TestCapturesService_List(t *testing.T) {
c.handler,
)
- res, list, err := tClient.Captures.List(c.args.ctx, c.args.payment)
+ res, list, err := tClient.Captures.List(c.args.ctx, c.args.payment, c.args.options)
if c.wantErr {
assert.NotNil(t, err)
assert.EqualError(t, err, c.err.Error())
diff --git a/testdata/captures.go b/testdata/captures.go
index 616a605d..d28e7892 100644
--- a/testdata/captures.go
+++ b/testdata/captures.go
@@ -100,3 +100,60 @@ const GetCaptureResponse = `{
}
}
}`
+
+// CreateCaptureResponse example.
+const CreateCaptureResponse = `{
+ "resource": "capture",
+ "id": "cpt_mNepDkEtco6ah3QNPUGYH",
+ "mode": "live",
+ "amount": {
+ "value": "35.95",
+ "currency": "EUR"
+ },
+ "paymentId": "tr_WDqYK6vllg",
+ "createdAt": "2018-08-02T09:29:56+00:00",
+ "description": "Capture for cart #12345",
+ "_links": {
+ "self": {
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_mNepDkEtco6ah3QNPUGYH",
+ "type": "application/hal+json"
+ },
+ "payment": {
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
+ "type": "application/hal+json"
+ },
+ "documentation": {
+ "href": "https://docs.mollie.com/reference/v2/captures-api/create-capture",
+ "type": "text/html"
+ }
+ }
+}`
+
+// CreateCaptureWithAccessTokenResponse example.
+const CreateCaptureWithAccessTokenResponse = `{
+ "resource": "capture",
+ "id": "cpt_mNepDkEtco6ah3QNPUGYH",
+ "mode": "live",
+ "amount": {
+ "value": "35.95",
+ "currency": "EUR"
+ },
+ "paymentId": "tr_WDqYK6vllg",
+ "createdAt": "2018-08-02T09:29:56+00:00",
+ "description": "Capture for cart #12345",
+ "testmode": true,
+ "_links": {
+ "self": {
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_mNepDkEtco6ah3QNPUGYH",
+ "type": "application/hal+json"
+ },
+ "payment": {
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
+ "type": "application/hal+json"
+ },
+ "documentation": {
+ "href": "https://docs.mollie.com/reference/v2/captures-api/create-capture",
+ "type": "text/html"
+ }
+ }
+}`
From a0a7a36896e7a8bbd4b8243e739cb0df61ec0b6b Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Sun, 3 Mar 2024 22:56:59 +0100
Subject: [PATCH 05/23] check chargebacks resource against api reference (#331)
---
Taskfile.yml | 2 +
docs/README.md | 86 +++++++++++++++++++++++++-------------
mollie/captures.go | 2 +-
mollie/chargebacks.go | 46 +++++++++++++-------
mollie/chargebacks_test.go | 8 ++--
testdata/chargebacks.go | 6 ++-
6 files changed, 99 insertions(+), 51 deletions(-)
diff --git a/Taskfile.yml b/Taskfile.yml
index 106be01f..de819ea3 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -64,6 +64,8 @@ tasks:
update-docs:
cmds:
- gomarkdoc --output docs/README.md ./mollie
+ - git add --all
+ - "git commit --message 'chore(docs): update generated docs'"
silent: false
sub-pkg-docs:
diff --git a/docs/README.md b/docs/README.md
index 81da279a..b7bf8ebf 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -63,12 +63,14 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type CapturesService](<#CapturesService>)
- [func \(cs \*CapturesService\) Create\(ctx context.Context, payment string, capture CreateCapture\) \(res \*Response, c \*Capture, err error\)](<#CapturesService.Create>)
- [func \(cs \*CapturesService\) Get\(ctx context.Context, payment, capture string, options \*CaptureOptions\) \(res \*Response, c \*Capture, err error\)](<#CapturesService.Get>)
- - [func \(cs \*CapturesService\) List\(ctx context.Context, payment string\) \(res \*Response, cl \*CapturesList, err error\)](<#CapturesService.List>)
+ - [func \(cs \*CapturesService\) List\(ctx context.Context, payment string, options \*CaptureOptions\) \(res \*Response, cl \*CapturesList, err error\)](<#CapturesService.List>)
- [type CardLabel](<#CardLabel>)
- [type CategoryCode](<#CategoryCode>)
- [type Chargeback](<#Chargeback>)
+- [type ChargebackAccessTokenFields](<#ChargebackAccessTokenFields>)
- [type ChargebackLinks](<#ChargebackLinks>)
- [type ChargebackOptions](<#ChargebackOptions>)
+- [type ChargebackReason](<#ChargebackReason>)
- [type ChargebacksList](<#ChargebacksList>)
- [type ChargebacksListOptions](<#ChargebacksListOptions>)
- [type ChargebacksService](<#ChargebacksService>)
@@ -1010,7 +1012,7 @@ type Capture struct {
CreatedAt *time.Time `json:"createdAt,omitempty"`
Metadata any `json:"metadata,omitempty"`
Links CaptureLinks `json:"_links,omitempty"`
- AccessTokenPaymentFields
+ CaptureAccessTokenFields
}
```
@@ -1137,10 +1139,10 @@ Get retrieves a single capture by its ID. Note the original payment’s ID is ne
See: https://docs.mollie.com/reference/v2/captures-api/get-capture
-### func \(\*CapturesService\) [List]()
+### func \(\*CapturesService\) [List]()
```go
-func (cs *CapturesService) List(ctx context.Context, payment string) (res *Response, cl *CapturesList, err error)
+func (cs *CapturesService) List(ctx context.Context, payment string, options *CaptureOptions) (res *Response, cl *CapturesList, err error)
```
List retrieves all captures for a certain payment.
@@ -1214,25 +1216,39 @@ const (
```
-## type [Chargeback]()
+## type [Chargeback]()
Chargeback describes a forced transaction reversal initiated by the cardholder's bank.
```go
type Chargeback struct {
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- SettlementAmount *Amount `json:"settlementAmount,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
- ReversedAt *time.Time `json:"reversedAt,omitempty"`
- PaymentID string `json:"paymentId,omitempty"`
- Links ChargebackLinks `json:"_links,omitempty"`
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ PaymentID string `json:"paymentId,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ SettlementAmount *Amount `json:"settlementAmount,omitempty"`
+ Reason *ChargebackReason `json:"reason,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ ReversedAt *time.Time `json:"reversedAt,omitempty"`
+ Links ChargebackLinks `json:"_links,omitempty"`
+ ChargebackAccessTokenFields
+}
+```
+
+
+## type [ChargebackAccessTokenFields]()
+
+ChargebackAccessTokenFields describes the fields to be used to create a chargeback access token.
+
+```go
+type ChargebackAccessTokenFields struct {
+ ProfileID string `json:"profileId,omitempty"`
+ Testmode bool `json:"testmode,omitempty"`
}
```
-## type [ChargebackLinks]()
+## type [ChargebackLinks]()
ChargebackLinks describes all the possible links to be returned with a chargeback object.
@@ -1246,19 +1262,31 @@ type ChargebackLinks struct {
```
-## type [ChargebackOptions]()
+## type [ChargebackOptions]()
ChargebackOptions describes chargeback endpoint valid query string parameters.
```go
type ChargebackOptions struct {
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
+}
+```
+
+
+## type [ChargebackReason]()
+
+ChargebackReason describes the reason for the chargeback as given by the bank.
+
+```go
+type ChargebackReason struct {
+ Code string `json:"code,omitempty"`
+ Description string `json:"description,omitempty"`
}
```
-## type [ChargebacksList]()
+## type [ChargebacksList]()
ChargebacksList describes how a list of chargebacks will be retrieved by Mollie.
@@ -1266,29 +1294,29 @@ ChargebacksList describes how a list of chargebacks will be retrieved by Mollie.
type ChargebacksList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Chargebacks []Chargeback
+ Chargebacks []*Chargeback
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
```
-## type [ChargebacksListOptions]()
+## type [ChargebacksListOptions]()
ChargebacksListOptions describes list chargebacks endpoint valid query string parameters.
```go
type ChargebacksListOptions struct {
- From string `url:"from,omitempty"`
- Limit int `url:"limit,omitempty"`
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
- ProfileID string `url:"profileId,omitempty"`
+ From string `url:"from,omitempty"`
+ Limit int `url:"limit,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
+ ProfileID string `url:"profileId,omitempty"`
}
```
-## type [ChargebacksService]()
+## type [ChargebacksService]()
ChargebacksService instance operates over chargeback resources.
@@ -1297,7 +1325,7 @@ type ChargebacksService service
```
-### func \(\*ChargebacksService\) [Get]()
+### func \(\*ChargebacksService\) [Get]()
```go
func (cs *ChargebacksService) Get(ctx context.Context, payment, chargeback string, opts *ChargebackOptions) (res *Response, p *Chargeback, err error)
@@ -1308,7 +1336,7 @@ Get retrieves a single chargeback by its ID. Note the original payment’s ID is
See: https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback
-### func \(\*ChargebacksService\) [List]()
+### func \(\*ChargebacksService\) [List]()
```go
func (cs *ChargebacksService) List(ctx context.Context, options *ChargebacksListOptions) (res *Response, cl *ChargebacksList, err error)
@@ -1319,7 +1347,7 @@ List retrieves a list of chargebacks associated with your account/organization.
See: https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks
-### func \(\*ChargebacksService\) [ListForPayment]()
+### func \(\*ChargebacksService\) [ListForPayment]()
```go
func (cs *ChargebacksService) ListForPayment(ctx context.Context, payment string, options *ChargebacksListOptions) (res *Response, cl *ChargebacksList, err error)
diff --git a/mollie/captures.go b/mollie/captures.go
index 50936be0..b251a600 100644
--- a/mollie/captures.go
+++ b/mollie/captures.go
@@ -54,7 +54,7 @@ type Capture struct {
CreatedAt *time.Time `json:"createdAt,omitempty"`
Metadata any `json:"metadata,omitempty"`
Links CaptureLinks `json:"_links,omitempty"`
- AccessTokenPaymentFields
+ CaptureAccessTokenFields
}
// CaptureLinks contains relevant links for a capture object.
diff --git a/mollie/chargebacks.go b/mollie/chargebacks.go
index 39c868ee..834ac279 100644
--- a/mollie/chargebacks.go
+++ b/mollie/chargebacks.go
@@ -9,14 +9,28 @@ import (
// Chargeback describes a forced transaction reversal initiated by the cardholder's bank.
type Chargeback struct {
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- SettlementAmount *Amount `json:"settlementAmount,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
- ReversedAt *time.Time `json:"reversedAt,omitempty"`
- PaymentID string `json:"paymentId,omitempty"`
- Links ChargebackLinks `json:"_links,omitempty"`
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ PaymentID string `json:"paymentId,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ SettlementAmount *Amount `json:"settlementAmount,omitempty"`
+ Reason *ChargebackReason `json:"reason,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
+ ReversedAt *time.Time `json:"reversedAt,omitempty"`
+ Links ChargebackLinks `json:"_links,omitempty"`
+ ChargebackAccessTokenFields
+}
+
+// ChargebackReason describes the reason for the chargeback as given by the bank.
+type ChargebackReason struct {
+ Code string `json:"code,omitempty"`
+ Description string `json:"description,omitempty"`
+}
+
+// ChargebackAccessTokenFields describes the fields to be used to create a chargeback access token.
+type ChargebackAccessTokenFields struct {
+ ProfileID string `json:"profileId,omitempty"`
+ Testmode bool `json:"testmode,omitempty"`
}
// ChargebackLinks describes all the possible links to be returned with
@@ -30,24 +44,24 @@ type ChargebackLinks struct {
// ChargebackOptions describes chargeback endpoint valid query string parameters.
type ChargebackOptions struct {
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
}
// ChargebacksListOptions describes list chargebacks endpoint valid query string parameters.
type ChargebacksListOptions struct {
- From string `url:"from,omitempty"`
- Limit int `url:"limit,omitempty"`
- Include string `url:"include,omitempty"`
- Embed string `url:"embed,omitempty"`
- ProfileID string `url:"profileId,omitempty"`
+ From string `url:"from,omitempty"`
+ Limit int `url:"limit,omitempty"`
+ Include []IncludeValue `url:"include,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
+ ProfileID string `url:"profileId,omitempty"`
}
// ChargebacksList describes how a list of chargebacks will be retrieved by Mollie.
type ChargebacksList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Chargebacks []Chargeback
+ Chargebacks []*Chargeback
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
diff --git a/mollie/chargebacks_test.go b/mollie/chargebacks_test.go
index 2887b099..83999875 100644
--- a/mollie/chargebacks_test.go
+++ b/mollie/chargebacks_test.go
@@ -37,7 +37,7 @@ func TestChargebacksService_Get(t *testing.T) {
"tr_WDqYK6vllg",
"chb_n9z0tp",
&ChargebackOptions{
- Include: "details.qrCode",
+ Include: []IncludeValue{IncludeQrCode},
},
},
false,
@@ -60,7 +60,7 @@ func TestChargebacksService_Get(t *testing.T) {
"tr_WDqYK6vllg",
"chb_n9z0tp",
&ChargebackOptions{
- Include: "details.qrCode",
+ Include: []IncludeValue{IncludeQrCode},
},
},
true,
@@ -75,7 +75,7 @@ func TestChargebacksService_Get(t *testing.T) {
"tr_WDqYK6vllg",
"chb_n9z0tp",
&ChargebackOptions{
- Include: "details.qrCode",
+ Include: []IncludeValue{IncludeQrCode},
},
},
true,
@@ -93,7 +93,7 @@ func TestChargebacksService_Get(t *testing.T) {
"tr_WDqYK6vllg",
"chb_n9z0tp",
&ChargebackOptions{
- Include: "details.qrCode",
+ Include: []IncludeValue{IncludeQrCode},
},
},
true,
diff --git a/testdata/chargebacks.go b/testdata/chargebacks.go
index 38a6d06c..aac830e7 100644
--- a/testdata/chargebacks.go
+++ b/testdata/chargebacks.go
@@ -13,6 +13,10 @@ const (
"value": "-35.07"
},
"createdAt": "2018-03-14T17:00:52.0Z",
+ "reason": {
+ "code": "AC01",
+ "description": "Account identifier incorrect (i.e. invalid IBAN)"
+ },
"reversedAt": null,
"paymentId": "tr_WDqYK6vllg",
"_links": {
@@ -25,7 +29,7 @@ const (
"type": "application/hal+json"
},
"documentation": {
- "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
+ "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-payment-chargeback",
"type": "text/html"
}
}
From a74c8f610ce034f13fbebb9f02ea0e5d937ea1dd Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Mon, 4 Mar 2024 10:28:58 +0100
Subject: [PATCH 06/23] check client_links resources against api reference
(#333)
---
docs/README.md | 78 ++++++++++++++++++-------------------
mollie/client_links.go | 33 ++++++++--------
mollie/client_links_test.go | 47 ++++++++++++----------
mollie/permissions.go | 2 +-
4 files changed, 83 insertions(+), 77 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index b7bf8ebf..0418b941 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -84,13 +84,12 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(c \*Client\) NewAPIRequest\(ctx context.Context, method string, uri string, body interface\{\}\) \(req \*http.Request, err error\)](<#Client.NewAPIRequest>)
- [func \(c \*Client\) SetIdempotencyKeyGenerator\(kg idempotency.KeyGenerator\)](<#Client.SetIdempotencyKeyGenerator>)
- [func \(c \*Client\) WithAuthenticationValue\(k string\) error](<#Client.WithAuthenticationValue>)
-- [type ClientDetails](<#ClientDetails>)
- [type ClientLink](<#ClientLink>)
-- [type ClientLinkFinalizeOptions](<#ClientLinkFinalizeOptions>)
+- [type ClientLinkAuthorizeOptions](<#ClientLinkAuthorizeOptions>)
- [type ClientLinkLinks](<#ClientLinkLinks>)
- [type ClientLinksService](<#ClientLinksService>)
- - [func \(cls \*ClientLinksService\) CreateClientLink\(ctx context.Context, cd \*ClientDetails\) \(res \*Response, cl \*ClientLink, err error\)](<#ClientLinksService.CreateClientLink>)
- - [func \(cls \*ClientLinksService\) CreateFinalizeClientLink\(ctx context.Context, clientLink string, options \*ClientLinkFinalizeOptions\) \(clientLinkURI string\)](<#ClientLinksService.CreateFinalizeClientLink>)
+ - [func \(cls \*ClientLinksService\) Create\(ctx context.Context, cd CreateClientLink\) \(res \*Response, cl \*ClientLink, err error\)](<#ClientLinksService.Create>)
+ - [func \(cls \*ClientLinksService\) GetFinalClientLink\(ctx context.Context, clientLink string, options \*ClientLinkAuthorizeOptions\) \(clientLinkURI string\)](<#ClientLinksService.GetFinalClientLink>)
- [type Commission](<#Commission>)
- [type Company](<#Company>)
- [type Config](<#Config>)
@@ -106,6 +105,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type ContextValues](<#ContextValues>)
- [func \(cv \*ContextValues\) UnmarshalJSON\(data \[\]byte\) error](<#ContextValues.UnmarshalJSON>)
- [type CreateCapture](<#CreateCapture>)
+- [type CreateClientLink](<#CreateClientLink>)
- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
- [type CreatePayment](<#CreatePayment>)
- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
@@ -1457,23 +1457,8 @@ WithAuthenticationValue offers a convenient setter for any of the valid authenti
Ideally your API key will be provided from and environment variable or a secret management engine. This should only be used when environment variables are "impossible" to be used.
-
-## type [ClientDetails]()
-
-ClientDetails contains information to link a new organization to an OAuth application.
-
-```go
-type ClientDetails struct {
- Owner Owner `json:"owner,omitempty"`
- Name string `json:"name,omitempty"`
- Address *Address `json:"address,omitempty"`
- RegistrationNumber string `json:"registrationNumber,omitempty"`
- VATNumber string `json:"vatNumber,omitempty"`
-}
-```
-
-## type [ClientLink]()
+## type [ClientLink]()
ClientLink object with redirect target.
@@ -1485,22 +1470,22 @@ type ClientLink struct {
}
```
-
-## type [ClientLinkFinalizeOptions]()
+
+## type [ClientLinkAuthorizeOptions]()
-ClientLinkFinalizeOptions subset of the parameters allowed for the Authorize endpoint.
+ClientLinkAuthorizeOptions subset of the parameters allowed for the Authorize endpoint.
```go
-type ClientLinkFinalizeOptions struct {
- ClientID string `url:"clientID,omitempty"`
- State string `url:"state,omitempty"`
- Scope string `url:"scope,omitempty"`
- ApprovalPrompt string `url:"approvalPrompt,omitempty"`
+type ClientLinkAuthorizeOptions struct {
+ ClientID string `url:"clientId,omitempty"`
+ State string `url:"state,omitempty"`
+ Scope []PermissionGrant `del:"+" url:"scope,omitempty"`
+ ApprovalPrompt ApprovalPromptAction `url:"approvalPrompt,omitempty"`
}
```
-## type [ClientLinkLinks]()
+## type [ClientLinkLinks]()
ClientLinkLinks describes all the possible links to be returned with a client links response object.
@@ -1512,7 +1497,7 @@ type ClientLinkLinks struct {
```
-## type [ClientLinksService]()
+## type [ClientLinksService]()
ClientLinksService interacts with the Client Links API to create new organizations for your customers.
@@ -1520,25 +1505,25 @@ ClientLinksService interacts with the Client Links API to create new organizatio
type ClientLinksService service
```
-
-### func \(\*ClientLinksService\) [CreateClientLink]()
+
+### func \(\*ClientLinksService\) [Create]()
```go
-func (cls *ClientLinksService) CreateClientLink(ctx context.Context, cd *ClientDetails) (res *Response, cl *ClientLink, err error)
+func (cls *ClientLinksService) Create(ctx context.Context, cd CreateClientLink) (res *Response, cl *ClientLink, err error)
```
-CreateClientLink based on the provided ClientDetails.
+Create a client link based on the provided CreateClientLink values.
See: https://docs.mollie.com/reference/v2/client-links-api/create-client-link
-
-### func \(\*ClientLinksService\) [CreateFinalizeClientLink]()
+
+### func \(\*ClientLinksService\) [GetFinalClientLink]()
```go
-func (cls *ClientLinksService) CreateFinalizeClientLink(ctx context.Context, clientLink string, options *ClientLinkFinalizeOptions) (clientLinkURI string)
+func (cls *ClientLinksService) GetFinalClientLink(ctx context.Context, clientLink string, options *ClientLinkAuthorizeOptions) (clientLinkURI string)
```
-
+GetFinalClientLink returns the final client link URI with the provided options.
## type [Commission]()
@@ -1826,6 +1811,21 @@ type CreateCapture struct {
}
```
+
+## type [CreateClientLink]()
+
+CreateClientLink contains information to link a new organization to an OAuth application.
+
+```go
+type CreateClientLink struct {
+ Owner Owner `json:"owner,omitempty"`
+ Name string `json:"name,omitempty"`
+ Address *Address `json:"address,omitempty"`
+ RegistrationNumber string `json:"registrationNumber,omitempty"`
+ VATNumber string `json:"vatNumber,omitempty"`
+}
+```
+
## type [CreateMollieConnectPaymentFields]()
@@ -4251,7 +4251,7 @@ const (
ShipmentsWrite PermissionGrant = "shipments.write"
OrganizationsRead PermissionGrant = "organizations.read"
OrganizationsWrite PermissionGrant = "organizations.write"
- OnboardingRead PermissionGrant = "onbording.read"
+ OnboardingRead PermissionGrant = "onboarding.read"
OnboardingWrite PermissionGrant = "onbording.write"
)
```
diff --git a/mollie/client_links.go b/mollie/client_links.go
index 36462936..a833132d 100644
--- a/mollie/client_links.go
+++ b/mollie/client_links.go
@@ -8,13 +8,9 @@ import (
"github.com/google/go-querystring/query"
)
-// ClientLinksService interacts with the Client Links API to create
-// new organizations for your customers.
-type ClientLinksService service
-
-// ClientDetails contains information to link a new organization to an
+// CreateClientLink contains information to link a new organization to an
// OAuth application.
-type ClientDetails struct {
+type CreateClientLink struct {
Owner Owner `json:"owner,omitempty"`
Name string `json:"name,omitempty"`
Address *Address `json:"address,omitempty"`
@@ -36,10 +32,14 @@ type ClientLink struct {
Links ClientLinkLinks `json:"_links,omitempty"`
}
-// CreateClientLink based on the provided ClientDetails.
+// ClientLinksService interacts with the Client Links API to create
+// new organizations for your customers.
+type ClientLinksService service
+
+// Create a client link based on the provided CreateClientLink values.
//
// See: https://docs.mollie.com/reference/v2/client-links-api/create-client-link
-func (cls *ClientLinksService) CreateClientLink(ctx context.Context, cd *ClientDetails) (
+func (cls *ClientLinksService) Create(ctx context.Context, cd CreateClientLink) (
res *Response,
cl *ClientLink,
err error,
@@ -66,18 +66,19 @@ const (
AutoApproval ApprovalPromptAction = "auto"
)
-// ClientLinkFinalizeOptions subset of the parameters allowed for the Authorize endpoint.
-type ClientLinkFinalizeOptions struct {
- ClientID string `url:"clientID,omitempty"`
- State string `url:"state,omitempty"`
- Scope string `url:"scope,omitempty"`
- ApprovalPrompt string `url:"approvalPrompt,omitempty"`
+// ClientLinkAuthorizeOptions subset of the parameters allowed for the Authorize endpoint.
+type ClientLinkAuthorizeOptions struct {
+ ClientID string `url:"clientId,omitempty"`
+ State string `url:"state,omitempty"`
+ Scope []PermissionGrant `del:"+" url:"scope,omitempty"`
+ ApprovalPrompt ApprovalPromptAction `url:"approvalPrompt,omitempty"`
}
-func (cls *ClientLinksService) CreateFinalizeClientLink(
+// GetFinalClientLink returns the final client link URI with the provided options.
+func (cls *ClientLinksService) GetFinalClientLink(
ctx context.Context,
clientLink string,
- options *ClientLinkFinalizeOptions,
+ options *ClientLinkAuthorizeOptions,
) (
clientLinkURI string,
) {
diff --git a/mollie/client_links_test.go b/mollie/client_links_test.go
index 624e01ae..66dd3f7f 100644
--- a/mollie/client_links_test.go
+++ b/mollie/client_links_test.go
@@ -10,13 +10,13 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestCreateClientLink(t *testing.T) {
+func TestClientLinkService_Create(t *testing.T) {
setEnv()
defer unsetEnv()
type args struct {
ctx context.Context
- cd *ClientDetails
+ cd CreateClientLink
}
cases := []struct {
@@ -31,7 +31,7 @@ func TestCreateClientLink(t *testing.T) {
"create new client link",
args{
context.Background(),
- &ClientDetails{},
+ CreateClientLink{},
},
false,
nil,
@@ -50,7 +50,7 @@ func TestCreateClientLink(t *testing.T) {
"create client link, an error is returned from the server",
args{
context.Background(),
- &ClientDetails{},
+ CreateClientLink{},
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -61,7 +61,7 @@ func TestCreateClientLink(t *testing.T) {
"create client link, an error occurs when parsing json",
args{
context.Background(),
- &ClientDetails{},
+ CreateClientLink{},
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -72,7 +72,7 @@ func TestCreateClientLink(t *testing.T) {
"create client link, invalid url when building request",
args{
context.Background(),
- &ClientDetails{},
+ CreateClientLink{},
},
true,
errBadBaseURL,
@@ -91,7 +91,7 @@ func TestCreateClientLink(t *testing.T) {
)
c.pre()
- res, cb, err := tClient.ClientLinks.CreateClientLink(c.args.ctx, c.args.cd)
+ res, cb, err := tClient.ClientLinks.Create(c.args.ctx, c.args.cd)
if c.wantErr {
assert.Error(t, err)
assert.EqualError(t, err, c.err.Error())
@@ -105,11 +105,14 @@ func TestCreateClientLink(t *testing.T) {
}
}
-func TestCreateFinalizeClientLink(t *testing.T) {
+func TestClientLinkService_GetFinalClientLink(t *testing.T) {
+ setEnv()
+ defer unsetEnv()
+
type args struct {
ctx context.Context
clientLink string
- options *ClientLinkFinalizeOptions
+ options *ClientLinkAuthorizeOptions
}
tests := []struct {
name string
@@ -121,43 +124,45 @@ func TestCreateFinalizeClientLink(t *testing.T) {
args{
context.Background(),
"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH",
- &ClientLinkFinalizeOptions{
+ &ClientLinkAuthorizeOptions{
ClientID: "app_j9Pakf56Ajta6Y65AkdTtAv",
- State: "decafbad",
- Scope: "onboarding.read+organization.read+payments.write+payments.read+profiles.write",
+ State: "unique_string_to_compare",
+ Scope: []PermissionGrant{OnboardingRead, OnboardingWrite},
},
},
- "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?clientID=app_j9Pakf56Ajta6Y65AkdTtAv&scope=onboarding.read%2Borganization.read%2Bpayments.write%2Bpayments.read%2Bprofiles.write&state=decafbad",
+ "https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?clientId=app_j9Pakf56Ajta6Y65AkdTtAv&scope=onboarding.read%2Bonbording.write&state=unique_string_to_compare",
},
{
"constructs client link finalize with complex values",
args{
context.Background(),
"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH",
- &ClientLinkFinalizeOptions{
+ &ClientLinkAuthorizeOptions{
ClientID: "",
State: "\ns\\s\\s\\s\n",
- Scope: "",
+ Scope: []PermissionGrant{},
},
},
"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?state=%0As%5Cs%5Cs%5Cs%0A",
},
{
- "constructs client link finalize with complex values",
+ "constructs client link finalize with no query params",
args{
context.Background(),
"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH",
- &ClientLinkFinalizeOptions{},
+ &ClientLinkAuthorizeOptions{},
},
"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?",
},
}
+
+ setup()
+ defer teardown()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- gotClientLinkURI := tClient.ClientLinks.CreateFinalizeClientLink(tt.args.ctx, tt.args.clientLink, tt.args.options)
- if gotClientLinkURI != tt.wantClientLinkURI {
- t.Errorf("ClientLinksService.CreateFinalizeClientLink() = %v, want %v", gotClientLinkURI, tt.wantClientLinkURI)
- }
+ gotClientLinkURI := tClient.ClientLinks.GetFinalClientLink(tt.args.ctx, tt.args.clientLink, tt.args.options)
+
+ assert.Equal(t, tt.wantClientLinkURI, gotClientLinkURI)
})
}
}
diff --git a/mollie/permissions.go b/mollie/permissions.go
index 8822d7cb..9e44e308 100644
--- a/mollie/permissions.go
+++ b/mollie/permissions.go
@@ -30,7 +30,7 @@ const (
ShipmentsWrite PermissionGrant = "shipments.write"
OrganizationsRead PermissionGrant = "organizations.read"
OrganizationsWrite PermissionGrant = "organizations.write"
- OnboardingRead PermissionGrant = "onbording.read"
+ OnboardingRead PermissionGrant = "onboarding.read"
OnboardingWrite PermissionGrant = "onbording.write"
)
From ff042f4f4d0909fb7806c94d526b59d38b24cdcb Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Wed, 6 Mar 2024 20:44:29 +0100
Subject: [PATCH 07/23] check customers resource against api reference (#334)
---
docs/README.md | 68 +++++++++++++++++++++++++++++-----------
mollie/customers.go | 30 +++++++++++++-----
mollie/customers_test.go | 20 ++++++------
mollie/payments.go | 2 +-
4 files changed, 83 insertions(+), 37 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 0418b941..f9cdcfcb 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -106,6 +106,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(cv \*ContextValues\) UnmarshalJSON\(data \[\]byte\) error](<#ContextValues.UnmarshalJSON>)
- [type CreateCapture](<#CreateCapture>)
- [type CreateClientLink](<#CreateClientLink>)
+- [type CreateCustomer](<#CreateCustomer>)
- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
- [type CreatePayment](<#CreatePayment>)
- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
@@ -117,13 +118,13 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type CustomersList](<#CustomersList>)
- [type CustomersListOptions](<#CustomersListOptions>)
- [type CustomersService](<#CustomersService>)
- - [func \(cs \*CustomersService\) Create\(ctx context.Context, c Customer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Create>)
+ - [func \(cs \*CustomersService\) Create\(ctx context.Context, c CreateCustomer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Create>)
- [func \(cs \*CustomersService\) CreatePayment\(ctx context.Context, id string, p CreatePayment\) \(res \*Response, pp \*Payment, err error\)](<#CustomersService.CreatePayment>)
- [func \(cs \*CustomersService\) Delete\(ctx context.Context, id string\) \(res \*Response, err error\)](<#CustomersService.Delete>)
- [func \(cs \*CustomersService\) Get\(ctx context.Context, id string\) \(res \*Response, c \*Customer, err error\)](<#CustomersService.Get>)
- [func \(cs \*CustomersService\) GetPayments\(ctx context.Context, id string, options \*CustomersListOptions\) \(res \*Response, pl \*PaymentList, err error\)](<#CustomersService.GetPayments>)
- [func \(cs \*CustomersService\) List\(ctx context.Context, options \*CustomersListOptions\) \(res \*Response, cl \*CustomersList, err error\)](<#CustomersService.List>)
- - [func \(cs \*CustomersService\) Update\(ctx context.Context, id string, c Customer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Update>)
+ - [func \(cs \*CustomersService\) Update\(ctx context.Context, id string, c UpdateCustomer\) \(res \*Response, cc \*Customer, err error\)](<#CustomersService.Update>)
- [type EligibilityReasons](<#EligibilityReasons>)
- [type EmbedValue](<#EmbedValue>)
- [type EntityType](<#EntityType>)
@@ -355,6 +356,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type TransferDestination](<#TransferDestination>)
- [type TransferFrequency](<#TransferFrequency>)
- [type URL](<#URL>)
+- [type UpdateCustomer](<#UpdateCustomer>)
- [type UpdatePayment](<#UpdatePayment>)
- [type UsedGiftCard](<#UsedGiftCard>)
- [type UserAgentToken](<#UserAgentToken>)
@@ -1826,6 +1828,20 @@ type CreateClientLink struct {
}
```
+
+## type [CreateCustomer]()
+
+CreateCustomer contains the parameters to create a customer.
+
+```go
+type CreateCustomer struct {
+ Name string `json:"name,omitempty"`
+ Email string `json:"email,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+}
+```
+
## type [CreateMollieConnectPaymentFields]()
@@ -1945,7 +1961,7 @@ type CreateShipmentRequest struct {
```
-## type [Customer]()
+## type [Customer]()
Customer represents buyers.
@@ -1957,30 +1973,30 @@ type Customer struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Locale Locale `json:"locale,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
Links CustomerLinks `json:"_links,omitempty"`
}
```
-## type [CustomerLinks]()
+## type [CustomerLinks]()
CustomerLinks contains the HAL resources for a customer response.
```go
type CustomerLinks struct {
Self *URL `json:"self,omitempty"`
+ Dashboard *URL `json:"dashboard,omitempty"`
Mandates *URL `json:"mandates,omitempty"`
Subscriptions *URL `json:"subscriptions,omitempty"`
Payments *URL `json:"payments,omitempty"`
Documentation *URL `json:"documentation,omitempty"`
- Dashboard *URL `json:"dashboard,omitempty"`
}
```
-## type [CustomersList]()
+## type [CustomersList]()
CustomersList contains a embedded list of customers wrapped in a standard Mollie paginated response.
@@ -1988,14 +2004,14 @@ CustomersList contains a embedded list of customers wrapped in a standard Mollie
type CustomersList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Customers []Customer `json:"customers,omitempty"`
+ Customers []*Customer `json:"customers,omitempty"`
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"links,omitempty"`
}
```
-## type [CustomersListOptions]()
+## type [CustomersListOptions]()
CustomersListOptions contains valid query parameters for the list customers endpoint.
@@ -2010,7 +2026,7 @@ type CustomersListOptions struct {
```
-## type [CustomersService]()
+## type [CustomersService]()
CustomersService operates over the customer resource.
@@ -2019,10 +2035,10 @@ type CustomersService service
```
-### func \(\*CustomersService\) [Create]()
+### func \(\*CustomersService\) [Create]()
```go
-func (cs *CustomersService) Create(ctx context.Context, c Customer) (res *Response, cc *Customer, err error)
+func (cs *CustomersService) Create(ctx context.Context, c CreateCustomer) (res *Response, cc *Customer, err error)
```
Create creates a simple minimal representation of a customer in the Mollie API to use for the Mollie Checkout and Recurring features.
@@ -2030,7 +2046,7 @@ Create creates a simple minimal representation of a customer in the Mollie API t
See: https://docs.mollie.com/reference/v2/customers-api/create-customer
-### func \(\*CustomersService\) [CreatePayment]()
+### func \(\*CustomersService\) [CreatePayment]()
```go
func (cs *CustomersService) CreatePayment(ctx context.Context, id string, p CreatePayment) (res *Response, pp *Payment, err error)
@@ -2041,7 +2057,7 @@ CreatePayment creates a payment for the customer.
See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
-### func \(\*CustomersService\) [Delete]()
+### func \(\*CustomersService\) [Delete]()
```go
func (cs *CustomersService) Delete(ctx context.Context, id string) (res *Response, err error)
@@ -2054,7 +2070,7 @@ All mandates and subscriptions created for this customer will be canceled as wel
See: https://docs.mollie.com/reference/v2/customers-api/delete-customer
-### func \(\*CustomersService\) [Get]()
+### func \(\*CustomersService\) [Get]()
```go
func (cs *CustomersService) Get(ctx context.Context, id string) (res *Response, c *Customer, err error)
@@ -2065,7 +2081,7 @@ Get finds a customer by its ID.
See: https://docs.mollie.com/reference/v2/customers-api/get-customer
-### func \(\*CustomersService\) [GetPayments]()
+### func \(\*CustomersService\) [GetPayments]()
```go
func (cs *CustomersService) GetPayments(ctx context.Context, id string, options *CustomersListOptions) (res *Response, pl *PaymentList, err error)
@@ -2076,7 +2092,7 @@ GetPayments retrieves all payments linked to the customer.
See: https://docs.mollie.com/reference/v2/customers-api/list-customer-payments
-### func \(\*CustomersService\) [List]()
+### func \(\*CustomersService\) [List]()
```go
func (cs *CustomersService) List(ctx context.Context, options *CustomersListOptions) (res *Response, cl *CustomersList, err error)
@@ -2087,10 +2103,10 @@ List retrieves all customers created.
See: https://docs.mollie.com/reference/v2/customers-api/list-customers
-### func \(\*CustomersService\) [Update]()
+### func \(\*CustomersService\) [Update]()
```go
-func (cs *CustomersService) Update(ctx context.Context, id string, c Customer) (res *Response, cc *Customer, err error)
+func (cs *CustomersService) Update(ctx context.Context, id string, c UpdateCustomer) (res *Response, cc *Customer, err error)
```
Update an existing customer.
@@ -5546,6 +5562,20 @@ type URL struct {
}
```
+
+## type [UpdateCustomer]()
+
+UpdateCustomer contains the parameters to update a customer.
+
+```go
+type UpdateCustomer struct {
+ Name string `json:"name,omitempty"`
+ Email string `json:"email,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+}
+```
+
## type [UpdatePayment]()
diff --git a/mollie/customers.go b/mollie/customers.go
index 486aa377..a3e67397 100644
--- a/mollie/customers.go
+++ b/mollie/customers.go
@@ -7,17 +7,30 @@ import (
"time"
)
-// CustomersService operates over the customer resource.
-type CustomersService service
+// CreateCustomer contains the parameters to create a customer.
+type CreateCustomer struct {
+ Name string `json:"name,omitempty"`
+ Email string `json:"email,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+}
+
+// UpdateCustomer contains the parameters to update a customer.
+type UpdateCustomer struct {
+ Name string `json:"name,omitempty"`
+ Email string `json:"email,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+}
// CustomerLinks contains the HAL resources for a customer response.
type CustomerLinks struct {
Self *URL `json:"self,omitempty"`
+ Dashboard *URL `json:"dashboard,omitempty"`
Mandates *URL `json:"mandates,omitempty"`
Subscriptions *URL `json:"subscriptions,omitempty"`
Payments *URL `json:"payments,omitempty"`
Documentation *URL `json:"documentation,omitempty"`
- Dashboard *URL `json:"dashboard,omitempty"`
}
// Customer represents buyers.
@@ -28,7 +41,7 @@ type Customer struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Locale Locale `json:"locale,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
Links CustomerLinks `json:"_links,omitempty"`
}
@@ -47,11 +60,14 @@ type CustomersListOptions struct {
type CustomersList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Customers []Customer `json:"customers,omitempty"`
+ Customers []*Customer `json:"customers,omitempty"`
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"links,omitempty"`
}
+// CustomersService operates over the customer resource.
+type CustomersService service
+
// Get finds a customer by its ID.
//
// See: https://docs.mollie.com/reference/v2/customers-api/get-customer
@@ -74,7 +90,7 @@ func (cs *CustomersService) Get(ctx context.Context, id string) (res *Response,
// to use for the Mollie Checkout and Recurring features.
//
// See: https://docs.mollie.com/reference/v2/customers-api/create-customer
-func (cs *CustomersService) Create(ctx context.Context, c Customer) (res *Response, cc *Customer, err error) {
+func (cs *CustomersService) Create(ctx context.Context, c CreateCustomer) (res *Response, cc *Customer, err error) {
res, err = cs.client.post(ctx, "v2/customers", c, nil)
if err != nil {
return
@@ -90,7 +106,7 @@ func (cs *CustomersService) Create(ctx context.Context, c Customer) (res *Respon
// Update an existing customer.
//
// See: https://docs.mollie.com/reference/v2/customers-api/update-customer
-func (cs *CustomersService) Update(ctx context.Context, id string, c Customer) (
+func (cs *CustomersService) Update(ctx context.Context, id string, c UpdateCustomer) (
res *Response,
cc *Customer,
err error,
diff --git a/mollie/customers_test.go b/mollie/customers_test.go
index 9863ab29..86e6b442 100644
--- a/mollie/customers_test.go
+++ b/mollie/customers_test.go
@@ -106,7 +106,7 @@ func TestCustomersService_Create(t *testing.T) {
defer unsetEnv()
type args struct {
ctx context.Context
- customer Customer
+ customer CreateCustomer
}
cases := []struct {
@@ -123,7 +123,7 @@ func TestCustomersService_Create(t *testing.T) {
http.StatusAccepted,
args{
context.Background(),
- Customer{Locale: German},
+ CreateCustomer{Locale: German},
},
false,
nil,
@@ -143,7 +143,7 @@ func TestCustomersService_Create(t *testing.T) {
http.StatusInternalServerError,
args{
context.Background(),
- Customer{},
+ CreateCustomer{},
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -155,7 +155,7 @@ func TestCustomersService_Create(t *testing.T) {
http.StatusInternalServerError,
args{
context.Background(),
- Customer{},
+ CreateCustomer{},
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -167,7 +167,7 @@ func TestCustomersService_Create(t *testing.T) {
http.StatusInternalServerError,
args{
context.Background(),
- Customer{},
+ CreateCustomer{},
},
true,
errBadBaseURL,
@@ -203,7 +203,7 @@ func TestCustomersService_Update(t *testing.T) {
type args struct {
ctx context.Context
customerID string
- customer Customer
+ customer UpdateCustomer
}
cases := []struct {
@@ -221,7 +221,7 @@ func TestCustomersService_Update(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Customer{Locale: French},
+ UpdateCustomer{Locale: French},
},
false,
nil,
@@ -242,7 +242,7 @@ func TestCustomersService_Update(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Customer{},
+ UpdateCustomer{},
},
true,
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
@@ -255,7 +255,7 @@ func TestCustomersService_Update(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Customer{},
+ UpdateCustomer{},
},
true,
fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
@@ -268,7 +268,7 @@ func TestCustomersService_Update(t *testing.T) {
args{
context.Background(),
"cst_kEn1PlbGa",
- Customer{},
+ UpdateCustomer{},
},
true,
errBadBaseURL,
diff --git a/mollie/payments.go b/mollie/payments.go
index 67af858d..e18d5e73 100644
--- a/mollie/payments.go
+++ b/mollie/payments.go
@@ -347,7 +347,7 @@ func (ps *PaymentsService) Update(ctx context.Context, id string, up UpdatePayme
type PaymentList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Payments []Payment
+ Payments []*Payment
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
From 448596af5d57a5676913b947882d26d0f2c1b614 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Fri, 8 Mar 2024 15:42:24 +0100
Subject: [PATCH 08/23] check invoices resource against api reference (#335)
---
docs/README.md | 12 ++++++------
mollie/invoices.go | 10 +++++-----
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index f9cdcfcb..f20e14be 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -2391,7 +2391,6 @@ type Invoice struct {
ID string `json:"id,omitempty"`
Reference string `json:"reference,omitempty"`
VatNumber string `json:"vatNumber,omitempty"`
- Status InvoiceStatus `json:"status,omitempty"`
IssuedAt string `json:"issuedAt,omitempty"`
PaidAt string `json:"paidAt,omitempty"`
DueAt string `json:"dueAt,omitempty"`
@@ -2399,6 +2398,7 @@ type Invoice struct {
VatAmount *Amount `json:"vatAmount,omitempty"`
GrossAmount *Amount `json:"grossAmount,omitempty"`
Lines []*LineItem `json:"lines,omitempty"`
+ Status InvoiceStatus `json:"status,omitempty"`
Links InvoiceLinks `json:"_links,omitempty"`
}
```
@@ -2444,7 +2444,7 @@ InvoicesList describes how a list of invoices will be retrieved by Mollie.
type InvoicesList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Invoices []Invoice `json:"invoices"`
+ Invoices []*Invoice `json:"invoices"`
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
@@ -2457,10 +2457,10 @@ InvoicesListOptions describes list invoices endpoint valid query string paramete
```go
type InvoicesListOptions struct {
+ Limit int64 `url:"limit,omitempty"`
Reference string `url:"reference,omitempty"`
Year string `url:"year,omitempty"`
From string `url:"from,omitempty"`
- Limit int64 `url:"limit,omitempty"`
}
```
@@ -2498,10 +2498,10 @@ LineItem product details.
```go
type LineItem struct {
- Period string `json:"period,omitempty"`
- Description string `json:"description,omitempty"`
Count int64 `json:"count,omitempty"`
VatPercentage float64 `json:"vatPercentage,omitempty"`
+ Period string `json:"period,omitempty"`
+ Description string `json:"description,omitempty"`
Amount *Amount `json:"amount,omitempty"`
}
```
@@ -3930,7 +3930,7 @@ PaymentList describes how a list of payments will be retrieved by Mollie.
type PaymentList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Payments []Payment
+ Payments []*Payment
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
diff --git a/mollie/invoices.go b/mollie/invoices.go
index 4bd18f1f..c833d4a1 100644
--- a/mollie/invoices.go
+++ b/mollie/invoices.go
@@ -22,7 +22,6 @@ type Invoice struct {
ID string `json:"id,omitempty"`
Reference string `json:"reference,omitempty"`
VatNumber string `json:"vatNumber,omitempty"`
- Status InvoiceStatus `json:"status,omitempty"`
IssuedAt string `json:"issuedAt,omitempty"`
PaidAt string `json:"paidAt,omitempty"`
DueAt string `json:"dueAt,omitempty"`
@@ -30,15 +29,16 @@ type Invoice struct {
VatAmount *Amount `json:"vatAmount,omitempty"`
GrossAmount *Amount `json:"grossAmount,omitempty"`
Lines []*LineItem `json:"lines,omitempty"`
+ Status InvoiceStatus `json:"status,omitempty"`
Links InvoiceLinks `json:"_links,omitempty"`
}
// LineItem product details.
type LineItem struct {
- Period string `json:"period,omitempty"`
- Description string `json:"description,omitempty"`
Count int64 `json:"count,omitempty"`
VatPercentage float64 `json:"vatPercentage,omitempty"`
+ Period string `json:"period,omitempty"`
+ Description string `json:"description,omitempty"`
Amount *Amount `json:"amount,omitempty"`
}
@@ -52,17 +52,17 @@ type InvoiceLinks struct {
// InvoicesListOptions describes list invoices endpoint valid query string parameters.
type InvoicesListOptions struct {
+ Limit int64 `url:"limit,omitempty"`
Reference string `url:"reference,omitempty"`
Year string `url:"year,omitempty"`
From string `url:"from,omitempty"`
- Limit int64 `url:"limit,omitempty"`
}
// InvoicesList describes how a list of invoices will be retrieved by Mollie.
type InvoicesList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Invoices []Invoice `json:"invoices"`
+ Invoices []*Invoice `json:"invoices"`
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
From 1e55ab8fdc078f1bea545f41103f3f8f4bdc0a9a Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Fri, 8 Mar 2024 16:10:45 +0100
Subject: [PATCH 09/23] check mandates resource against api reference (#336)
---
docs/README.md | 72 +++++++++++++++++++++++++++++------------
mollie/mandates.go | 36 +++++++++++++++++----
mollie/mandates_test.go | 10 +++---
3 files changed, 86 insertions(+), 32 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index f20e14be..e7980607 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -107,6 +107,8 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type CreateCapture](<#CreateCapture>)
- [type CreateClientLink](<#CreateClientLink>)
- [type CreateCustomer](<#CreateCustomer>)
+- [type CreateMandate](<#CreateMandate>)
+- [type CreateMandateAccessTokenFields](<#CreateMandateAccessTokenFields>)
- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
- [type CreatePayment](<#CreatePayment>)
- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
@@ -158,7 +160,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type MandatesList](<#MandatesList>)
- [type MandatesListOptions](<#MandatesListOptions>)
- [type MandatesService](<#MandatesService>)
- - [func \(ms \*MandatesService\) Create\(ctx context.Context, customer string, mandate Mandate\) \(res \*Response, mr \*Mandate, err error\)](<#MandatesService.Create>)
+ - [func \(ms \*MandatesService\) Create\(ctx context.Context, customer string, mandate CreateMandate\) \(res \*Response, mr \*Mandate, err error\)](<#MandatesService.Create>)
- [func \(ms \*MandatesService\) Get\(ctx context.Context, customer, mandate string\) \(res \*Response, mr \*Mandate, err error\)](<#MandatesService.Get>)
- [func \(ms \*MandatesService\) List\(ctx context.Context, customer string, options \*MandatesListOptions\) \(res \*Response, ml \*MandatesList, err error\)](<#MandatesService.List>)
- [func \(ms \*MandatesService\) Revoke\(ctx context.Context, customer, mandate string\) \(res \*Response, err error\)](<#MandatesService.Revoke>)
@@ -1152,7 +1154,7 @@ List retrieves all captures for a certain payment.
See: https://docs.mollie.com/reference/v2/captures-api/list-captures
-## type [CardLabel]()
+## type [CardLabel]()
CardLabel Note that not all labels can be processed through Mollie.
@@ -1842,6 +1844,36 @@ type CreateCustomer struct {
}
```
+
+## type [CreateMandate]()
+
+CreateMandate contains the parameters to create a mandate.
+
+```go
+type CreateMandate struct {
+ ConsumerName string `json:"consumerName,omitempty"`
+ ConsumerAccount string `json:"consumerAccount,omitempty"`
+ ConsumerBIC string `json:"consumerBic,omitempty"`
+ ConsumerEmail string `json:"consumerEmail,omitempty"`
+ MandateReference string `json:"mandateReference,omitempty"`
+ PaypalBillingAgreementID string `json:"paypalBillingAgreementId,omitempty"`
+ SignatureDate *ShortDate `json:"signatureDate,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ CreateMandateAccessTokenFields
+}
+```
+
+
+## type [CreateMandateAccessTokenFields]()
+
+CreateMandateAccessTokenFields contains the parameters to create a mandate when using an access token.
+
+```go
+type CreateMandateAccessTokenFields struct {
+ Testmode bool `json:"testmode,omitempty"`
+}
+```
+
## type [CreateMollieConnectPaymentFields]()
@@ -2590,7 +2622,7 @@ const (
```
-## type [Mandate]()
+## type [Mandate]()
Mandate allow you to charge a customer’s credit card or bank account recurrently.
@@ -2598,22 +2630,22 @@ Mandate allow you to charge a customer’s credit card or bank account recurrent
type Mandate struct {
ID string `json:"id,omitempty"`
Resource string `json:"resource,omitempty"`
- Method PaymentMethod `json:"method,omitempty"`
ConsumerName string `json:"consumerName,omitempty"`
ConsumerAccount string `json:"consumerAccount,omitempty"`
ConsumerBic string `json:"consumerBic,omitempty"`
- SignatureDate *ShortDate `json:"signatureDate,omitempty"`
MandateReference string `json:"mandateReference,omitempty"`
+ SignatureDate *ShortDate `json:"signatureDate,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
Mode Mode `json:"mode,omitempty"`
Status MandateStatus `json:"status,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
Details MandateDetails `json:"details,omitempty"`
Links MandateLinks `json:"_links,omitempty"`
}
```
-## type [MandateDetails]()
+## type [MandateDetails]()
MandateDetails are possible values inside the mandate.details field.
@@ -2624,14 +2656,14 @@ type MandateDetails struct {
ConsumerBic string `json:"consumerBic,omitempty"`
CardHolder string `json:"cardHolder,omitempty"`
CardNumber string `json:"cardNumber,omitempty"`
- CardLabel CardLabel `json:"cardLabel,omitempty"`
CardFingerprint string `json:"cardFingerprint,omitempty"`
CardExpiryDate *ShortDate `json:"cardExpiryDate,omitempty"`
+ CardLabel CardLabel `json:"cardLabel,omitempty"`
}
```
-## type [MandateLinks]()
+## type [MandateLinks]()
MandateLinks response objects.
@@ -2644,7 +2676,7 @@ type MandateLinks struct {
```
-## type [MandateStatus]()
+## type [MandateStatus]()
MandateStatus for the Mandate object.
@@ -2663,7 +2695,7 @@ const (
```
-## type [MandatesList]()
+## type [MandatesList]()
MandatesList describes how a list of mandates will be retrieved by Mollie.
@@ -2671,14 +2703,14 @@ MandatesList describes how a list of mandates will be retrieved by Mollie.
type MandatesList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Mandates []Mandate
+ Mandates []*Mandate
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
```
-## type [MandatesListOptions]()
+## type [MandatesListOptions]()
MandatesListOptions contains valid query parameters to filter the List mandates actions.
@@ -2686,13 +2718,13 @@ From is a mandate id to offset from \(inclusive\) Limit is the max number of man
```go
type MandatesListOptions struct {
- From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
+ From string `url:"from,omitempty"`
}
```
-## type [MandatesService]()
+## type [MandatesService]()
MandatesService operates over customer mandates endpoints.
@@ -2701,10 +2733,10 @@ type MandatesService service
```
-### func \(\*MandatesService\) [Create]()
+### func \(\*MandatesService\) [Create]()
```go
-func (ms *MandatesService) Create(ctx context.Context, customer string, mandate Mandate) (res *Response, mr *Mandate, err error)
+func (ms *MandatesService) Create(ctx context.Context, customer string, mandate CreateMandate) (res *Response, mr *Mandate, err error)
```
Create a mandate for a specific customer.
@@ -2714,7 +2746,7 @@ Mandates allow you to charge a customer’s credit card or bank account recurren
See: https://docs.mollie.com/reference/v2/mandates-api/create-mandate
-### func \(\*MandatesService\) [Get]()
+### func \(\*MandatesService\) [Get]()
```go
func (ms *MandatesService) Get(ctx context.Context, customer, mandate string) (res *Response, mr *Mandate, err error)
@@ -2725,7 +2757,7 @@ Get retrieves a mandate by its ID and its customer’s ID. The mandate will eith
See: https://docs.mollie.com/reference/v2/mandates-api/get-mandate
-### func \(\*MandatesService\) [List]()
+### func \(\*MandatesService\) [List]()
```go
func (ms *MandatesService) List(ctx context.Context, customer string, options *MandatesListOptions) (res *Response, ml *MandatesList, err error)
@@ -2736,7 +2768,7 @@ List retrieves all mandates for the given customerId, ordered from newest to old
See: https://docs.mollie.com/reference/v2/mandates-api/list-mandates
-### func \(\*MandatesService\) [Revoke]()
+### func \(\*MandatesService\) [Revoke]()
```go
func (ms *MandatesService) Revoke(ctx context.Context, customer, mandate string) (res *Response, err error)
diff --git a/mollie/mandates.go b/mollie/mandates.go
index 4627ffab..b9e7624d 100644
--- a/mollie/mandates.go
+++ b/mollie/mandates.go
@@ -7,19 +7,37 @@ import (
"time"
)
+// CreateMandate contains the parameters to create a mandate.
+type CreateMandate struct {
+ ConsumerName string `json:"consumerName,omitempty"`
+ ConsumerAccount string `json:"consumerAccount,omitempty"`
+ ConsumerBIC string `json:"consumerBic,omitempty"`
+ ConsumerEmail string `json:"consumerEmail,omitempty"`
+ MandateReference string `json:"mandateReference,omitempty"`
+ PaypalBillingAgreementID string `json:"paypalBillingAgreementId,omitempty"`
+ SignatureDate *ShortDate `json:"signatureDate,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ CreateMandateAccessTokenFields
+}
+
+// CreateMandateAccessTokenFields contains the parameters to create a mandate when using an access token.
+type CreateMandateAccessTokenFields struct {
+ Testmode bool `json:"testmode,omitempty"`
+}
+
// Mandate allow you to charge a customer’s credit card or bank account recurrently.
type Mandate struct {
ID string `json:"id,omitempty"`
Resource string `json:"resource,omitempty"`
- Method PaymentMethod `json:"method,omitempty"`
ConsumerName string `json:"consumerName,omitempty"`
ConsumerAccount string `json:"consumerAccount,omitempty"`
ConsumerBic string `json:"consumerBic,omitempty"`
- SignatureDate *ShortDate `json:"signatureDate,omitempty"`
MandateReference string `json:"mandateReference,omitempty"`
+ SignatureDate *ShortDate `json:"signatureDate,omitempty"`
+ CreatedAt *time.Time `json:"createdAt,omitempty"`
Mode Mode `json:"mode,omitempty"`
Status MandateStatus `json:"status,omitempty"`
- CreatedAt *time.Time `json:"createdAt,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
Details MandateDetails `json:"details,omitempty"`
Links MandateLinks `json:"_links,omitempty"`
}
@@ -31,9 +49,9 @@ type MandateDetails struct {
ConsumerBic string `json:"consumerBic,omitempty"`
CardHolder string `json:"cardHolder,omitempty"`
CardNumber string `json:"cardNumber,omitempty"`
- CardLabel CardLabel `json:"cardLabel,omitempty"`
CardFingerprint string `json:"cardFingerprint,omitempty"`
CardExpiryDate *ShortDate `json:"cardExpiryDate,omitempty"`
+ CardLabel CardLabel `json:"cardLabel,omitempty"`
}
// MandateStatus for the Mandate object.
@@ -82,15 +100,15 @@ type MandateLinks struct {
// From is a mandate id to offset from (inclusive)
// Limit is the max number of mandates to retrieve.
type MandatesListOptions struct {
- From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
+ From string `url:"from,omitempty"`
}
// MandatesList describes how a list of mandates will be retrieved by Mollie.
type MandatesList struct {
Count int `json:"count,omitempty"`
Embedded struct {
- Mandates []Mandate
+ Mandates []*Mandate
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
@@ -100,13 +118,17 @@ type MandatesList struct {
// Mandates allow you to charge a customer’s credit card or bank account recurrently.
//
// See: https://docs.mollie.com/reference/v2/mandates-api/create-mandate
-func (ms *MandatesService) Create(ctx context.Context, customer string, mandate Mandate) (
+func (ms *MandatesService) Create(ctx context.Context, customer string, mandate CreateMandate) (
res *Response,
mr *Mandate,
err error,
) {
u := fmt.Sprintf("v2/customers/%s/mandates", customer)
+ if ms.client.HasAccessToken() && ms.client.config.testing {
+ mandate.Testmode = true
+ }
+
res, err = ms.client.post(ctx, u, mandate, nil)
if err != nil {
return
diff --git a/mollie/mandates_test.go b/mollie/mandates_test.go
index fe13c2bd..3a032103 100644
--- a/mollie/mandates_test.go
+++ b/mollie/mandates_test.go
@@ -120,7 +120,7 @@ func TestMandatesService_Create(t *testing.T) {
type args struct {
ctx context.Context
- mandate Mandate
+ mandate CreateMandate
customer string
}
@@ -136,7 +136,7 @@ func TestMandatesService_Create(t *testing.T) {
"create mandates works as expected.",
args{
context.Background(),
- Mandate{
+ CreateMandate{
Method: PayPal,
},
"cst_4qqhO89gsT",
@@ -158,7 +158,7 @@ func TestMandatesService_Create(t *testing.T) {
"create mandate, an error is returned from the server",
args{
context.Background(),
- Mandate{
+ CreateMandate{
Method: PayPal,
},
"cst_4qqhO89gsT",
@@ -172,7 +172,7 @@ func TestMandatesService_Create(t *testing.T) {
"create mandate, an error occurs when parsing json",
args{
context.Background(),
- Mandate{
+ CreateMandate{
Method: PayPal,
},
"cst_4qqhO89gsT",
@@ -186,7 +186,7 @@ func TestMandatesService_Create(t *testing.T) {
"create mandate, invalid url when building request",
args{
context.Background(),
- Mandate{
+ CreateMandate{
Method: PayPal,
},
"cst_4qqhO89gsT",
From be31f07c5bed090f53fce31953dd1534f7c28eed Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Fri, 8 Mar 2024 17:00:04 +0100
Subject: [PATCH 10/23] check mandates resources against api reference (#337)
From 33954069533d8dc5d8d46880091955b448e14622 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Fri, 8 Mar 2024 17:04:16 +0100
Subject: [PATCH 11/23] check wallets resources against api reference (#338)
---
docs/README.md | 50 +++++++++----------
mollie/mollie.go | 4 +-
mollie/{miscellaneous.go => wallets.go} | 8 +--
...{miscellaneous_test.go => wallets_test.go} | 2 +-
4 files changed, 32 insertions(+), 32 deletions(-)
rename mollie/{miscellaneous.go => wallets.go} (83%)
rename mollie/{miscellaneous_test.go => wallets_test.go} (95%)
diff --git a/docs/README.md b/docs/README.md
index e7980607..95887273 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -165,8 +165,6 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ms \*MandatesService\) List\(ctx context.Context, customer string, options \*MandatesListOptions\) \(res \*Response, ml \*MandatesList, err error\)](<#MandatesService.List>)
- [func \(ms \*MandatesService\) Revoke\(ctx context.Context, customer, mandate string\) \(res \*Response, err error\)](<#MandatesService.Revoke>)
- [type MethodsLinks](<#MethodsLinks>)
-- [type MiscellaneousService](<#MiscellaneousService>)
- - [func \(ms \*MiscellaneousService\) ApplePaymentSession\(ctx context.Context, asr \*ApplePaymentSessionRequest\) \(res \*Response, aps \*ApplePaymentSession, err error\)](<#MiscellaneousService.ApplePaymentSession>)
- [type Mode](<#Mode>)
- [type MollieConnectPaymentFields](<#MollieConnectPaymentFields>)
- [type Onboarding](<#Onboarding>)
@@ -362,6 +360,8 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type UpdatePayment](<#UpdatePayment>)
- [type UsedGiftCard](<#UsedGiftCard>)
- [type UserAgentToken](<#UserAgentToken>)
+- [type WalletsService](<#WalletsService>)
+ - [func \(ms \*WalletsService\) ApplePaymentSession\(ctx context.Context, asr \*ApplePaymentSessionRequest\) \(res \*Response, aps \*ApplePaymentSession, err error\)](<#WalletsService.ApplePaymentSession>)
## Constants
@@ -437,7 +437,7 @@ type Amount struct {
```
-## type [ApplePaymentSession]()
+## type [ApplePaymentSession]()
ApplePaymentSession contains information about an Apple pay session.
@@ -455,7 +455,7 @@ type ApplePaymentSession struct {
```
-## type [ApplePaymentSessionRequest]()
+## type [ApplePaymentSessionRequest]()
ApplePaymentSessionRequest contains the body parameters for requesting a valid PaymentSession from Apple.
@@ -1384,7 +1384,7 @@ type Client struct {
Captures *CapturesService
Subscriptions *SubscriptionsService
Customers *CustomersService
- Miscellaneous *MiscellaneousService
+ Wallets *WalletsService
Mandates *MandatesService
Permissions *PermissionsService
Onboarding *OnboardingService
@@ -2792,26 +2792,6 @@ type MethodsLinks struct {
}
```
-
-## type [MiscellaneousService]()
-
-MiscellaneousService operates over the resources described in Mollie's miscellaneous API endpoints section.
-
-```go
-type MiscellaneousService service
-```
-
-
-### func \(\*MiscellaneousService\) [ApplePaymentSession]()
-
-```go
-func (ms *MiscellaneousService) ApplePaymentSession(ctx context.Context, asr *ApplePaymentSessionRequest) (res *Response, aps *ApplePaymentSession, err error)
-```
-
-ApplePaymentSession returns an Apple Payment Session object valid for one transaction.
-
-See: https://docs.mollie.com/reference/v2/wallets-api/request-apple-pay-payment-session
-
## type [Mode]()
@@ -5659,4 +5639,24 @@ type UserAgentToken struct {
}
```
+
+## type [WalletsService]()
+
+WalletsService operates over the resources described in Mollie's wallets API endpoints section.
+
+```go
+type WalletsService service
+```
+
+
+### func \(\*WalletsService\) [ApplePaymentSession]()
+
+```go
+func (ms *WalletsService) ApplePaymentSession(ctx context.Context, asr *ApplePaymentSessionRequest) (res *Response, aps *ApplePaymentSession, err error)
+```
+
+ApplePaymentSession returns an Apple Payment Session object valid for one transaction.
+
+See: https://docs.mollie.com/reference/v2/wallets-api/request-apple-pay-payment-session
+
Generated by [gomarkdoc]()
diff --git a/mollie/mollie.go b/mollie/mollie.go
index 1a1d01c5..f3b2f446 100644
--- a/mollie/mollie.go
+++ b/mollie/mollie.go
@@ -63,7 +63,7 @@ type Client struct {
Captures *CapturesService
Subscriptions *SubscriptionsService
Customers *CustomersService
- Miscellaneous *MiscellaneousService
+ Wallets *WalletsService
Mandates *MandatesService
Permissions *PermissionsService
Onboarding *OnboardingService
@@ -299,7 +299,7 @@ func NewClient(baseClient *http.Client, conf *Config) (mollie *Client, err error
mollie.Settlements = (*SettlementsService)(&mollie.common)
mollie.Subscriptions = (*SubscriptionsService)(&mollie.common)
mollie.Customers = (*CustomersService)(&mollie.common)
- mollie.Miscellaneous = (*MiscellaneousService)(&mollie.common)
+ mollie.Wallets = (*WalletsService)(&mollie.common)
mollie.Mandates = (*MandatesService)(&mollie.common)
mollie.Permissions = (*PermissionsService)(&mollie.common)
mollie.Onboarding = (*OnboardingService)(&mollie.common)
diff --git a/mollie/miscellaneous.go b/mollie/wallets.go
similarity index 83%
rename from mollie/miscellaneous.go
rename to mollie/wallets.go
index f1921ba6..bc429edd 100644
--- a/mollie/miscellaneous.go
+++ b/mollie/wallets.go
@@ -5,9 +5,9 @@ import (
"encoding/json"
)
-// MiscellaneousService operates over the resources described
-// in Mollie's miscellaneous API endpoints section.
-type MiscellaneousService service
+// WalletsService operates over the resources described
+// in Mollie's wallets API endpoints section.
+type WalletsService service
// ApplePaymentSession contains information about an Apple pay session.
type ApplePaymentSession struct {
@@ -31,7 +31,7 @@ type ApplePaymentSessionRequest struct {
// ApplePaymentSession returns an Apple Payment Session object valid for one transaction.
//
// See: https://docs.mollie.com/reference/v2/wallets-api/request-apple-pay-payment-session
-func (ms *MiscellaneousService) ApplePaymentSession(ctx context.Context, asr *ApplePaymentSessionRequest) (
+func (ms *WalletsService) ApplePaymentSession(ctx context.Context, asr *ApplePaymentSessionRequest) (
res *Response,
aps *ApplePaymentSession,
err error,
diff --git a/mollie/miscellaneous_test.go b/mollie/wallets_test.go
similarity index 95%
rename from mollie/miscellaneous_test.go
rename to mollie/wallets_test.go
index 0bab18d3..09be8bc7 100644
--- a/mollie/miscellaneous_test.go
+++ b/mollie/wallets_test.go
@@ -91,7 +91,7 @@ func TestMiscellaneousService_ApplePaymentSession(t *testing.T) {
c.pre()
tMux.HandleFunc("/v2/wallets/applepay/sessions", c.handler)
- res, m, err := tClient.Miscellaneous.ApplePaymentSession(c.args.ctx, c.args.appleSess)
+ res, m, err := tClient.Wallets.ApplePaymentSession(c.args.ctx, c.args.appleSess)
if c.wantErr {
assert.NotNil(t, err)
assert.EqualError(t, err, c.err.Error())
From 9a25a2ad592f73699d375347939bf7961e1e6a55 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Fri, 8 Mar 2024 17:21:01 +0100
Subject: [PATCH 12/23] check onboarding resources against api reference (#339)
---
docs/README.md | 6 +++---
mollie/onboarding.go | 12 ++++++------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 95887273..4a9d6250 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -2828,12 +2828,12 @@ Onboarding data for an organization.
```go
type Onboarding struct {
+ CanReceivePayments bool `json:"canReceivePayments,omitempty"`
+ CanReceiveSettlements bool `json:"canReceiveSettlements,omitempty"`
Resource string `json:"reference,omitempty"`
Name string `json:"name,omitempty"`
SignedUpAt *time.Time `json:"signedUpAt,omitempty"`
Status OnboardingStatus `json:"status,omitempty"`
- CanReceivePayments bool `json:"canReceivePayments,omitempty"`
- CanReveiceSettlements bool `json:"canReceiveSettlements,omitempty"`
Links OnboardingLinks `json:"_links,omitempty"`
}
```
@@ -2858,10 +2858,10 @@ OnboardingDataOrganization contains data of the organization you want to provide
```go
type OnboardingDataOrganization struct {
Name string `json:"name,omitempty"`
- Address *Address `json:"address,omitempty"`
RegistrationNumber string `json:"registrationNumber,omitempty"`
VatNumber string `json:"vatNumber,omitempty"`
VatRegulation string `json:"vatRegulation,omitempty"`
+ Address *Address `json:"address,omitempty"`
}
```
diff --git a/mollie/onboarding.go b/mollie/onboarding.go
index 45621d94..e8386974 100644
--- a/mollie/onboarding.go
+++ b/mollie/onboarding.go
@@ -6,7 +6,7 @@ import (
"time"
)
-const onboardingTarget = "v2/onboarding/me"
+const onboardingURLPath = "v2/onboarding/me"
// OnboardingStatus describes status of the organization’s onboarding process.
type OnboardingStatus string
@@ -31,12 +31,12 @@ type OnboardingLinks struct {
// Onboarding data for an organization.
type Onboarding struct {
+ CanReceivePayments bool `json:"canReceivePayments,omitempty"`
+ CanReceiveSettlements bool `json:"canReceiveSettlements,omitempty"`
Resource string `json:"reference,omitempty"`
Name string `json:"name,omitempty"`
SignedUpAt *time.Time `json:"signedUpAt,omitempty"`
Status OnboardingStatus `json:"status,omitempty"`
- CanReceivePayments bool `json:"canReceivePayments,omitempty"`
- CanReveiceSettlements bool `json:"canReceiveSettlements,omitempty"`
Links OnboardingLinks `json:"_links,omitempty"`
}
@@ -44,7 +44,7 @@ type Onboarding struct {
//
// See: https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status
func (os *OnboardingService) GetOnboardingStatus(ctx context.Context) (res *Response, o *Onboarding, err error) {
- res, err = os.client.get(ctx, onboardingTarget, nil)
+ res, err = os.client.get(ctx, onboardingURLPath, nil)
if err != nil {
return
}
@@ -66,10 +66,10 @@ func (os *OnboardingService) GetOnboardingStatus(ctx context.Context) (res *Resp
// OnboardingDataOrganization contains data of the organization you want to provide.
type OnboardingDataOrganization struct {
Name string `json:"name,omitempty"`
- Address *Address `json:"address,omitempty"`
RegistrationNumber string `json:"registrationNumber,omitempty"`
VatNumber string `json:"vatNumber,omitempty"`
VatRegulation string `json:"vatRegulation,omitempty"`
+ Address *Address `json:"address,omitempty"`
}
// OnboardingDataProfile contains data of the payment profile you want to provide.
@@ -96,7 +96,7 @@ type OnboardingData struct {
//
// See: https://docs.mollie.com/reference/v2/onboarding-api/submit-onboarding-data
func (os *OnboardingService) SubmitOnboardingData(ctx context.Context, d *OnboardingData) (res *Response, err error) {
- res, err = os.client.post(ctx, onboardingTarget, d, nil)
+ res, err = os.client.post(ctx, onboardingURLPath, d, nil)
if err != nil {
return
}
From 3bd0e0e0805a97452c8142e977847bf639ad0447 Mon Sep 17 00:00:00 2001
From: Victor Hugo Avelar Ossorio
<7926849+VictorAvelar@users.noreply.github.com>
Date: Fri, 8 Mar 2024 22:57:28 +0100
Subject: [PATCH 13/23] check orders resource against api reference (#340)
---
docs/README.md | 298 ++++++++++++++++++++++++++--------------
mollie/captures_test.go | 4 +-
mollie/common_types.go | 4 +-
mollie/orders.go | 249 +++++++++++++++++++++------------
mollie/orders_test.go | 117 +++++++---------
testdata/orders.go | 4 +-
6 files changed, 413 insertions(+), 263 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 4a9d6250..0ee9b420 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -110,6 +110,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type CreateMandate](<#CreateMandate>)
- [type CreateMandateAccessTokenFields](<#CreateMandateAccessTokenFields>)
- [type CreateMollieConnectPaymentFields](<#CreateMollieConnectPaymentFields>)
+- [type CreateOrder](<#CreateOrder>)
- [type CreatePayment](<#CreatePayment>)
- [type CreatePaymentAccessTokenFields](<#CreatePaymentAccessTokenFields>)
- [type CreatePreAuthorizedPaymentFields](<#CreatePreAuthorizedPaymentFields>)
@@ -177,6 +178,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(os \*OnboardingService\) SubmitOnboardingData\(ctx context.Context, d \*OnboardingData\) \(res \*Response, err error\)](<#OnboardingService.SubmitOnboardingData>)
- [type OnboardingStatus](<#OnboardingStatus>)
- [type Order](<#Order>)
+- [type OrderAccessTokenFields](<#OrderAccessTokenFields>)
- [type OrderAddress](<#OrderAddress>)
- [type OrderLine](<#OrderLine>)
- [type OrderLineChangeInstruction](<#OrderLineChangeInstruction>)
@@ -197,15 +199,15 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type OrdersService](<#OrdersService>)
- [func \(ors \*OrdersService\) Cancel\(ctx context.Context, orderID string\) \(res \*Response, order \*Order, err error\)](<#OrdersService.Cancel>)
- [func \(ors \*OrdersService\) CancelOrderLines\(ctx context.Context, orderID string, orderLines \[\]OrderLine\) \(res \*Response, err error\)](<#OrdersService.CancelOrderLines>)
- - [func \(ors \*OrdersService\) Create\(ctx context.Context, ord Order, opts \*OrderOptions\) \(res \*Response, order \*Order, err error\)](<#OrdersService.Create>)
+ - [func \(ors \*OrdersService\) Create\(ctx context.Context, ord CreateOrder, opts \*OrderOptions\) \(res \*Response, order \*Order, err error\)](<#OrdersService.Create>)
- [func \(ors \*OrdersService\) CreateOrderPayment\(ctx context.Context, orderID string, ordPay \*OrderPayment\) \(res \*Response, payment \*Payment, err error\)](<#OrdersService.CreateOrderPayment>)
- [func \(ors \*OrdersService\) CreateOrderRefund\(ctx context.Context, orderID string, order \*Order\) \(res \*Response, refund \*Refund, err error\)](<#OrdersService.CreateOrderRefund>)
- [func \(ors \*OrdersService\) Get\(ctx context.Context, orID string, opts \*OrderOptions\) \(res \*Response, order \*Order, err error\)](<#OrdersService.Get>)
- [func \(ors \*OrdersService\) List\(ctx context.Context, opts \*OrderListOptions\) \(res \*Response, ordList \*OrderList, err error\)](<#OrdersService.List>)
- [func \(ors \*OrdersService\) ListOrderRefunds\(ctx context.Context, orderID string, opts \*OrderListRefundOptions\) \(res \*Response, orderListRefund \*OrderListRefund, err error\)](<#OrdersService.ListOrderRefunds>)
- [func \(ors \*OrdersService\) ManageOrderLines\(ctx context.Context, orderID string, operations \*OrderLineOperations\) \(res \*Response, order \*Order, err error\)](<#OrdersService.ManageOrderLines>)
- - [func \(ors \*OrdersService\) Update\(ctx context.Context, orderID string, ord Order\) \(res \*Response, order \*Order, err error\)](<#OrdersService.Update>)
- - [func \(ors \*OrdersService\) UpdateOrderLine\(ctx context.Context, orderID string, orderLineID string, orderLine OrderLine\) \(res \*Response, order \*Order, err error\)](<#OrdersService.UpdateOrderLine>)
+ - [func \(ors \*OrdersService\) Update\(ctx context.Context, orderID string, ord UpdateOrder\) \(res \*Response, order \*Order, err error\)](<#OrdersService.Update>)
+ - [func \(ors \*OrdersService\) UpdateOrderLine\(ctx context.Context, orderID string, orderLineID string, orderLine UpdateOrderLine\) \(res \*Response, order \*Order, err error\)](<#OrdersService.UpdateOrderLine>)
- [type Organization](<#Organization>)
- [type OrganizationLinks](<#OrganizationLinks>)
- [type OrganizationPartnerLinks](<#OrganizationPartnerLinks>)
@@ -266,7 +268,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ps \*PermissionsService\) List\(ctx context.Context\) \(res \*Response, pl \*PermissionsList, err error\)](<#PermissionsService.List>)
- [type PhoneNumber](<#PhoneNumber>)
- [type PreAuthorizedPaymentFields](<#PreAuthorizedPaymentFields>)
-- [type ProductType](<#ProductType>)
+- [type ProductKind](<#ProductKind>)
- [type Profile](<#Profile>)
- [type ProfileLinks](<#ProfileLinks>)
- [type ProfileList](<#ProfileList>)
@@ -357,6 +359,8 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type TransferFrequency](<#TransferFrequency>)
- [type URL](<#URL>)
- [type UpdateCustomer](<#UpdateCustomer>)
+- [type UpdateOrder](<#UpdateOrder>)
+- [type UpdateOrderLine](<#UpdateOrderLine>)
- [type UpdatePayment](<#UpdatePayment>)
- [type UsedGiftCard](<#UsedGiftCard>)
- [type UserAgentToken](<#UserAgentToken>)
@@ -1888,6 +1892,32 @@ type CreateMollieConnectPaymentFields struct {
}
```
+
+## type [CreateOrder]()
+
+CreateOrder contains the parameters to create an order.
+
+```go
+type CreateOrder struct {
+ ShopperCountryMustMatchTheBillingCountry bool `json:"shopperCountryMustMatchTheBillingCountry,omitempty"`
+ OrderNumber string `json:"orderNumber,omitempty"`
+ RedirectURL string `json:"redirectUrl,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ CancelURL string `json:"cancelUrl,omitempty"`
+ Amount *Amount `json:"amount,omitempty"`
+ BillingAddress *OrderAddress `json:"billingAddress,omitempty"`
+ ShippingAddress *OrderAddress `json:"shippingAddress,omitempty"`
+ ConsumerDateOfBirth *ShortDate `json:"consumerDateOfBirth,omitempty"`
+ Payment *OrderPayment `json:"payment,omitempty"`
+ ExpiresAt *ShortDate `json:"expiresAt,omitempty"`
+ Lines []OrderLine `json:"lines,omitempty"`
+ Method []PaymentMethod `json:"method,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ OrderAccessTokenFields
+}
+```
+
## type [CreatePayment]()
@@ -2177,18 +2207,26 @@ EmbedValue describes the valid value of embed query string.
type EmbedValue string
```
-Valid Embed query string value.
+Valid Embed query string value.
```go
const (
- EmbedPayment EmbedValue = "payments"
- EmbedRefund EmbedValue = "refunds"
+ EmbedPayments EmbedValue = "payments"
+ EmbedRefunds EmbedValue = "refunds"
EmbedShipments EmbedValue = "shipments"
EmbedChargebacks EmbedValue = "chargebacks"
EmbedCaptures EmbedValue = "captures"
)
```
+Local embed value type.
+
+```go
+const (
+ EmbedNestedPaymentDetails EmbedValue = "payments.details.remainderDetails"
+)
+```
+
## type [EntityType]()
@@ -2948,36 +2986,28 @@ const (
```
-## type [Order]()
+## type [Order]()
Order explain the items that customers need to pay for.
```go
type Order struct {
- TestMode bool `json:"testmode,omitempty"`
IsCancelable bool `json:"isCancelable,omitempty"`
ShopperCountryMustMatchTheBillingCountry bool `json:"shopperCountryMustMatchTheBillingCountry,omitempty"`
Resource string `json:"resource,omitempty"`
ID string `json:"id,omitempty"`
ProfileID string `json:"profileId,omitempty"`
- OrderNumber string `json:"orderNumber,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
- WebhookURL string `json:"webhookUrl,omitempty"`
- Description string `json:"description,omitempty"`
- Sku string `json:"sku,omitempty"`
CancelURL string `json:"cancelUrl,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
- Mode Mode `json:"mode,omitempty"`
- Method PaymentMethod `json:"method,omitempty"`
- Status OrderStatus `json:"status,omitempty"`
- Locale Locale `json:"locale,omitempty"`
- ShippingAddress OrderAddress `json:"shippingAddress,omitempty"`
- Links OrderLinks `json:"_links,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ OrderNumber string `json:"orderNumber,omitempty"`
+ Lines []*OrderLine `json:"lines,omitempty"`
Amount *Amount `json:"amount,omitempty"`
AmountCaptured *Amount `json:"amountCaptured,omitempty"`
AmountRefunded *Amount `json:"amountRefunded,omitempty"`
BillingAddress *OrderAddress `json:"billingAddress,omitempty"`
ConsumerDateOfBirth *ShortDate `json:"consumerDateOfBirth,omitempty"`
+ ShippingAddress *OrderAddress `json:"shippingAddress,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
ExpiredAt *time.Time `json:"expiredAt,omitempty"`
@@ -2985,8 +3015,12 @@ type Order struct {
AuthorizedAt *time.Time `json:"authorizedAt,omitempty"`
CanceledAt *time.Time `json:"canceledAt,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
- OrderPayment *OrderPayment `json:"payment,omitempty"`
- Lines []*OrderLine `json:"lines,omitempty"`
+ Method PaymentMethod `json:"method,omitempty"`
+ Mode Mode `json:"mode,omitempty"`
+ Locale Locale `json:"locale,omitempty"`
+ Status OrderStatus `json:"status,omitempty"`
+ Links OrderLinks `json:"_links,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
Embedded struct {
Payments []*Payment `json:"payments,omitempty"`
Refunds []*Refund `json:"refunds,omitempty"`
@@ -2994,8 +3028,20 @@ type Order struct {
}
```
+
+## type [OrderAccessTokenFields]()
+
+OrderAccessTokenFields contains the fields available to include in an order when using an access token.
+
+```go
+type OrderAccessTokenFields struct {
+ ProfileID string `json:"profileId,omitempty"`
+ Testmode bool `json:"testmode,omitempty"`
+}
+```
+
-## type [OrderAddress]()
+## type [OrderAddress]()
OrderAddress identify both the address and the person the order is billed or shipped to.
@@ -3006,57 +3052,53 @@ type OrderAddress struct {
GivenName string `json:"givenName,omitempty"`
FamilyName string `json:"familyName,omitempty"`
Email string `json:"email,omitempty"`
- Phone PhoneNumber `json:"phone,omitempty"`
StreetAndNumber string `json:"streetAndNumber,omitempty"`
StreetAdditional string `json:"streetAdditional,omitempty"`
PostalCode string `json:"postalCode,omitempty"`
City string `json:"city,omitempty"`
Region string `json:"region,omitempty"`
Country string `json:"country,omitempty"`
+ Phone PhoneNumber `json:"phone,omitempty"`
}
```
-## type [OrderLine]()
+## type [OrderLine]()
OrderLine contain the actual things the customer bought.
```go
type OrderLine struct {
- Resource string `json:"resource,omitempty"`
- ID string `json:"id,omitempty"`
- OrderID string `json:"orderId,omitempty"`
- ProductType ProductType `json:"type,omitempty"`
- Name string `json:"name,omitempty"`
- Amount *Amount `json:"amount,omitempty"`
- Status OrderLineStatus `json:"status,omitempty"`
IsCancelable bool `json:"isCancelable,omitempty"`
Quantity int `json:"quantity,omitempty"`
QuantityShipped int `json:"quantityShipped,omitempty"`
- AmountShipped *Amount `json:"amountShipped,omitempty"`
QuantityRefunded int `json:"quantityRefunded,omitempty"`
- AmountRefunded *Amount `json:"amountRefunded,omitempty"`
QuantityCanceled int `json:"quantityCanceled,omitempty"`
- AmountCanceled *Amount `json:"amountCanceled,omitempty"`
ShippableQuantity int `json:"shippableQuantity,omitempty"`
RefundableQuantity int `json:"refundableQuantity,omitempty"`
CancelableQuantity int `json:"cancelableQuantity,omitempty"`
+ Resource string `json:"resource,omitempty"`
+ ID string `json:"id,omitempty"`
+ OrderID string `json:"orderId,omitempty"`
+ Name string `json:"name,omitempty"`
+ VatRate string `json:"vatRate,omitempty"`
+ SKU string `json:"sku,omitempty"`
+ AmountShipped *Amount `json:"amountShipped,omitempty"`
+ AmountRefunded *Amount `json:"amountRefunded,omitempty"`
+ AmountCanceled *Amount `json:"amountCanceled,omitempty"`
UnitPrice *Amount `json:"unitPrice,omitempty"`
DiscountAmount *Amount `json:"discountAmount,omitempty"`
TotalAmount *Amount `json:"totalAmount,omitempty"`
- VatRate string `json:"vatRate,omitempty"`
VatAmount *Amount `json:"vatAmount,omitempty"`
- SKU string `json:"sku,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
+ ProductType ProductKind `json:"type,omitempty"`
+ Status OrderLineStatus `json:"status,omitempty"`
Links OrderLineLinks `json:"_links,omitempty"`
- ImageURL string `json:"imageUrl,omitempty"`
- ProductURL string `json:"productUrl,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
}
```
-## type [OrderLineChangeInstruction]()
+## type [OrderLineChangeInstruction]()
OrderLineChangeInstruction contains details on what needs to be changed when managing order lines.
@@ -3068,7 +3110,7 @@ type OrderLineChangeInstruction struct {
```
-## type [OrderLineLinks]()
+## type [OrderLineLinks]()
OrderLineLinks describes object with several URL objects relevant to the order line.
@@ -3080,7 +3122,7 @@ type OrderLineLinks struct {
```
-## type [OrderLineOperation]()
+## type [OrderLineOperation]()
OrderLineOperation describes supported operations when managing order lines.
@@ -3088,18 +3130,18 @@ OrderLineOperation describes supported operations when managing order lines.
type OrderLineOperation string
```
-Supported order lines operation types.
+Supported order lines operation types.
```go
const (
- AddOrderLine OrderLineOperation = "add"
- UpdateOrderLine OrderLineOperation = "update"
- CancelOrderLine OrderLineOperation = "cancel"
+ AddOrderLineOperation OrderLineOperation = "add"
+ UpdateOrderLineOperation OrderLineOperation = "update"
+ CancelOrderLineOperation OrderLineOperation = "cancel"
)
```
-## type [OrderLineOperationData]()
+## type [OrderLineOperationData]()
OrderLineOperationData contains the order line’s details for an update operation.
@@ -3112,19 +3154,20 @@ type OrderLineOperationData struct {
ImageURL string `json:"imageUrl,omitempty"`
ProductURL string `json:"productUrl,omitempty"`
VATRate string `json:"vatRate,omitempty"`
- Type string `json:"type,omitempty"`
+ Kind ProductKind `json:"type,omitempty"`
Category OrderLineOperationProductCategory `json:"category,omitempty"`
Amount *Amount `json:"amount,omitempty"`
UnitPrice *Amount `json:"unitPrice,omitempty"`
DiscountAmount *Amount `json:"discountAmount,omitempty"`
VATAmount *Amount `json:"vatAmount,omitempty"`
TotalAmount *Amount `json:"totalAmount,omitempty"`
- Metadata interface{} `json:"metadata,omitempty"`
+ Metadata any `json:"metadata,omitempty"`
+ OrderAccessTokenFields
}
```
-## type [OrderLineOperationProductCategory]()
+## type [OrderLineOperationProductCategory]()
OrderLineOperationProductCategory contains the product category.
@@ -3143,7 +3186,7 @@ const (
```
-## type [OrderLineOperations]()
+## type [OrderLineOperations]()
OrderLineOperations contains the operations to be performed when managing order lines.
@@ -3154,7 +3197,7 @@ type OrderLineOperations struct {
```
-## type [OrderLineStatus]()
+## type [OrderLineStatus]()
OrderLineStatus describes status of the order line.
@@ -3176,7 +3219,7 @@ const (
```
-## type [OrderLinks]()
+## type [OrderLinks]()
OrderLinks describes an object with several URL objects relevant to the order. Every URL object will contain an href and a type field.
@@ -3190,7 +3233,7 @@ type OrderLinks struct {
```
-## type [OrderList]()
+## type [OrderList]()
OrderList for containing the response of list orders.
@@ -3205,20 +3248,21 @@ type OrderList struct {
```
-## type [OrderListOptions]()
+## type [OrderListOptions]()
OrderListOptions describes order endpoint valid query string parameters.
```go
type OrderListOptions struct {
- ProfileID string `url:"profileId,omitempty"`
- From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
+ From string `url:"from,omitempty"`
+ Sort string `url:"sort,omitempty"`
+ ProfileID string `url:"profileId,omitempty"`
}
```
-## type [OrderListRefund]()
+## type [OrderListRefund]()
OrderListRefund for containing the response of list orders.
@@ -3233,7 +3277,7 @@ type OrderListRefund struct {
```
-## type [OrderListRefundOptions]()
+## type [OrderListRefundOptions]()
OrderListRefundOptions describes order endpoint valid query string parameters.
@@ -3246,40 +3290,51 @@ type OrderListRefundOptions struct {
```
-## type [OrderOptions]()
+## type [OrderOptions]()
OrderOptions describes order endpoint valid query string parameters.
```go
type OrderOptions struct {
- Embed []EmbedValue `url:"embed,omitempty"`
ProfileID string `url:"profileId,omitempty"`
+ Embed []EmbedValue `url:"embed,omitempty"`
}
```
-## type [OrderPayment]()
+## type [OrderPayment]()
OrderPayment describes payment specific parameters that can be passed during order creation.
```go
type OrderPayment struct {
- ConsumerAccount string `json:"consumerAccount,omitempty"`
- CustomerID string `json:"customerId,omitempty"`
- CustomerReference string `json:"customerReference,omitempty"`
- Issuer string `json:"issuer,omitempty"`
- MandateID string `json:"mandateId,omitempty"`
- SequenceType SequenceType `json:"sequenceType,omitempty"`
- VoucherNumber string `json:"voucherNumber,omitempty"`
- VoucherPin string `json:"voucherPin,omitempty"`
- WebhookURL string `json:"webhookUrl,omitempty"`
- ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
- Method PaymentMethod `json:"method,omitempty"`
+ ApplePayPaymentToken string `json:"applePayPaymentToken,omitempty"`
+ CardToken string `json:"cardToken,omitempty"`
+ ConsumerAccount string `json:"consumerAccount,omitempty"`
+ CustomerID string `json:"customerId,omitempty"`
+ CustomerReference string `json:"customerReference,omitempty"`
+ ExtraMerchantData string `json:"extraMerchantData,omitempty"`
+ Issuer string `json:"issuer,omitempty"`
+ VoucherNumber string `json:"voucherNumber,omitempty"`
+ VoucherPin string `json:"voucherPin,omitempty"`
+ WebhookURL string `json:"webhookUrl,omitempty"`
+ BillingEmail string `json:"billingEmail,omitempty"`
+ SessionID string `json:"sessionId,omitempty"`
+ TerminalID string `json:"terminalId,omitempty"`
+ ConsumerName string `json:"consumerName,omitempty"`
+ DueDate *ShortDate `json:"dueDate,omitempty"`
+ ShippingAddress *Address `json:"shippingAddress,omitempty"`
+ BillingAddress *Address `json:"billingAddress,omitempty"`
+ Company *Company `json:"company,omitempty"`
+ // Only available when using access tokens.
+ ApplicationFee *ApplicationFee `json:"applicationFee,omitempty"`
+ SequenceType SequenceType `json:"sequenceType,omitempty"`
+ Method []PaymentMethod `json:"method,omitempty"`
}
```
-## type [OrderStatus]()
+## type [OrderStatus]()
OrderStatus describes the valid order status.
@@ -3302,7 +3357,7 @@ const (
```
-## type [OrdersService]()
+## type [OrdersService]()
OrdersService instance operates over refund resources.
@@ -3311,7 +3366,7 @@ type OrdersService service
```
-### func \(\*OrdersService\) [Cancel]()
+### func \(\*OrdersService\) [Cancel](