paypale/README.md

300 lines
6.9 KiB
Markdown
Raw Normal View History

2019-08-21 15:50:20 +02:00
[![Go Report Card](https://goreportcard.com/badge/plutov/paypal)](https://goreportcard.com/report/plutov/paypal)
[![Build Status](https://travis-ci.org/plutov/paypal.svg?branch=master)](https://travis-ci.org/plutov/paypal)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/plutov/paypal)
2015-10-15 08:10:03 +02:00
2019-03-26 15:39:18 +01:00
### Go client for PayPal REST API
2019-03-27 09:27:53 +01:00
Currently supports **v2** only, if you want to use **v1**, use **v1.1.4** git tag.
2015-10-30 08:02:32 +01:00
2016-11-04 05:35:51 +01:00
### Coverage
2019-03-27 09:27:53 +01:00
2015-11-25 11:50:38 +01:00
* POST /v1/oauth2/token
* POST /v1/identity/openidconnect/tokenservice
* GET /v1/identity/openidconnect/userinfo/?schema=**SCHEMA**
* POST /v1/payments/payouts
* GET /v1/payments/payouts/**ID**
* GET /v1/payments/payouts-item/**ID**
* POST /v1/payments/payouts-item/**ID**/cancel
2016-11-01 13:05:20 +01:00
* GET /v1/payment-experience/web-profiles
* POST /v1/payment-experience/web-profiles
* GET /v1/payment-experience/web-profiles/**ID**
* PUT /v1/payment-experience/web-profiles/**ID**
* DELETE /v1/payment-experience/web-profiles/**ID**
2016-12-19 06:55:00 +01:00
* POST /v1/vault/credit-cards
* DELETE /v1/vault/credit-cards/**ID**
* PATCH /v1/vault/credit-cards/**ID**
* GET /v1/vault/credit-cards/**ID**
* GET /v1/vault/credit-cards
* GET /v2/payments/authorizations/**ID**
* POST /v2/payments/authorizations/**ID**/capture
* POST /v2/payments/authorizations/**ID**/void
* POST /v2/payments/authorizations/**ID**/reauthorize
2019-03-27 09:27:53 +01:00
* GET /v2/payments/sale/**ID**
* POST /v2/payments/sale/**ID**/refund
* GET /v2/payments/refund/**ID**
2019-06-27 06:22:30 +02:00
* POST /v2/checkout/orders
2019-04-21 05:08:48 +02:00
* GET /v2/checkout/orders/**ID**
2019-07-30 15:12:58 +02:00
* PATCH /v2/checkout/orders/**ID**
2019-04-21 05:08:48 +02:00
* POST /v2/checkout/orders/**ID**/authorize
* POST /v2/checkout/orders/**ID**/capture
* GET /v2/payments/billing-plans
2019-03-27 09:27:53 +01:00
* POST /v2/payments/billing-plans
* PATCH /v2/payments/billing-plans/***ID***
* POST /v2/payments/billing-agreements
* POST /v2/payments/billing-agreements/***TOKEN***/agreement-execute
* POST /v1/notifications/verify-webhook-signature
2015-11-25 11:50:38 +01:00
2016-11-04 05:35:51 +01:00
### Missing endpoints
2019-08-21 15:50:20 +02:00
It is possible that some endpoints are missing in this SDK Client, but you can use built-in **paypal** functions to perform a request: **NewClient -> NewRequest -> SendWithAuth**
2015-12-17 08:58:31 +01:00
2017-03-02 04:43:23 +01:00
### New Client
2015-10-30 08:02:32 +01:00
```go
2019-08-21 15:50:20 +02:00
import "github.com/plutov/paypal"
// If using Go Modules
// import "github.com/plutov/paypal/v3"
2015-10-30 08:02:32 +01:00
// Create a client instance
2019-08-21 15:50:20 +02:00
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
2016-05-14 14:38:24 +02:00
c.SetLog(os.Stdout) // Set log to terminal stdout
2015-10-30 08:02:32 +01:00
2015-11-20 07:38:40 +01:00
accessToken, err := c.GetAccessToken()
2015-11-16 06:11:27 +01:00
```
2016-11-04 05:35:51 +01:00
### Get authorization by ID
```go
2017-03-02 04:43:23 +01:00
auth, err := c.GetAuthorization("2DC87612EK520411B")
```
2016-11-04 05:35:51 +01:00
### Capture authorization
```go
2019-08-21 15:50:20 +02:00
capture, err := c.CaptureAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"}, true)
```
2016-11-04 05:35:51 +01:00
### Void authorization
```go
2015-12-17 08:58:31 +01:00
auth, err := c.VoidAuthorization(authID)
```
2016-11-04 05:35:51 +01:00
### Reauthorize authorization
```go
2019-08-21 15:50:20 +02:00
auth, err := c.ReauthorizeAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"})
```
2015-12-17 04:56:49 +01:00
2016-11-04 05:35:51 +01:00
### Get Sale by ID
2015-12-17 04:56:49 +01:00
```go
2017-03-02 04:43:23 +01:00
sale, err := c.GetSale("36C38912MN9658832")
2015-12-17 04:56:49 +01:00
```
2016-11-04 05:35:51 +01:00
### Refund Sale by ID
2015-12-17 04:56:49 +01:00
```go
// Full
2015-12-17 08:58:31 +01:00
refund, err := c.RefundSale(saleID, nil)
2015-12-17 04:56:49 +01:00
// Partial
2019-08-21 15:50:20 +02:00
refund, err := c.RefundSale(saleID, &paypal.Amount{Total: "7.00", Currency: "USD"})
2015-12-17 04:56:49 +01:00
```
2015-12-17 05:28:26 +01:00
2016-11-04 05:35:51 +01:00
### Get Refund by ID
2015-12-17 05:28:26 +01:00
```go
2017-03-02 04:43:23 +01:00
refund, err := c.GetRefund("O-4J082351X3132253H")
2015-12-17 08:50:25 +01:00
```
2016-11-04 05:35:51 +01:00
### Get Order by ID
2015-12-17 08:50:25 +01:00
```go
2017-03-02 04:43:23 +01:00
order, err := c.GetOrder("O-4J082351X3132253H")
2015-12-17 08:50:25 +01:00
```
2019-06-27 06:22:30 +02:00
### Create an Order
```go
2019-08-21 15:50:20 +02:00
order, err := c.CreateOrder(paypal.OrderIntentCapture, []paypal.PurchaseUnitRequest{paypal.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypal.Amount{Total: "7.00", Currency: "USD"}}})
2019-06-27 06:22:30 +02:00
```
2019-07-30 15:12:58 +02:00
### Update Order by ID
2015-12-17 08:50:25 +01:00
```go
2019-08-21 15:50:20 +02:00
order, err := c.UpdateOrder("O-4J082351X3132253H", []paypal.PurchaseUnitRequest{})
2015-12-17 08:50:25 +01:00
```
2019-07-30 15:12:58 +02:00
### Authorize Order
2015-12-17 08:50:25 +01:00
```go
2019-08-21 15:50:20 +02:00
auth, err := c.AuthorizeOrder(orderID, paypal.AuthorizeOrderRequest{})
2015-12-17 08:50:25 +01:00
```
2019-07-30 15:12:58 +02:00
### Capture Order
2015-12-17 08:50:25 +01:00
```go
2019-08-21 15:50:20 +02:00
capture, err := c.CaptureOrder(orderID, paypal.CaptureOrderRequest{})
2015-12-17 05:28:26 +01:00
```
2015-12-29 10:30:23 +01:00
2016-11-04 05:35:51 +01:00
### Identity
2016-01-18 09:42:42 +01:00
```go
token, err := c.GrantNewAccessTokenFromAuthCode("<Authorization-Code>", "http://example.com/myapp/return.php")
// ... or by refresh token
token, err := c.GrantNewAccessTokenFromRefreshToken("<Refresh-Token>")
```
2016-11-04 05:35:51 +01:00
### Retreive user information
```go
userInfo, err := c.GetUserInfo("openid")
```
2016-11-04 05:35:51 +01:00
### Create single payout to email
2016-02-17 05:10:49 +01:00
```go
2019-08-21 15:50:20 +02:00
payout := paypal.Payout{
SenderBatchHeader: &paypal.SenderBatchHeader{
2016-02-17 05:10:49 +01:00
EmailSubject: "Subject will be displayed on PayPal",
},
2019-08-21 15:50:20 +02:00
Items: []paypal.PayoutItem{
paypal.PayoutItem{
2016-02-17 05:10:49 +01:00
RecipientType: "EMAIL",
Receiver: "single-email-payout@mail.com",
2019-08-21 15:50:20 +02:00
Amount: &paypal.AmountPayout{
2016-02-17 05:10:49 +01:00
Value: "15.11",
Currency: "USD",
},
Note: "Optional note",
SenderItemID: "Optional Item ID",
},
},
}
payoutResp, err := c.CreateSinglePayout(payout)
```
### Get payout by ID
```go
payout, err := c.GetPayout("PayoutBatchID")
```
### Get payout item by ID
```go
payoutItem, err := c.GetPayoutItem("PayoutItemID")
```
### Cancel unclaimed payout item by ID
```go
payoutItem, err := c.CancelPayoutItem("PayoutItemID")
```
2016-11-01 13:05:20 +01:00
### Create web experience profile
```go
webprofile := WebProfile{
Name: "YeowZa! T-Shirt Shop",
Presentation: Presentation{
BrandName: "YeowZa! Paypal",
LogoImage: "http://www.yeowza.com",
LocaleCode: "US",
},
InputFields: InputFields{
AllowNote: true,
NoShipping: NoShippingDisplay,
AddressOverride: AddrOverrideFromCall,
},
FlowConfig: FlowConfig{
LandingPageType: LandingPageTypeBilling,
BankTXNPendingURL: "http://www.yeowza.com",
},
}
result, err := c.CreateWebProfile(webprofile)
```
### Get web experience profile
```go
webprofile, err := c.GetWebProfile("XP-CP6S-W9DY-96H8-MVN2")
```
### List web experience profile
```go
webprofiles, err := c.GetWebProfiles()
```
### Update web experience profile
```go
webprofile := WebProfile{
ID: "XP-CP6S-W9DY-96H8-MVN2",
Name: "Shop YeowZa! YeowZa! ",
}
err := c.SetWebProfile(webprofile)
```
### Delete web experience profile
```go
err := c.DeleteWebProfile("XP-CP6S-W9DY-96H8-MVN2")
```
2016-12-19 06:55:00 +01:00
### Vault
```go
// Store CC
2019-08-21 15:50:20 +02:00
c.StoreCreditCard(paypal.CreditCard{
2016-12-19 06:55:00 +01:00
Number: "4417119669820331",
Type: "visa",
ExpireMonth: "11",
ExpireYear: "2020",
CVV2: "874",
FirstName: "Foo",
LastName: "Bar",
})
// Delete it
c.DeleteCreditCard("CARD-ID-123")
// Edit it
2019-08-21 15:50:20 +02:00
c.PatchCreditCard("CARD-ID-123", []paypal.CreditCardField{
paypal.CreditCardField{
2016-12-19 06:55:00 +01:00
Operation: "replace",
Path: "/billing_address/line1",
Value: "New value",
},
})
// Get it
c.GetCreditCard("CARD-ID-123")
2017-03-02 04:43:23 +01:00
// Get all stored credit cards
2016-12-19 06:55:00 +01:00
c.GetCreditCards(nil)
```
2016-11-04 05:35:51 +01:00
### How to Contribute
2015-12-29 10:30:23 +01:00
* Fork a repository
* Add/Fix something
2017-03-02 04:43:23 +01:00
* Check that tests are passing
* Create PR
2019-07-22 15:02:18 +02:00
Current contributors:
- [Roopak Venkatakrishnan](https://github.com/roopakv)
2019-07-22 15:03:15 +02:00
- [Alex Pliutau](https://github.com/plutov)
2019-07-22 15:02:18 +02:00
2017-03-02 04:43:23 +01:00
### Tests
2019-08-21 15:50:20 +02:00
* Unit tests: `go test -v ./...`
2017-04-05 05:47:11 +02:00
* Integration tests: `go test -tags=integration`