forked from go-packages/paypal
Correctly handle the case when PayPal returns token expires_in field as a string
Credit goes to oauth2 package. https://github.com/golang/oauth2/blob/master/internal/token.go#L62
This commit is contained in:
parent
08326c3caa
commit
6bc1110944
19
types.go
19
types.go
|
@ -1,6 +1,7 @@
|
||||||
package paypalsdk
|
package paypalsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -454,12 +455,14 @@ type (
|
||||||
Phone string `json:"phone,omitempty"`
|
Phone string `json:"phone,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expirationTime int64
|
||||||
|
|
||||||
// TokenResponse is for API response for the /oauth2/token endpoint
|
// TokenResponse is for API response for the /oauth2/token endpoint
|
||||||
TokenResponse struct {
|
TokenResponse struct {
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken string `json:"refresh_token"`
|
||||||
Token string `json:"access_token"`
|
Token string `json:"access_token"`
|
||||||
Type string `json:"token_type"`
|
Type string `json:"token_type"`
|
||||||
ExpiresIn int64 `json:"expires_in"`
|
ExpiresIn expirationTime `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction struct
|
// Transaction struct
|
||||||
|
@ -544,3 +547,17 @@ func (t JSONTime) MarshalJSON() ([]byte, error) {
|
||||||
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
|
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
|
||||||
return []byte(stamp), nil
|
return []byte(stamp), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *expirationTime) UnmarshalJSON(b []byte) error {
|
||||||
|
var n json.Number
|
||||||
|
err := json.Unmarshal(b, &n)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
i, err := n.Int64()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*e = expirationTime(i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user