Compare commits

...

11 Commits

Author SHA1 Message Date
5c4c0e1b7b Merge pull request 'staging' (#5) from staging into master
Reviewed-on: #5
2024-10-22 18:42:28 +02:00
63bbbdf1e1 Update events to trigger actions lint-test.yaml 2024-10-22 18:42:28 +02:00
283485068c Merge pull request 'staging' (#3) from staging into master
All checks were successful
Lint and Test / lint (push) Successful in 10m22s
Lint and Test / test (push) Successful in 10m5s
Reviewed-on: #3
2024-10-22 16:37:21 +02:00
fb37ee85f2 Update package name 2024-10-22 16:37:21 +02:00
f840b7aac7
Add omitempty to JSON tags to CardBillingAddress AddressLine2 and AdminArea2
All checks were successful
Lint and Test / lint (push) Successful in 10m22s
Lint and Test / test (push) Successful in 10m6s
2024-10-22 14:24:40 +02:00
6217511bbd
Add omitempty to JSON tags to PaymentSourceCard type 2024-10-22 14:23:56 +02:00
27ffa97190
Add vendor directory to .gitignore 2024-10-22 14:22:47 +02:00
Alex Pliutau
0a5a40c12c
Create CONTRIBUTING.md
Some checks failed
Lint and Test / test (push) Waiting to run
Lint and Test / lint (push) Has been cancelled
2024-09-24 11:51:26 +02:00
Alex Pliutau
c9c1a38641 Remove unused tokenservice endpoints 2024-08-30 13:57:08 +02:00
Suhail Gupta
9451befb2b
Update README.md (#273) 2024-08-30 13:46:26 +02:00
Penny
daabe58f88
fix: Log request body (#272) 2024-08-19 13:24:58 +02:00
9 changed files with 60 additions and 92 deletions

View File

@ -1,6 +1,16 @@
name: Lint and Test
on: push
on:
push:
branches:
- features/*
- testing/*
- fix/*
- enhance/*
pull_request:
branches:
- master
- staging
jobs:
lint:
@ -11,7 +21,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 +43,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

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
.idea
.vscode
.vscode
vendor/

10
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,10 @@
First off all, thank you for considering contributing to this project. It's people like you that make it such a great tool.
Keep an open mind! Improving documentation, bug triaging, or writing tutorials are all examples of helpful contributions that mean less work for you.
Some basic suggestions to get you started:
- Make sure the PR is up-to-date with the latest changes in the main branch.
- Make sure the PR passes all the tests.
- Make sure the PR passes the linter.
- Make sure the PR is well documented and formatted.
- Make sure the PR is well tested.

View File

@ -1,5 +1,10 @@
[Docs](https://pkg.go.dev/github.com/plutov/paypal)
<p>
<a href="https://github.com/plutov/paypal/releases"><img src="https://img.shields.io/github/release/plutov/paypal.svg" alt="Latest Release"></a>
<a href="https://pkg.go.dev/github.com/plutov/paypal?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
</p>
# Go client for PayPal REST API
## Paypal REST API Docs
@ -62,7 +67,7 @@ order, err := c.GetOrder("O-4J082351X3132253H")
ctx := context.Background()
units := []paypal.PurchaseUnitRequest{}
source := &paypal.PaymentSource{}
appCtx := &paypalApplicationContext{}
appCtx := &paypal.ApplicationContext{}
order, err := c.CreateOrder(ctx, paypal.OrderIntentCapture, units, ource, appCtx)
```
@ -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

View File

@ -97,13 +97,23 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
if c.returnRepresentation {
req.Header.Set("Prefer", "return=representation")
}
if c.Log != nil {
if reqDump, err := httputil.DumpRequestOut(req, true); err == nil {
c.Log.Write([]byte(fmt.Sprintf("Request: %s\n", reqDump)))
}
}
resp, err = c.Client.Do(req)
c.log(req, resp)
if err != nil {
return err
}
if c.Log != nil {
if respDump, err := httputil.DumpResponse(resp, true); err == nil {
c.Log.Write([]byte(fmt.Sprintf("Response from %s: %s\n", req.URL, respDump)))
}
}
defer func(Body io.ReadCloser) error {
return Body.Close()
}(resp.Body)
@ -180,22 +190,3 @@ func (c *Client) NewRequest(ctx context.Context, method, url string, payload int
}
return http.NewRequestWithContext(ctx, method, url, buf)
}
// log will dump request and response to the log file
func (c *Client) log(r *http.Request, resp *http.Response) {
if c.Log != nil {
var (
reqDump string
respDump []byte
)
if r != nil {
reqDump = fmt.Sprintf("%s %s. Data: %s", r.Method, r.URL.String(), r.Form.Encode())
}
if resp != nil {
respDump, _ = httputil.DumpResponse(resp, true)
}
c.Log.Write([]byte(fmt.Sprintf("Request: %s\nResponse: %s\n", reqDump, string(respDump))))
}
}

4
go.mod
View File

@ -1,6 +1,6 @@
module github.com/plutov/paypal/v4
module euphoria-laxis.fr/go-packages/paypale/v4
go 1.21
go 1.23
require github.com/stretchr/testify v1.9.0

View File

@ -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=<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{}

View File

@ -5,7 +5,7 @@ import (
"encoding/json"
"testing"
"github.com/plutov/paypal/v4"
"euphoria-laxis.fr/go-packages/paypale/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -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
@ -1057,14 +1057,14 @@ type (
// PaymentSourceCard structure
PaymentSourceCard struct {
ID string `json:"id"`
Name string `json:"name"`
Number string `json:"number"`
Expiry string `json:"expiry"`
SecurityCode string `json:"security_code"`
LastDigits string `json:"last_digits"`
CardType string `json:"card_type"`
BillingAddress *CardBillingAddress `json:"billing_address"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Number string `json:"number,omitempty"`
Expiry string `json:"expiry,omitempty"`
SecurityCode string `json:"security_code,omitempty"`
LastDigits string `json:"last_digits,omitempty"`
CardType string `json:"card_type,omitempty"`
BillingAddress *CardBillingAddress `json:"billing_address,omitempty"`
}
// PaymentSourcePaypal structure
@ -1086,8 +1086,8 @@ type (
// CardBillingAddress structure
CardBillingAddress struct {
AddressLine1 string `json:"address_line_1"`
AddressLine2 string `json:"address_line_2"`
AdminArea2 string `json:"admin_area_2"`
AddressLine2 string `json:"address_line_2,omitempty"`
AdminArea2 string `json:"admin_area_2,omitempty"`
AdminArea1 string `json:"admin_area_1"`
PostalCode string `json:"postal_code"`
CountryCode string `json:"country_code"`