forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use real time.Time structs for CreatedAt/UpdatedAt
Also introduce Date struct to handle values from Braintree that are dates rather than datetimes.
- Loading branch information
Showing
10 changed files
with
102 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package braintree | ||
|
||
import ( | ||
"encoding/xml" | ||
"time" | ||
) | ||
|
||
// Date wraps a time object but handles deserializing dates returned from the Braintree API | ||
// e.g. "2014-02-09" | ||
type Date struct { | ||
*time.Time | ||
} | ||
|
||
func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error { | ||
var v string | ||
dec.DecodeElement(&v, &start) | ||
|
||
parse, err := time.Parse("2006-01-02", v) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*d = Date{Time: &parse} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package braintree | ||
|
||
import ( | ||
"encoding/xml" | ||
"testing" | ||
) | ||
|
||
func TestDateUnmarshalXML(t *testing.T) { | ||
date := &Date{} | ||
|
||
dateXML := []byte(`<?xml version="1.0" encoding="UTF-8"?><foo>2014-02-09</foo></xml>`) | ||
if err := xml.Unmarshal(dateXML, date); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if date.Format("2006-01-02") != "2014-02-09" { | ||
t.Fatalf("expected 2014-02-09 got %s", date) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
package braintree | ||
|
||
import "time" | ||
|
||
const ( | ||
ModificationKindDiscount = "discount" | ||
ModificationKindAddOn = "add_on" | ||
) | ||
|
||
type Modification struct { | ||
Id string `xml:"id,omitempty"` | ||
Amount float64 `xml:"amount,omitempty"` | ||
Description string `xml:"description,omitempty"` | ||
Kind string `xml:"kind,omitempty"` | ||
Name string `xml:"name,omitempty"` | ||
NeverExpires bool `xml:"never-expires,omitempty"` | ||
Quantity int `xml:"quantity,omitempty"` | ||
UpdatedAt string `xml:"updated_at,omitempty"` | ||
Id string `xml:"id,omitempty"` | ||
Amount float64 `xml:"amount,omitempty"` | ||
Description string `xml:"description,omitempty"` | ||
Kind string `xml:"kind,omitempty"` | ||
Name string `xml:"name,omitempty"` | ||
NeverExpires bool `xml:"never-expires,omitempty"` | ||
Quantity int `xml:"quantity,omitempty"` | ||
UpdatedAt *time.Time `xml:"updated_at,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters