mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 02:11:02 +01:00
Update package name
This commit is contained in:
parent
f7f8c60772
commit
e70e544c1a
44
README.md
44
README.md
|
@ -1,6 +1,6 @@
|
||||||
[![Go Report Card](https://goreportcard.com/badge/plutov/PayPal-Go-SDK)](https://goreportcard.com/report/plutov/PayPal-Go-SDK)
|
[![Go Report Card](https://goreportcard.com/badge/plutov/paypal)](https://goreportcard.com/report/plutov/paypal)
|
||||||
[![Build Status](https://travis-ci.org/plutov/PayPal-Go-SDK.svg?branch=master)](https://travis-ci.org/plutov/PayPal-Go-SDK)
|
[![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-Go-SDK)
|
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/plutov/paypal)
|
||||||
|
|
||||||
### Go client for PayPal REST API
|
### Go client for PayPal REST API
|
||||||
|
|
||||||
|
@ -43,15 +43,15 @@ Currently supports **v2** only, if you want to use **v1**, use **v1.1.4** git ta
|
||||||
* POST /v2/payments/billing-agreements/***TOKEN***/agreement-execute
|
* POST /v2/payments/billing-agreements/***TOKEN***/agreement-execute
|
||||||
|
|
||||||
### Missing endpoints
|
### Missing endpoints
|
||||||
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**
|
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**
|
||||||
|
|
||||||
### New Client
|
### New Client
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "github.com/plutov/PayPal-Go-SDK"
|
import "github.com/plutov/paypal"
|
||||||
|
|
||||||
// Create a client instance
|
// Create a client instance
|
||||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
|
||||||
c.SetLog(os.Stdout) // Set log to terminal stdout
|
c.SetLog(os.Stdout) // Set log to terminal stdout
|
||||||
|
|
||||||
accessToken, err := c.GetAccessToken()
|
accessToken, err := c.GetAccessToken()
|
||||||
|
@ -66,7 +66,7 @@ auth, err := c.GetAuthorization("2DC87612EK520411B")
|
||||||
### Capture authorization
|
### Capture authorization
|
||||||
|
|
||||||
```go
|
```go
|
||||||
capture, err := c.CaptureAuthorization(authID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"}, true)
|
capture, err := c.CaptureAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"}, true)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Void authorization
|
### Void authorization
|
||||||
|
@ -78,7 +78,7 @@ auth, err := c.VoidAuthorization(authID)
|
||||||
### Reauthorize authorization
|
### Reauthorize authorization
|
||||||
|
|
||||||
```go
|
```go
|
||||||
auth, err := c.ReauthorizeAuthorization(authID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"})
|
auth, err := c.ReauthorizeAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get Sale by ID
|
### Get Sale by ID
|
||||||
|
@ -93,7 +93,7 @@ sale, err := c.GetSale("36C38912MN9658832")
|
||||||
// Full
|
// Full
|
||||||
refund, err := c.RefundSale(saleID, nil)
|
refund, err := c.RefundSale(saleID, nil)
|
||||||
// Partial
|
// Partial
|
||||||
refund, err := c.RefundSale(saleID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"})
|
refund, err := c.RefundSale(saleID, &paypal.Amount{Total: "7.00", Currency: "USD"})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get Refund by ID
|
### Get Refund by ID
|
||||||
|
@ -111,25 +111,25 @@ order, err := c.GetOrder("O-4J082351X3132253H")
|
||||||
### Create an Order
|
### Create an Order
|
||||||
|
|
||||||
```go
|
```go
|
||||||
order, err := c.CreateOrder(paypalsdk.OrderIntentCapture, []paypalsdk.PurchaseUnitRequest{paypalsdk.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypalsdk.Amount{Total: "7.00", Currency: "USD"}}})
|
order, err := c.CreateOrder(paypal.OrderIntentCapture, []paypal.PurchaseUnitRequest{paypal.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypal.Amount{Total: "7.00", Currency: "USD"}}})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Update Order by ID
|
### Update Order by ID
|
||||||
|
|
||||||
```go
|
```go
|
||||||
order, err := c.UpdateOrder("O-4J082351X3132253H", []paypalsdk.PurchaseUnitRequest{})
|
order, err := c.UpdateOrder("O-4J082351X3132253H", []paypal.PurchaseUnitRequest{})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Authorize Order
|
### Authorize Order
|
||||||
|
|
||||||
```go
|
```go
|
||||||
auth, err := c.AuthorizeOrder(orderID, paypalsdk.AuthorizeOrderRequest{})
|
auth, err := c.AuthorizeOrder(orderID, paypal.AuthorizeOrderRequest{})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Capture Order
|
### Capture Order
|
||||||
|
|
||||||
```go
|
```go
|
||||||
capture, err := c.CaptureOrder(orderID, paypalsdk.CaptureOrderRequest{})
|
capture, err := c.CaptureOrder(orderID, paypal.CaptureOrderRequest{})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Identity
|
### Identity
|
||||||
|
@ -149,15 +149,15 @@ userInfo, err := c.GetUserInfo("openid")
|
||||||
### Create single payout to email
|
### Create single payout to email
|
||||||
|
|
||||||
```go
|
```go
|
||||||
payout := paypalsdk.Payout{
|
payout := paypal.Payout{
|
||||||
SenderBatchHeader: &paypalsdk.SenderBatchHeader{
|
SenderBatchHeader: &paypal.SenderBatchHeader{
|
||||||
EmailSubject: "Subject will be displayed on PayPal",
|
EmailSubject: "Subject will be displayed on PayPal",
|
||||||
},
|
},
|
||||||
Items: []paypalsdk.PayoutItem{
|
Items: []paypal.PayoutItem{
|
||||||
paypalsdk.PayoutItem{
|
paypal.PayoutItem{
|
||||||
RecipientType: "EMAIL",
|
RecipientType: "EMAIL",
|
||||||
Receiver: "single-email-payout@mail.com",
|
Receiver: "single-email-payout@mail.com",
|
||||||
Amount: &paypalsdk.AmountPayout{
|
Amount: &paypal.AmountPayout{
|
||||||
Value: "15.11",
|
Value: "15.11",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
|
@ -247,7 +247,7 @@ err := c.DeleteWebProfile("XP-CP6S-W9DY-96H8-MVN2")
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Store CC
|
// Store CC
|
||||||
c.StoreCreditCard(paypalsdk.CreditCard{
|
c.StoreCreditCard(paypal.CreditCard{
|
||||||
Number: "4417119669820331",
|
Number: "4417119669820331",
|
||||||
Type: "visa",
|
Type: "visa",
|
||||||
ExpireMonth: "11",
|
ExpireMonth: "11",
|
||||||
|
@ -261,8 +261,8 @@ c.StoreCreditCard(paypalsdk.CreditCard{
|
||||||
c.DeleteCreditCard("CARD-ID-123")
|
c.DeleteCreditCard("CARD-ID-123")
|
||||||
|
|
||||||
// Edit it
|
// Edit it
|
||||||
c.PatchCreditCard("CARD-ID-123", []paypalsdk.CreditCardField{
|
c.PatchCreditCard("CARD-ID-123", []paypal.CreditCardField{
|
||||||
paypalsdk.CreditCardField{
|
paypal.CreditCardField{
|
||||||
Operation: "replace",
|
Operation: "replace",
|
||||||
Path: "/billing_address/line1",
|
Path: "/billing_address/line1",
|
||||||
Value: "New value",
|
Value: "New value",
|
||||||
|
@ -290,5 +290,5 @@ Current contributors:
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
* Unit tests: `go test`
|
* Unit tests: `go test -v ./...`
|
||||||
* Integration tests: `go test -tags=integration`
|
* Integration tests: `go test -tags=integration`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
@ -1,39 +1,37 @@
|
||||||
package paypalsdk_test
|
package paypal_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pp "github.com/plutov/PayPal-Go-SDK"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func BillingExample() {
|
func BillingExample() {
|
||||||
plan := pp.BillingPlan{
|
plan := BillingPlan{
|
||||||
Name: "Plan with Regular and Trial Payment Definitions",
|
Name: "Plan with Regular and Trial Payment Definitions",
|
||||||
Description: "Plan with regular and trial payment definitions.",
|
Description: "Plan with regular and trial payment definitions.",
|
||||||
Type: "fixed",
|
Type: "fixed",
|
||||||
PaymentDefinitions: []pp.PaymentDefinition{
|
PaymentDefinitions: []PaymentDefinition{
|
||||||
{
|
{
|
||||||
Name: "Regular payment definition",
|
Name: "Regular payment definition",
|
||||||
Type: "REGULAR",
|
Type: "REGULAR",
|
||||||
Frequency: "MONTH",
|
Frequency: "MONTH",
|
||||||
FrequencyInterval: "2",
|
FrequencyInterval: "2",
|
||||||
Amount: pp.AmountPayout{
|
Amount: AmountPayout{
|
||||||
Value: "100",
|
Value: "100",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
Cycles: "12",
|
Cycles: "12",
|
||||||
ChargeModels: []pp.ChargeModel{
|
ChargeModels: []ChargeModel{
|
||||||
{
|
{
|
||||||
Type: "SHIPPING",
|
Type: "SHIPPING",
|
||||||
Amount: pp.AmountPayout{
|
Amount: AmountPayout{
|
||||||
Value: "10",
|
Value: "10",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: "TAX",
|
Type: "TAX",
|
||||||
Amount: pp.AmountPayout{
|
Amount: AmountPayout{
|
||||||
Value: "12",
|
Value: "12",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
|
@ -45,22 +43,22 @@ func BillingExample() {
|
||||||
Type: "trial",
|
Type: "trial",
|
||||||
Frequency: "week",
|
Frequency: "week",
|
||||||
FrequencyInterval: "5",
|
FrequencyInterval: "5",
|
||||||
Amount: pp.AmountPayout{
|
Amount: AmountPayout{
|
||||||
Value: "9.19",
|
Value: "9.19",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
Cycles: "2",
|
Cycles: "2",
|
||||||
ChargeModels: []pp.ChargeModel{
|
ChargeModels: []ChargeModel{
|
||||||
{
|
{
|
||||||
Type: "SHIPPING",
|
Type: "SHIPPING",
|
||||||
Amount: pp.AmountPayout{
|
Amount: AmountPayout{
|
||||||
Value: "1",
|
Value: "1",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: "TAX",
|
Type: "TAX",
|
||||||
Amount: pp.AmountPayout{
|
Amount: AmountPayout{
|
||||||
Value: "2",
|
Value: "2",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
|
@ -68,8 +66,8 @@ func BillingExample() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MerchantPreferences: &pp.MerchantPreferences{
|
MerchantPreferences: &MerchantPreferences{
|
||||||
SetupFee: &pp.AmountPayout{
|
SetupFee: &AmountPayout{
|
||||||
Value: "1",
|
Value: "1",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
|
@ -80,7 +78,7 @@ func BillingExample() {
|
||||||
MaxFailAttempts: "0",
|
MaxFailAttempts: "0",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c, err := pp.NewClient("clientID", "secretID", pp.APIBaseSandBox)
|
c, err := NewClient("clientID", "secretID", APIBaseSandBox)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -94,18 +92,18 @@ func BillingExample() {
|
||||||
}
|
}
|
||||||
err = c.ActivatePlan(planResp.ID)
|
err = c.ActivatePlan(planResp.ID)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
agreement := pp.BillingAgreement{
|
agreement := BillingAgreement{
|
||||||
Name: "Fast Speed Agreement",
|
Name: "Fast Speed Agreement",
|
||||||
Description: "Agreement for Fast Speed Plan",
|
Description: "Agreement for Fast Speed Plan",
|
||||||
StartDate: pp.JSONTime(time.Now().Add(time.Hour * 24)),
|
StartDate: JSONTime(time.Now().Add(time.Hour * 24)),
|
||||||
Plan: pp.BillingPlan{ID: planResp.ID},
|
Plan: BillingPlan{ID: planResp.ID},
|
||||||
Payer: pp.Payer{
|
Payer: Payer{
|
||||||
PaymentMethod: "paypal",
|
PaymentMethod: "paypal",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp, err := c.CreateBillingAgreement(agreement)
|
resp, err := c.CreateBillingAgreement(agreement)
|
||||||
fmt.Println(err, resp)
|
fmt.Println(err, resp)
|
||||||
|
|
||||||
bps, err := c.ListBillingPlans(pp.BillingPlanListParams{Status: "ACTIVE"})
|
bps, err := c.ListBillingPlans(BillingPlanListParams{Status: "ACTIVE"})
|
||||||
fmt.Println(err, bps)
|
fmt.Println(err, bps)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewClient returns new Client struct
|
// NewClient returns new Client struct
|
||||||
// APIBase is a base API URL, for testing you can use paypalsdk.APIBaseSandBox
|
// APIBase is a base API URL, for testing you can use paypal.APIBaseSandBox
|
||||||
func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
|
func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
|
||||||
if clientID == "" || secret == "" || APIBase == "" {
|
if clientID == "" || secret == "" || APIBase == "" {
|
||||||
return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
|
return nil, errors.New("ClientID, Secret and APIBase are required to create a Client")
|
||||||
|
@ -65,7 +65,7 @@ func (c *Client) SetAccessToken(token string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLog will set/change the output destination.
|
// SetLog will set/change the output destination.
|
||||||
// If log file is set paypalsdk will log all requests and responses to this Writer
|
// If log file is set paypal will log all requests and responses to this Writer
|
||||||
func (c *Client) SetLog(log io.Writer) {
|
func (c *Client) SetLog(log io.Writer) {
|
||||||
c.Log = log
|
c.Log = log
|
||||||
}
|
}
|
||||||
|
|
10
doc.go
10
doc.go
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
Package paypalsdk provides a wrapper to PayPal API (https://developer.paypal.com/webapps/developer/docs/api/).
|
Package paypal provides a wrapper to PayPal API (https://developer.paypal.com/webapps/developer/docs/api/).
|
||||||
The first thing you do is to create a Client (you can select API base URL using paypalsdk contants).
|
The first thing you do is to create a Client (you can select API base URL using paypal contants).
|
||||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
|
||||||
Then you can get an access token from PayPal:
|
Then you can get an access token from PayPal:
|
||||||
accessToken, err := c.GetAccessToken()
|
accessToken, err := c.GetAccessToken()
|
||||||
After you have an access token you can call built-in functions to get data from PayPal.
|
After you have an access token you can call built-in functions to get data from PayPal.
|
||||||
paypalsdk will assign all responses to go structures.
|
paypal will assign all responses to go structures.
|
||||||
*/
|
*/
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package paypalsdk_test
|
package paypal_test
|
||||||
|
|
||||||
import paypalsdk "github.com/plutov/PayPal-Go-SDK"
|
import paypal "github.com/plutov/paypal"
|
||||||
|
|
||||||
func Example() {
|
func Example() {
|
||||||
// Initialize client
|
// Initialize client
|
||||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build integration
|
// +build integration
|
||||||
|
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
2
types.go
2
types.go
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package paypalsdk
|
package paypal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -44,7 +44,7 @@ func (c *Client) GetWebProfile(profileID string) (*WebProfile, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if wp.ID == "" {
|
if wp.ID == "" {
|
||||||
return &wp, fmt.Errorf("paypalsdk: unable to get web profile with ID = %s", profileID)
|
return &wp, fmt.Errorf("paypal: unable to get web profile with ID = %s", profileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &wp, nil
|
return &wp, nil
|
||||||
|
@ -76,7 +76,7 @@ func (c *Client) GetWebProfiles() ([]WebProfile, error) {
|
||||||
func (c *Client) SetWebProfile(wp WebProfile) error {
|
func (c *Client) SetWebProfile(wp WebProfile) error {
|
||||||
|
|
||||||
if wp.ID == "" {
|
if wp.ID == "" {
|
||||||
return fmt.Errorf("paypalsdk: no ID specified for WebProfile")
|
return fmt.Errorf("paypal: no ID specified for WebProfile")
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", wp.ID)
|
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", wp.ID)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user