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
25
types.go
25
types.go
|
@ -1,6 +1,7 @@
|
|||
package paypalsdk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -454,12 +455,14 @@ type (
|
|||
Phone string `json:"phone,omitempty"`
|
||||
}
|
||||
|
||||
expirationTime int64
|
||||
|
||||
// TokenResponse is for API response for the /oauth2/token endpoint
|
||||
TokenResponse struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
Token string `json:"access_token"`
|
||||
Type string `json:"token_type"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
Token string `json:"access_token"`
|
||||
Type string `json:"token_type"`
|
||||
ExpiresIn expirationTime `json:"expires_in"`
|
||||
}
|
||||
|
||||
// Transaction struct
|
||||
|
@ -544,3 +547,17 @@ 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)
|
||||
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