diff --git a/mollie/common_types.go b/mollie/common_types.go index 77e9956..e395ab9 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" url:"currency,omitempty"` - Value string `json:"value,omitempty" url:"value,omitempty"` + Currency string `json:"currency,omitempty" url:"amount[currency],omitempty"` + Value string `json:"value,omitempty" url:"amount[value],omitempty"` } // Address provides a human friendly representation of a geographical space. diff --git a/mollie/common_types_test.go b/mollie/common_types_test.go index ef15118..1f5ebc5 100644 --- a/mollie/common_types_test.go +++ b/mollie/common_types_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/google/go-querystring/query" "github.com/stretchr/testify/assert" ) @@ -49,3 +50,24 @@ func TestShortDate_MarshalJSON(t *testing.T) { assert.Nil(t, err) }) } + +func TestURLQueryEncode(t *testing.T) { + cases := []struct { + name string + in any + expected string + }{ + { + "test amount encode", + &Amount{Currency: "EUR", Value: "10.00"}, + "amount%5Bcurrency%5D=EUR&amount%5Bvalue%5D=10.00", + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + v, _ := query.Values(c.in) + assert.Equal(t, c.expected, v.Encode()) + }) + } +}