Repository: VictorAvelar/mollie-api-go
Pull request #345 (2024-03-13 09:55:17)

check payment methods resource against api reference
<!--- Provide a general summary of your changes in the Title above -->

# Description

Ensures that the `payment methods` resource delivers API parity. 

## Motivation and context

Ensures the library has full API parity.

## How has this been tested?

Please describe in detail how you tested your changes.

Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.

- [x] Unit tests added / updated
- [x] The tests run on docker (using `make test`)
- [ ] The required `test data` has been added / updated

If you are running the tests locally, please specify:

- OS: macos
- Go version 1.22

## Types of changes

What types of changes does your code introduce? Put an `x` in all the boxes that apply:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] This change requires a documentation update

## Checklist

Go over all the following points, and put an `x` in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your [tests and code style pass](https://help.github.com/articles/about-required-status-checks/).

- [x] I have read the **[CONTRIBUTING](CONTRIBUTING.md)** document.
- [x] My pull request addresses exactly one patch/feature.
- [x] I have created a branch for this patch/feature.
- [x] Each individual commit in the pull request is meaningful.
- [x] If my change requires a change to the documentation, I have updated it accordingly.

<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->



Patch:
diff --git a/docs/README.md b/docs/README.md
index 869eeea..360c1ba 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -363,6 +363,7 @@ 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 Wallet](<#Wallet>)
 - [type WalletsService](<#WalletsService>)
   - [func \(ms \*WalletsService\) ApplePaymentSession\(ctx context.Context, asr \*ApplePaymentSessionRequest\) \(res \*Response, aps \*ApplePaymentSession, err error\)](<#WalletsService.ApplePaymentSession>)
 
@@ -434,13 +435,13 @@ Amount represents a currency and value pair.
 
 ```go
 type Amount struct {
-    Currency string `json:"currency,omitempty"`
-    Value    string `json:"value,omitempty"`
+    Currency string `json:"currency,omitempty" url:"currency,omitempty"`
+    Value    string `json:"value,omitempty"    url:"value,omitempty"`
 }
 ```
 
 <a name="ApplePaymentSession"></a>
-## type [ApplePaymentSession](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L13-L22>)
+## type [ApplePaymentSession](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L21-L30>)
 
 ApplePaymentSession contains information about an Apple pay session.
 
@@ -458,7 +459,7 @@ type ApplePaymentSession struct {
 ```
 
 <a name="ApplePaymentSessionRequest"></a>
-## type [ApplePaymentSessionRequest](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L26-L29>)
+## type [ApplePaymentSessionRequest](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L34-L37>)
 
 ApplePaymentSessionRequest contains the body parameters for requesting a valid PaymentSession from Apple.
 
@@ -2217,7 +2218,7 @@ const (
 ```
 
 <a name="EmbedValue"></a>
-## type [EmbedValue](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L334>)
+## type [EmbedValue](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L336>)
 
 EmbedValue describes the valid value of embed query string.
 
@@ -2440,7 +2441,7 @@ type GiftCardLinks struct {
 ```
 
 <a name="Image"></a>
-## type [Image](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L354-L358>)
+## type [Image](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L356-L360>)
 
 Image describes a generic image resource retrieved by Mollie.
 
@@ -2467,6 +2468,8 @@ type IncludeValue string
 const (
     IncludeQrCode           IncludeValue = "details.qrCode"
     IncludeRemainderDetails IncludeValue = "details.remainderDetails"
+    IncludeIssuers          IncludeValue = "issuers"
+    IncludePricing          IncludeValue = "pricing"
 )
 ```
 
@@ -3657,7 +3660,7 @@ GetPartnerStatus retrieves details about the partner status of the currently aut
 See: https://docs.mollie.com/reference/v2/organizations-api/get-partner
 
 <a name="Owner"></a>
-## type [Owner](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L361-L366>)
+## type [Owner](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L363-L368>)
 
 Personal data of your customer.
 
@@ -4054,7 +4057,7 @@ type PaymentMethodIssuer struct {
     Resource string `json:"resource,omitempty"`
     ID       string `json:"id,omitempty"`
     Name     string `json:"name,omitempty"`
-    Image    Image  `json:"image,omitempty"`
+    Image    *Image `json:"image,omitempty"`
 }
 ```
 
@@ -4065,10 +4068,10 @@ PaymentMethodOptions are applicable query string parameters to get methods from
 
 ```go
 type PaymentMethodOptions struct {
-    Locale    Locale `url:"locale,omitempty"`
-    Currency  string `url:"currency,omitempty"`
-    ProfileID string `url:"profileId,omitempty"`
-    Include   string `url:"include,omitempty"`
+    Locale    Locale         `url:"locale,omitempty"`
+    Currency  string         `url:"currency,omitempty"`
+    ProfileID string         `url:"profileId,omitempty"`
+    Include   []IncludeValue `url:"include,omitempty"`
 }
 ```
 
@@ -4080,8 +4083,8 @@ PaymentMethodPricing contains information about commissions and fees applicable
 ```go
 type PaymentMethodPricing struct {
     Description string    `json:"description,omitempty"`
-    Fixed       *Amount   `json:"fixed,omitempty"`
     Variable    string    `json:"variable,omitempty"`
+    Fixed       *Amount   `json:"fixed,omitempty"`
     FeeRegion   FeeRegion `json:"feeRegion,omitempty"`
 }
 ```
@@ -4123,7 +4126,7 @@ type PaymentMethodsList struct {
 ```
 
 <a name="PaymentMethodsListOptions"></a>
-## type [PaymentMethodsListOptions](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L83-L91>)
+## type [PaymentMethodsListOptions](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L83-L92>)
 
 PaymentMethodsListOptions are applicable query string parameters to list methods from mollie's API.
 
@@ -4132,17 +4135,18 @@ It contains list specific options and embeds GetMethodOptions.
 ```go
 type PaymentMethodsListOptions struct {
     PaymentMethodOptions
-    SequenceType   SequenceType `url:"sequenceType,omitempty"`
-    AmountCurrency string       `url:"amount[currency],omitempty"`
-    AmountValue    string       `url:"amount[value],omitempty"`
-    Resource       string       `url:"resource,omitempty"`
-    BillingCountry string       `url:"billingCountry,omitempty"`
-    IncludeWallets string       `url:"includeWallets,omitempty"`
+    Resource            string                              `url:"resource,omitempty"`
+    BillingCountry      string                              `url:"billingCountry,omitempty"`
+    Amount              *Amount                             `url:"amount,omitempty"`
+    IncludeWallets      []Wallet                            `url:"includeWallets,omitempty"`
+    OrderLineCategories []OrderLineOperationProductCategory `url:"orderLineCategories,omitempty"`
+    Locale              Locale                              `url:"locale,omitempty"`
+    SequenceType        SequenceType                        `url:"sequenceType,omitempty"`
 }
 ```
 
 <a name="PaymentMethodsService"></a>
-## type [PaymentMethodsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L94>)
+## type [PaymentMethodsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L95>)
 
 PaymentMethodsService operates on methods endpoints.
 
@@ -4151,7 +4155,7 @@ type PaymentMethodsService service
 ```
 
 <a name="PaymentMethodsService.All"></a>
-### func \(\*PaymentMethodsService\) [All](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L123-L127>)
+### func \(\*PaymentMethodsService\) [All](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L124-L128>)
 
 ```go
 func (ms *PaymentMethodsService) All(ctx context.Context, options *PaymentMethodsListOptions) (res *Response, pm *PaymentMethodsList, err error)
@@ -4162,7 +4166,7 @@ All retrieves all the payment methods enabled for your account/organization.
 See: https://docs.mollie.com/reference/v2/methods-api/list-all-methods
 
 <a name="PaymentMethodsService.Get"></a>
-### func \(\*PaymentMethodsService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L101-L105>)
+### func \(\*PaymentMethodsService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L102-L106>)
 
 ```go
 func (ms *PaymentMethodsService) Get(ctx context.Context, id PaymentMethod, options *PaymentMethodOptions) (res *Response, pmd *PaymentMethodDetails, err error)
@@ -4173,7 +4177,7 @@ Get returns information about the payment method specified by id, it also receiv
 See: https://docs.mollie.com/reference/v2/methods-api/get-method
 
 <a name="PaymentMethodsService.List"></a>
-### func \(\*PaymentMethodsService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L136-L140>)
+### func \(\*PaymentMethodsService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/payment_methods.go#L137-L141>)
 
 ```go
 func (ms *PaymentMethodsService) List(ctx context.Context, options *PaymentMethodsListOptions) (res *Response, pm *PaymentMethodsList, err error)
@@ -4655,7 +4659,7 @@ type QRCode struct {
 ```
 
 <a name="Rate"></a>
-## type [Rate](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L348-L351>)
+## type [Rate](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L350-L353>)
 
 Rate describes service rates, further divided into fixed and percentage costs.
 
@@ -5720,8 +5724,25 @@ type UserAgentToken struct {
 }
 ```
 
+<a name="Wallet"></a>
+## type [Wallet](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L9>)
+
+Wallet describes the wallet types that Mollie supports.
+
+```go
+type Wallet string
+```
+
+<a name="ApplePayWallet"></a>Available wallet types.
+
+```go
+const (
+    ApplePayWallet Wallet = "applepay"
+)
+```
+
 <a name="WalletsService"></a>
-## type [WalletsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L10>)
+## type [WalletsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L18>)
 
 WalletsService operates over the resources described in Mollie's wallets API endpoints section.
 
@@ -5730,7 +5751,7 @@ type WalletsService service
 ```
 
 <a name="WalletsService.ApplePaymentSession"></a>
-### func \(\*WalletsService\) [ApplePaymentSession](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L34-L38>)
+### func \(\*WalletsService\) [ApplePaymentSession](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/wallets.go#L42-L46>)
 
 ```go
 func (ms *WalletsService) ApplePaymentSession(ctx context.Context, asr *ApplePaymentSessionRequest) (res *Response, aps *ApplePaymentSession, err error)
diff --git a/mollie/common_types.go b/mollie/common_types.go
index b40d7bd..353df52 100644
--- a/mollie/common_types.go
+++ b/mollie/common_types.go
@@ -9,8 +9,8 @@ import (
 
 // Amount represents a currency and value pair.
 type Amount struct {
-	Currency string `json:"currency,omitempty"`
-	Value    string `json:"value,omitempty"`
+	Currency string `json:"currency,omitempty" url:"currency,omitempty"`
+	Value    string `json:"value,omitempty"    url:"value,omitempty"`
 }
 
 // Address provides a human friendly representation of a geographical space.
@@ -328,6 +328,8 @@ type IncludeValue string
 const (
 	IncludeQrCode           IncludeValue = "details.qrCode"
 	IncludeRemainderDetails IncludeValue = "details.remainderDetails"
+	IncludeIssuers          IncludeValue = "issuers"
+	IncludePricing          IncludeValue = "pricing"
 )
 
 // EmbedValue describes the valid value of embed query string.
diff --git a/mollie/payment_methods.go b/mollie/payment_methods.go
index 78414b1..1c277ab 100644
--- a/mollie/payment_methods.go
+++ b/mollie/payment_methods.go
@@ -44,8 +44,8 @@ type MethodsLinks struct {
 // applicable to a payment method.
 type PaymentMethodPricing struct {
 	Description string    `json:"description,omitempty"`
-	Fixed       *Amount   `json:"fixed,omitempty"`
 	Variable    string    `json:"variable,omitempty"`
+	Fixed       *Amount   `json:"fixed,omitempty"`
 	FeeRegion   FeeRegion `json:"feeRegion,omitempty"`
 }
 
@@ -55,7 +55,7 @@ type PaymentMethodIssuer struct {
 	Resource string `json:"resource,omitempty"`
 	ID       string `json:"id,omitempty"`
 	Name     string `json:"name,omitempty"`
-	Image    Image  `json:"image,omitempty"`
+	Image    *Image `json:"image,omitempty"`
 }
 
 // PaymentMethodsList describes a list of paginated payment methods.
@@ -70,10 +70,10 @@ type PaymentMethodsList struct {
 // PaymentMethodOptions are applicable query string parameters to get methods
 // from mollie's API.
 type PaymentMethodOptions struct {
-	Locale    Locale `url:"locale,omitempty"`
-	Currency  string `url:"currency,omitempty"`
-	ProfileID string `url:"profileId,omitempty"`
-	Include   string `url:"include,omitempty"`
+	Locale    Locale         `url:"locale,omitempty"`
+	Currency  string         `url:"currency,omitempty"`
+	ProfileID string         `url:"profileId,omitempty"`
+	Include   []IncludeValue `url:"include,omitempty"`
 }
 
 // PaymentMethodsListOptions are applicable query string parameters to list methods
@@ -82,12 +82,13 @@ type PaymentMethodOptions struct {
 // It contains list specific options and embeds GetMethodOptions.
 type PaymentMethodsListOptions struct {
 	PaymentMethodOptions
-	SequenceType   SequenceType `url:"sequenceType,omitempty"`
-	AmountCurrency string       `url:"amount[currency],omitempty"`
-	AmountValue    string       `url:"amount[value],omitempty"`
-	Resource       string       `url:"resource,omitempty"`
-	BillingCountry string       `url:"billingCountry,omitempty"`
-	IncludeWallets string       `url:"includeWallets,omitempty"`
+	Resource            string                              `url:"resource,omitempty"`
+	BillingCountry      string                              `url:"billingCountry,omitempty"`
+	Amount              *Amount                             `url:"amount,omitempty"`
+	IncludeWallets      []Wallet                            `url:"includeWallets,omitempty"`
+	OrderLineCategories []OrderLineOperationProductCategory `url:"orderLineCategories,omitempty"`
+	Locale              Locale                              `url:"locale,omitempty"`
+	SequenceType        SequenceType                        `url:"sequenceType,omitempty"`
 }
 
 // PaymentMethodsService operates on methods endpoints.
diff --git a/mollie/wallets.go b/mollie/wallets.go
index bc429ed..e0caeec 100644
--- a/mollie/wallets.go
+++ b/mollie/wallets.go
@@ -5,6 +5,14 @@ import (
 	"encoding/json"
 )
 
+// Wallet describes the wallet types that Mollie supports.
+type Wallet string
+
+// Available wallet types.
+const (
+	ApplePayWallet Wallet = "applepay"
+)
+
 // WalletsService operates over the resources described
 // in Mollie's wallets API endpoints section.
 type WalletsService service


Test patch:
diff --git a/mollie/custom_types_test.go b/mollie/custom_types_test.go
index e7f3cc7..b376218 100644
--- a/mollie/custom_types_test.go
+++ b/mollie/custom_types_test.go
@@ -3,6 +3,7 @@ package mollie
 import (
 	"testing"
 
+	"github.com/google/go-querystring/query"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -71,3 +72,57 @@ func TestContextValues_UnmarshalJSON(t *testing.T) {
 		})
 	}
 }
+
+func TestAmount_URLEncodingSimple(t *testing.T) {
+	tests := []struct {
+		name string
+		a    Amount
+		want string
+	}{
+		{
+			name: "Test URL encoding simple.",
+			a: Amount{
+				Value:    "10.00",
+				Currency: "EUR",
+			},
+			want: "currency=EUR&value=10.00",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			v, err := query.Values(tt.a)
+			assert.Nil(t, err)
+			assert.Equal(t, tt.want, v.Encode())
+		})
+	}
+}
+
+func TestAmount_URLEncodingNested(t *testing.T) {
+	tests := []struct {
+		name string
+		a    struct {
+			Amount Amount `url:"amount"`
+		}
+		want string
+	}{
+		{
+			name: "Test URL encoding nested amount in struct.",
+			a: struct {
+				Amount Amount `url:"amount"`
+			}{
+				Amount{
+					Value:    "10.00",
+					Currency: "EUR",
+				},
+			},
+			want: "amount%5Bcurrency%5D=EUR&amount%5Bvalue%5D=10.00",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			v, err := query.Values(tt.a)
+			assert.Nil(t, err)
+			assert.Equal(t, tt.want, v.Encode())
+		})
+	}
+}
diff --git a/mollie/payment_methods_test.go b/mollie/payment_methods_test.go
index 9fe60ef..8a0387b 100644
--- a/mollie/payment_methods_test.go
+++ b/mollie/payment_methods_test.go
@@ -51,8 +51,10 @@ func TestMethodsService_List(t *testing.T) {
 			args{
 				context.Background(),
 				&PaymentMethodsListOptions{
-					AmountCurrency: "EUR",
-					AmountValue:    "100.00",
+					Amount: &Amount{
+						Value:    "100.00",
+						Currency: "EUR",
+					},
 				},
 			},
 			false,
@@ -166,8 +168,10 @@ func TestMethodsService_All(t *testing.T) {
 			args{
 				context.Background(),
 				&PaymentMethodsListOptions{
-					AmountCurrency: "EUR",
-					AmountValue:    "100.00",
+					Amount: &Amount{
+						Value:    "100.00",
+						Currency: "EUR",
+					},
 				},
 			},
 			false,