Skip to content

Commit

Permalink
ISSUE-63 - Add executeThreeD value to AdditionalData
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed Aug 23, 2018
1 parent 11cc777 commit 15fc688
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 5 deletions.
13 changes: 13 additions & 0 deletions boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ func (b *stringBool) UnmarshalJSON(data []byte) (err error) {
*b = stringBool(parsed)
return
}

func (b stringBool) MarshalJSON() ([]byte, error) {
boolResult := bool(b)
var boolString string

if boolResult {
boolString = `"true"`
} else {
boolString = `"false"`
}

return []byte(boolString), nil
}
72 changes: 72 additions & 0 deletions boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type thing struct {
Bool stringBool `json:"value"`
}

type thingWithEmpty struct {
Bool *stringBool `json:"value,omitempty"`
}

func TestStringBool_Unmarshal(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -86,3 +90,71 @@ func TestStringBool_Unmarshal(t *testing.T) {
})
}
}

func TestStringBool_Marshal(t *testing.T) {
cases := []struct {
name string
object thing
expected string
}{
{
name: "true",
object: thing{Bool: stringBool(true)},
expected: `{"value":"true"}`,
},
{
name: "false",
object: thing{Bool: stringBool(false)},
expected: `{"value":"false"}`,
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
res, _ := json.Marshal(c.object)
str := string(res)

if c.expected != str {
t.Fatalf("my exp: %v but got %v", c.expected, str)
}
})
}
}

func TestStringBool_MarshalWithOmitempty(t *testing.T) {
valueTrue := stringBool(true)
valueFalse := stringBool(false)

cases := []struct {
name string
object thingWithEmpty
expected string
}{
{
name: "true",
object: thingWithEmpty{Bool: &valueTrue},
expected: `{"value":"true"}`,
},
{
name: "false",
object: thingWithEmpty{Bool: &valueFalse},
expected: `{"value":"false"}`,
},
{
name: "false",
object: thingWithEmpty{},
expected: `{}`,
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
res, _ := json.Marshal(c.object)
str := string(res)

if c.expected != str {
t.Fatalf("my exp: %v but got %v", c.expected, str)
}
})
}
}
7 changes: 4 additions & 3 deletions payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ type AuthoriseResponse struct {

// AdditionalData stores encrypted information about customer's credit card
type AdditionalData struct {
Content string `json:"card.encrypted.json,omitempty"`
AliasType string `json:"aliasType,omitempty"`
Alias string `json:"alias,omitempty"`
Content string `json:"card.encrypted.json,omitempty"`
AliasType string `json:"aliasType,omitempty"`
Alias string `json:"alias,omitempty"`
ExecuteThreeD *stringBool `json:"executeThreeD,omitempty"`
}

// BrowserInfo hold information on the user browser
Expand Down
11 changes: 9 additions & 2 deletions payment_gateway_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adyen

import (
"encoding/json"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -75,12 +76,18 @@ func TestAuthorise(t *testing.T) {
t.Errorf("Response should be succesfull, error - %s", err.Error())
}

responseBytes, err := json.Marshal(response)

if err != nil {
t.Error("Response can't be converted to JSON")
}

if response.PspReference == "" {
t.Errorf("Response should contain PSP Reference. Response - %s", response)
t.Errorf("Response should contain PSP Reference. Response - %s", string(responseBytes))
}

if response.ResultCode != "Authorised" {
t.Errorf("Response resultCode should be Authorised, Response - %s", response)
t.Errorf("Response resultCode should be Authorised, Response - %s", string(responseBytes))
}
}

Expand Down

0 comments on commit 15fc688

Please sign in to comment.