Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: go

go:
- 1.1
- 1.2
- 1.3
- release
- tip

before_install:
- go get github.com/smartystreets/goconvey

script:
- go test -v
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Payment REST API Go client

[![Coverage Status](https://coveralls.io/repos/fundary/paypal/badge.png)](https://coveralls.io/r/fundary/paypal) [![GoDoc](https://godoc.org/github.com/fundary/paypal?status.svg)](https://godoc.org/github.com/fundary/paypal)
[![Build Status](https://travis-ci.org/fundary/paypal.svg?branch=develop)](https://travis-ci.org/fundary/paypal) [![GoDoc](https://godoc.org/github.com/fundary/paypal?status.svg)](https://godoc.org/github.com/fundary/paypal)

This is a client for the Paypal REST API ([https://developer.paypal.com/webapps/developer/docs/api/](https://developer.paypal.com/webapps/developer/docs/api/)
A Go client for the Paypal REST API ([https://developer.paypal.com/webapps/developer/docs/api/](https://developer.paypal.com/webapps/developer/docs/api/))

## Goals

- [x] Automated tests that don't require manual approval in Paypal account
- [x] Concurrency safety by utilizing `PayPal-Request-Id`
- [ ] Automated tests that require manual approval in a Paypal account (with a different build tag, eg. `PAYPAL_APPROVED_PAYMENT_ID`
- [ ] Concurrency safety by utilizing `PayPal-Request-Id`

## Usage

Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {

client := paypal.NewClient(clientID, secret, paypal.APIBaseLive)

payments, err := client.ListPayments(map[string]string{
payments, err, _ := client.ListPayments(map[string]string{
"count": "10",
"sort_by": "create_time",
})
Expand All @@ -59,13 +59,13 @@ func main() {
This library use [Goconvey](http://goconvey.co/) for tests, so to run them, start Goconvey:

```
PAYPAL_TEST_CLIENTID=[Paypal Client ID] PAYPAL_TEST_SECRET=[Paypal Secret] goconvey
PAYPAL_TEST_CLIENTID=[Paypal Client ID] PAYPAL_TEST_SECRET=[Paypal Secret] PAYPAL_TEST_ACCOUNT_EMAIL=[Paypal test account email] goconvey
```

Or you can just use `go test`

```
PAYPAL_TEST_CLIENTID=[Paypal Client ID] PAYPAL_TEST_SECRET=[Paypal Secret] go test
PAYPAL_TEST_CLIENTID=[Paypal Client ID] PAYPAL_TEST_SECRET=[Paypal Secret] PAYPAL_TEST_ACCOUNT_EMAIL=[Paypal test account email] go test
```

## Roadmap
Expand All @@ -75,9 +75,10 @@ PAYPAL_TEST_CLIENTID=[Paypal Client ID] PAYPAL_TEST_SECRET=[Paypal Secret] go te
- [x] [Payments - Refunds](https://developer.paypal.com/webapps/developer/docs/api/#refunds)
- [x] [Payments - Authorizations](https://developer.paypal.com/webapps/developer/docs/api/#authorizations)
- [x] [Payments - Captures](https://developer.paypal.com/webapps/developer/docs/api/#billing-plans-and-agreements)
- [ ] [Payments - Billing Plans and Agreements](https://developer.paypal.com/webapps/developer/docs/api/#billing-plans-and-agreements)
- [ ] [Payments - Order](https://developer.paypal.com/webapps/developer/docs/api/#orders)
- [ ] [Vault](https://developer.paypal.com/webapps/developer/docs/api/#vault)
- [x] [Payments - Billing Plans and Agreements](https://developer.paypal.com/webapps/developer/docs/api/#billing-plans-and-agreements)
- [x] [Payments - Order](https://developer.paypal.com/webapps/developer/docs/api/#orders)
- [x] [Vault](https://developer.paypal.com/webapps/developer/docs/api/#vault)
- [ ] [Identity](https://developer.paypal.com/webapps/developer/docs/api/#identity)
- [ ] [Invoicing](https://developer.paypal.com/webapps/developer/docs/api/#invoicing)
- [x] [Invoicing](https://developer.paypal.com/webapps/developer/docs/api/#invoicing)
- [ ] [Payment Experience](https://developer.paypal.com/webapps/developer/docs/api/#payment-experience)
- [x] [Notifications](https://developer.paypal.com/webapps/developer/docs/api/#notifications)
45 changes: 24 additions & 21 deletions authorization.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package paypal

import "fmt"
import (
"fmt"
"net/http"
)

// https://developer.paypal.com/webapps/developer/docs/api/#authorizations

Expand All @@ -11,79 +14,79 @@ type (
)

// GetAuthorization returns an authorization by ID
func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
func (c *Client) GetAuthorization(authID string) (*Authorization, error, *http.Response) {
req, err := NewRequest("GET", fmt.Sprintf("%s/payments/authorization/%s", c.APIBase, authID), nil)
if err != nil {
return nil, err
return nil, err, nil
}

v := &Authorization{}

err = c.SendWithAuth(req, v)
resp, err := c.SendWithAuth(req, v)
if err != nil {
return nil, err
return nil, err, resp
}

return v, nil
return v, nil, resp
}

// CaptureAuthorization captures and process an existing authorization.
// To use this method, the original payment must have Intent set to PaymentIntentAuthorize
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error, *http.Response) {
req, err := NewRequest("POST", fmt.Sprintf("%s/payments/authorization/%s/capture", c.APIBase, authID), struct {
Amount *Amount `json:"amount"`
IsFinalCapture bool `json:"is_final_capture"`
}{a, isFinalCapture})
if err != nil {
return nil, err
return nil, err, nil
}

v := &Capture{}

err = c.SendWithAuth(req, v)
resp, err := c.SendWithAuth(req, v)
if err != nil {
return nil, err
return nil, err, resp
}

return v, nil
return v, nil, resp
}

// VoidAuthorization voids a previously authorized payment. A fully
// captured authorization cannot be voided
func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
func (c *Client) VoidAuthorization(authID string) (*Authorization, error, *http.Response) {
req, err := NewRequest("POST", fmt.Sprintf("%s/payments/authorization/%s/void", c.APIBase, authID), nil)
if err != nil {
return nil, err
return nil, err, nil
}

v := &Authorization{}

err = c.SendWithAuth(req, v)
resp, err := c.SendWithAuth(req, v)
if err != nil {
return nil, err
return nil, err, resp
}

return v, nil
return v, nil, resp
}

// ReauthorizeAuthorization reauthorize a Paypal account payment. Paypal recommends
// that a payment should be reauthorized after the initial 3-day honor period to
// ensure that funds are still available. Only paypal account payments can be re-
// authorized
func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error) {
func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error, *http.Response) {
req, err := NewRequest("POST", fmt.Sprintf("%s/payments/authorization/%s/reauthorize", c.APIBase, authID), struct {
Amount *Amount `json:"amount"`
}{a})
if err != nil {
return nil, err
return nil, err, nil
}

v := &Authorization{}

err = c.SendWithAuth(req, v)
resp, err := c.SendWithAuth(req, v)
if err != nil {
return nil, err
return nil, err, resp
}

return v, nil
return v, nil, resp
}
Loading