Skip to content

Commit

Permalink
Merge pull request #94 from VictorAvelar/hotfix/methods-amount-list-q…
Browse files Browse the repository at this point in the history
…uery-parsing

Fixed amount query parsing for payment methods
  • Loading branch information
VictorAvelar authored Oct 18, 2020
2 parents fbdaaf4 + 08f2ee8 commit 0df48eb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## master

## v1.6.3

### Fixed
- Error when parsing amount values on payment methods #94

## v1.6.2

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@ type MethodsOptions struct {
Include string `url:"include,omitempty"`
// Use for List method only
SequenceType SequenceType `url:"sequenceType,omitempty"`
Amount Amount `url:"amount,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"`
Expand Down
3 changes: 2 additions & 1 deletion mollie/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type MethodsOptions struct {
Include string `url:"include,omitempty"`
// Use for List method only
SequenceType SequenceType `url:"sequenceType,omitempty"`
Amount Amount `url:"amount,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"`
Expand Down
75 changes: 75 additions & 0 deletions mollie/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,81 @@ import (
"github.com/VictorAvelar/mollie-api-go/testdata"
)

func TestMethodsService_ListWithQueryOptionsAmountCurrency(t *testing.T) {
setup()
defer teardown()
_ = tClient.WithAuthenticationValue("test_token")

tMux.HandleFunc("/v2/methods", func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer test_token")
testMethod(t, r, "GET")
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
}

if r.URL.RawQuery != "amount%5Bcurrency%5D=USD&amount%5Bvalue%5D=100.00" {
t.Fatal(r.URL.RawQuery)
}

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(testdata.ListMethodsResponse))
})

opts := &MethodsOptions{
AmountCurrency: "USD",
AmountValue: "100.00",
}

res, err := tClient.Methods.List(opts)
if err != nil {
t.Fatal(err)
}

if res.Count <= 0 {
t.Error("expecting methods and got 0")
}
}

func TestMethodsService_ListWithQueryOptionsAll(t *testing.T) {
setup()
defer teardown()
_ = tClient.WithAuthenticationValue("test_token")

tMux.HandleFunc("/v2/methods", func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer test_token")
testMethod(t, r, "GET")
if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
}

if r.URL.RawQuery != "amount%5Bcurrency%5D=USD&amount%5Bvalue%5D=100.00&billingCountry=DE&includeWallets=applepay&locale=de_DE&resource=orders&sequenceType=first" {
t.Fatal(r.URL.RawQuery)
}

w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(testdata.ListMethodsResponse))
})

opts := &MethodsOptions{
AmountCurrency: "USD",
AmountValue: "100.00",
Resource: "orders",
SequenceType: FirstSequence,
Locale: German,
BillingCountry: "DE",
IncludeWallets: "applepay",
}

res, err := tClient.Methods.List(opts)
if err != nil {
t.Fatal(err)
}

if res.Count <= 0 {
t.Error("expecting methods and got 0")
}
}

func TestMethodsService_Get(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 0df48eb

Please sign in to comment.