bugs everywhere

This commit is contained in:
imikod 2018-03-26 16:56:57 +03:00
parent 838828c020
commit 5ff41664bd
3 changed files with 13 additions and 23 deletions

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/http"
"time"
)
// ActivatePlan activates a billing plan.
@ -36,7 +35,7 @@ func (c *Client) CancelAgreement(agreementID string) error {
// A successful request returns the HTTP 204 No Content status code with no JSON response body.
// This raises error "EOF"
if err.Error() == "EOF" {
if err != nil && err.Error() == "EOF" {
return nil
}
@ -133,7 +132,7 @@ func (c *Client) ListBillingPlans(status interface{}, page interface{}) (*ListBi
// A successful request for empty list returns the HTTP 204 No Content status code with no JSON response body.
// This raises error "EOF"
if err.Error() == "EOF" {
if err != nil && err.Error() == "EOF" {
return &l, nil
}

View File

@ -99,7 +99,7 @@ func BillingExample() {
agreement := pp.BillingAgreement{
Name: "Fast Speed Agreement",
Description: "Agreement for Fast Speed Plan",
StartDate: pp.JSONTime(time.Now().Add(time.Hour * 24)),
StartDate: time.Now().UTC().Add(time.Hour * 24).Format(time.RFC3339),
Plan: pp.BillingPlan{ID: planResp.ID},
Payer: pp.Payer{
PaymentMethod: "paypal",

View File

@ -54,9 +54,6 @@ const (
)
type (
// JSONTime overrides MarshalJson method to format in ISO8601
JSONTime time.Time
// Address struct
Address struct {
Line1 string `json:"line1"`
@ -121,16 +118,16 @@ type (
// BillingAgreement struct
BillingAgreement struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
StartDate JSONTime `json:"start_date,omitempty"`
Plan BillingPlan `json:"plan,omitempty"`
Payer Payer `json:"payer,omitempty"`
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
State string `json:"state,omitempty"`
AgreementDetails AgreementDetails `json:"agreement_details"`
Links []Link `json:"links"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
StartDate string `json:"start_date,omitempty"`
Plan BillingPlan `json:"plan,omitempty"`
Payer Payer `json:"payer,omitempty"`
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
State string `json:"state,omitempty"`
AgreementDetails *AgreementDetails `json:"agreement_details,omitempty"`
Links []Link `json:"links,omitempty"`
}
// BillingPlan struct
@ -585,12 +582,6 @@ func (r *ErrorResponse) Error() string {
return fmt.Sprintf("%v %v: %d %s", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message)
}
// MarshalJSON for JSONTime
func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
return []byte(stamp), nil
}
func (e *expirationTime) UnmarshalJSON(b []byte) error {
var n json.Number
err := json.Unmarshal(b, &n)