paypale/README.md

330 lines
8.1 KiB
Markdown
Raw Normal View History

2016-12-22 06:06:00 +01:00
[![Go Report Card](https://goreportcard.com/badge/logpacker/PayPal-Go-SDK)](https://goreportcard.com/report/logpacker/PayPal-Go-SDK)
2016-01-05 07:08:02 +01:00
[![Build Status](https://travis-ci.org/logpacker/PayPal-Go-SDK.svg?branch=master)](https://travis-ci.org/logpacker/PayPal-Go-SDK)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/logpacker/PayPal-Go-SDK)
2016-01-20 07:37:00 +01:00
[![Chat at https://gitter.im/logpacker/PayPal-Go-SDK](https://img.shields.io/badge/gitter-dev_chat-46bc99.svg)](https://gitter.im/logpacker/PayPal-Go-SDK?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2017-02-13 05:00:23 +01:00
[![Sourcegraph](https://sourcegraph.com/github.com/logpacker/PayPal-Go-SDK/-/badge.svg)](https://sourcegraph.com/github.com/logpacker/PayPal-Go-SDK?badge)
2015-10-15 08:10:03 +02:00
2016-11-04 05:35:51 +01:00
### GO client for PayPal REST API
2015-10-30 08:02:32 +01:00
2016-11-04 05:35:51 +01:00
### Coverage
2015-11-25 11:50:38 +01:00
* POST /v1/oauth2/token
* POST /v1/payments/payment
2015-12-01 05:40:07 +01:00
* GET /v1/payments/payment/**ID**
* GET /v1/payments/payment
2015-12-01 05:40:07 +01:00
* GET /v1/payments/authorization/**ID**
* POST /v1/payments/authorization/**ID**/capture
* POST /v1/payments/authorization/**ID**/void
* POST /v1/payments/authorization/**ID**/reauthorize
2015-12-17 04:56:49 +01:00
* GET /v1/payments/sale/**ID**
* POST /v1/payments/sale/**ID**/refund
2015-12-17 05:28:26 +01:00
* GET /v1/payments/refund/**ID**
2015-12-17 08:50:25 +01:00
* GET /v1/payments/orders/**ID**
* POST /v1/payments/orders/**ID**/authorize
* POST /v1/payments/orders/**ID**/capture
* POST /v1/payments/orders/**ID**/do-void
* POST /v1/identity/openidconnect/tokenservice
* GET /v1/identity/openidconnect/userinfo/?schema=**SCHEMA**
* POST /v1/payments/payouts
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
2017-09-06 10:15:21 +02:00
* POST /v1/payments/billing-plans
* PATCH /v1/payments/billing-plans/***ID***
* POST /v1/payments/billing-agreements
* POST /v1/payments/billing-agreements/***TOKEN***/agreement-execute
2015-11-25 11:50:38 +01:00
2016-11-04 05:35:51 +01:00
### Missing endpoints
2015-12-17 08:58:31 +01:00
It is possible that some endpoints are missing in this SDK Client, but you can use built-in **paypalsdk** functions to perform a request: **NewClient -> NewRequest -> SendWithAuth**
2017-03-02 04:43:23 +01:00
### New Client
2015-10-30 08:02:32 +01:00
```go
2016-01-05 07:08:02 +01:00
import "github.com/logpacker/PayPal-Go-SDK"
2015-10-30 08:02:32 +01:00
// Create a client instance
2015-12-17 08:50:25 +01:00
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.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
### Create direct paypal payment
2015-11-25 11:50:38 +01:00
2015-11-16 07:15:24 +01:00
```go
2015-12-22 07:01:59 +01:00
amount := paypalsdk.Amount{
Total: "7.00",
2015-11-16 06:11:27 +01:00
Currency: "USD",
}
2015-11-25 11:50:38 +01:00
redirectURI := "http://example.com/redirect-uri"
cancelURI := "http://example.com/cancel-uri"
description := "Description for this payment"
paymentResult, err := c.CreateDirectPaypalPayment(amount, redirectURI, cancelURI, description)
2015-11-16 07:15:24 +01:00
```
2015-11-16 06:11:27 +01:00
2017-03-02 04:43:23 +01:00
### Create custom payment
```go
p := paypalsdk.Payment{
Intent: "sale",
Payer: &paypalsdk.Payer{
PaymentMethod: "credit_card",
FundingInstruments: []paypalsdk.FundingInstrument{paypalsdk.FundingInstrument{
CreditCard: &paypalsdk.CreditCard{
Number: "4111111111111111",
Type: "visa",
ExpireMonth: "11",
ExpireYear: "2020",
CVV2: "777",
FirstName: "John",
LastName: "Doe",
},
}},
},
Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
Amount: &paypalsdk.Amount{
Currency: "USD",
2015-12-22 07:01:59 +01:00
Total: "7.00",
},
Description: "My Payment",
}},
RedirectURLs: &paypalsdk.RedirectURLs{
ReturnURL: "http://...",
CancelURL: "http://...",
},
}
paymentResponse, err := client.CreatePayment(p)
```
2016-11-04 05:35:51 +01:00
### Execute approved payment
2015-11-25 11:50:38 +01:00
2015-11-16 07:15:24 +01:00
```go
2015-11-16 06:11:27 +01:00
paymentID := "PAY-17S8410768582940NKEE66EQ"
payerID := "7E7MGXCWTTKK2"
executeResult, err := c.ExecuteApprovedPayment(paymentID, payerID)
2015-10-30 08:02:32 +01:00
```
2015-11-25 11:30:25 +01:00
2016-11-04 05:35:51 +01:00
### Get payment by ID
2015-11-25 11:50:38 +01:00
2015-11-25 11:30:25 +01:00
```go
2017-03-02 04:43:23 +01:00
payment, err := c.GetPayment("PAY-17S8410768582940NKEE66EQ")
2015-11-25 11:30:25 +01:00
```
2016-11-04 05:35:51 +01:00
### Get list of payments
2015-11-25 11:50:38 +01:00
2015-11-25 11:30:25 +01:00
```go
payments, err := c.GetPayments()
```
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
2015-12-22 07:01:59 +01:00
capture, err := c.CaptureAuthorization(authID, &paypalsdk.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
2015-12-22 07:01:59 +01:00
auth, err := c.ReauthorizeAuthorization(authID, &paypalsdk.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
2015-12-22 07:01:59 +01:00
refund, err := c.RefundSale(saleID, &paypalsdk.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
```
2016-11-04 05:35:51 +01:00
### Authorize Order
2015-12-17 08:50:25 +01:00
```go
2015-12-22 07:01:59 +01:00
auth, err := c.AuthorizeOrder(orderID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"})
2015-12-17 08:50:25 +01:00
```
2016-11-04 05:35:51 +01:00
### Capture Order
2015-12-17 08:50:25 +01:00
```go
2015-12-22 07:01:59 +01:00
capture, err := c.CaptureOrder(orderID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"}, true, nil)
2015-12-17 08:50:25 +01:00
```
2016-11-04 05:35:51 +01:00
### Void Order
2015-12-17 08:50:25 +01:00
```go
2015-12-17 08:58:31 +01:00
order, err := c.VoidOrder(orderID)
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
payout := paypalsdk.Payout{
SenderBatchHeader: &paypalsdk.SenderBatchHeader{
EmailSubject: "Subject will be displayed on PayPal",
},
Items: []paypalsdk.PayoutItem{
paypalsdk.PayoutItem{
RecipientType: "EMAIL",
Receiver: "single-email-payout@mail.com",
Amount: &paypalsdk.AmountPayout{
Value: "15.11",
Currency: "USD",
},
Note: "Optional note",
SenderItemID: "Optional Item ID",
},
},
}
payoutResp, err := c.CreateSinglePayout(payout)
```
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
c.StoreCreditCard(paypalsdk.CreditCard{
Number: "4417119669820331",
Type: "visa",
ExpireMonth: "11",
ExpireYear: "2020",
CVV2: "874",
FirstName: "Foo",
LastName: "Bar",
})
// Delete it
c.DeleteCreditCard("CARD-ID-123")
// Edit it
c.PatchCreditCard("CARD-ID-123", []paypalsdk.CreditCardField{
paypalsdk.CreditCardField{
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
### Tests
2017-03-02 05:19:08 +01:00
* Unit tests: `go test`
2017-04-05 05:47:11 +02:00
* Integration tests: `go test -tags=integration`