From c9c1a386415297031fe9c57ab3ddc0da844f4dac Mon Sep 17 00:00:00 2001 From: Alex Pliutau Date: Fri, 30 Aug 2024 13:57:08 +0200 Subject: [PATCH] Remove unused tokenservice endpoints --- .github/workflows/lint-test.yaml | 4 +-- README.md | 9 ++++-- go.mod | 2 +- identity.go | 49 -------------------------------- types.go | 4 +-- 5 files changed, 12 insertions(+), 56 deletions(-) diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index ead7ade..3906f1e 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -11,7 +11,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: "1.21.x" + go-version: "1.23" - name: Install dependencies run: go get . - name: Install linters @@ -33,7 +33,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: "1.21.x" + go-version: "1.23" - name: Install dependencies run: go get . - name: Run Tests diff --git a/README.md b/README.md index 5c91415..9d0eab4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ [Docs](https://pkg.go.dev/github.com/plutov/paypal) +

+ Latest Release + GoDoc +

+ # Go client for PayPal REST API ## Paypal REST API Docs @@ -294,10 +299,10 @@ invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33") - Check that tests are passing - Create PR -Current contributors: +Main contributors: -- [Roopak Venkatakrishnan](https://github.com/roopakv) - [Alex Pliutau](https://github.com/plutov) +- [Roopak Venkatakrishnan](https://github.com/roopakv) ## Tests diff --git a/go.mod b/go.mod index 9e6d0c1..13baae2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/plutov/paypal/v4 -go 1.21 +go 1.23 require github.com/stretchr/testify v1.9.0 diff --git a/identity.go b/identity.go index e94a646..7e3c6a2 100644 --- a/identity.go +++ b/identity.go @@ -4,59 +4,10 @@ import ( "context" "fmt" "net/http" - "net/url" - "strings" ) -// GrantNewAccessTokenFromAuthCode - Use this call to grant a new access token, using the previously obtained authorization code. -// Endpoint: POST /v1/identity/openidconnect/tokenservice -func (c *Client) GrantNewAccessTokenFromAuthCode(ctx context.Context, code, redirectURI string) (*TokenResponse, error) { - token := &TokenResponse{} - - q := url.Values{} - q.Set("grant_type", "authorization_code") - q.Set("code", code) - q.Set("redirect_uri", redirectURI) - - req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/identity/openidconnect/tokenservice"), strings.NewReader(q.Encode())) - if err != nil { - return token, err - } - - req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - - if err = c.SendWithBasicAuth(req, token); err != nil { - return token, err - } - - return token, nil -} - -// GrantNewAccessTokenFromRefreshToken - Use this call to grant a new access token, using a refresh token. -// Endpoint: POST /v1/identity/openidconnect/tokenservice -func (c *Client) GrantNewAccessTokenFromRefreshToken(ctx context.Context, refreshToken string) (*TokenResponse, error) { - type request struct { - GrantType string `json:"grant_type"` - RefreshToken string `json:"refresh_token"` - } - - token := &TokenResponse{} - - req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/identity/openidconnect/tokenservice"), request{GrantType: "refresh_token", RefreshToken: refreshToken}) - if err != nil { - return token, err - } - - if err = c.SendWithAuth(req, token); err != nil { - return token, err - } - - return token, nil -} - // GetUserInfo - Use this call to retrieve user profile attributes. // Endpoint: GET /v1/identity/openidconnect/userinfo/?schema= -// Pass the schema that is used to return as per openidconnect protocol. The only supported schema value is openid. func (c *Client) GetUserInfo(ctx context.Context, schema string) (*UserInfo, error) { u := &UserInfo{} diff --git a/types.go b/types.go index 7202d16..af048e7 100644 --- a/types.go +++ b/types.go @@ -12,10 +12,10 @@ import ( const ( // APIBaseSandBox points to the sandbox (for testing) version of the API - APIBaseSandBox = "https://api.sandbox.paypal.com" + APIBaseSandBox = "https://api-m.sandbox.paypal.com" // APIBaseLive points to the live version of the API - APIBaseLive = "https://api.paypal.com" + APIBaseLive = "https://api-m.paypal.com" // RequestNewTokenBeforeExpiresIn is used by SendWithAuth and try to get new Token when it's about to expire RequestNewTokenBeforeExpiresIn = time.Duration(60) * time.Second