forked from go-packages/paypal
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)
|
||||
[![Build Status](https://travis-ci.org/plutov/PayPal-Go-SDK.svg?branch=master)](https://travis-ci.org/plutov/PayPal-Go-SDK)
|
||||
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/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.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 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
|
||||
|
||||
### 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
|
||||
|
||||
```go
|
||||
import "github.com/plutov/PayPal-Go-SDK"
|
||||
import "github.com/plutov/paypal"
|
||||
|
||||
// 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
|
||||
|
||||
accessToken, err := c.GetAccessToken()
|
||||
|
@ -66,7 +66,7 @@ auth, err := c.GetAuthorization("2DC87612EK520411B")
|
|||
### Capture authorization
|
||||
|
||||
```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
|
||||
|
@ -78,7 +78,7 @@ auth, err := c.VoidAuthorization(authID)
|
|||
### Reauthorize authorization
|
||||
|
||||
```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
|
||||
|
@ -93,7 +93,7 @@ sale, err := c.GetSale("36C38912MN9658832")
|
|||
// Full
|
||||
refund, err := c.RefundSale(saleID, nil)
|
||||
// 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
|
||||
|
@ -111,25 +111,25 @@ order, err := c.GetOrder("O-4J082351X3132253H")
|
|||
### Create an Order
|
||||
|
||||
```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
|
||||
|
||||
```go
|
||||
order, err := c.UpdateOrder("O-4J082351X3132253H", []paypalsdk.PurchaseUnitRequest{})
|
||||
order, err := c.UpdateOrder("O-4J082351X3132253H", []paypal.PurchaseUnitRequest{})
|
||||
```
|
||||
|
||||
### Authorize Order
|
||||
|
||||
```go
|
||||
auth, err := c.AuthorizeOrder(orderID, paypalsdk.AuthorizeOrderRequest{})
|
||||
auth, err := c.AuthorizeOrder(orderID, paypal.AuthorizeOrderRequest{})
|
||||
```
|
||||
|
||||
### Capture Order
|
||||
|
||||
```go
|
||||
capture, err := c.CaptureOrder(orderID, paypalsdk.CaptureOrderRequest{})
|
||||
capture, err := c.CaptureOrder(orderID, paypal.CaptureOrderRequest{})
|
||||
```
|
||||
|
||||
### Identity
|
||||
|
@ -149,15 +149,15 @@ userInfo, err := c.GetUserInfo("openid")
|
|||
### Create single payout to email
|
||||
|
||||
```go
|
||||
payout := paypalsdk.Payout{
|
||||
SenderBatchHeader: &paypalsdk.SenderBatchHeader{
|
||||
payout := paypal.Payout{
|
||||
SenderBatchHeader: &paypal.SenderBatchHeader{
|
||||
EmailSubject: "Subject will be displayed on PayPal",
|
||||
},
|
||||
Items: []paypalsdk.PayoutItem{
|
||||
paypalsdk.PayoutItem{
|
||||
Items: []paypal.PayoutItem{
|
||||
paypal.PayoutItem{
|
||||
RecipientType: "EMAIL",
|
||||
Receiver: "single-email-payout@mail.com",
|
||||
Amount: &paypalsdk.AmountPayout{
|
||||
Amount: &paypal.AmountPayout{
|
||||
Value: "15.11",
|
||||
Currency: "USD",
|
||||
},
|
||||
|
@ -247,7 +247,7 @@ err := c.DeleteWebProfile("XP-CP6S-W9DY-96H8-MVN2")
|
|||
|
||||
```go
|
||||
// Store CC
|
||||
c.StoreCreditCard(paypalsdk.CreditCard{
|
||||
c.StoreCreditCard(paypal.CreditCard{
|
||||
Number: "4417119669820331",
|
||||
Type: "visa",
|
||||
ExpireMonth: "11",
|
||||
|
@ -261,8 +261,8 @@ c.StoreCreditCard(paypalsdk.CreditCard{
|
|||
c.DeleteCreditCard("CARD-ID-123")
|
||||
|
||||
// Edit it
|
||||
c.PatchCreditCard("CARD-ID-123", []paypalsdk.CreditCardField{
|
||||
paypalsdk.CreditCardField{
|
||||
c.PatchCreditCard("CARD-ID-123", []paypal.CreditCardField{
|
||||
paypal.CreditCardField{
|
||||
Operation: "replace",
|
||||
Path: "/billing_address/line1",
|
||||
Value: "New value",
|
||||
|
@ -290,5 +290,5 @@ Current contributors:
|
|||
|
||||
### Tests
|
||||
|
||||
* Unit tests: `go test`
|
||||
* Unit tests: `go test -v ./...`
|
||||
* Integration tests: `go test -tags=integration`
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
|
@ -1,39 +1,37 @@
|
|||
package paypalsdk_test
|
||||
package paypal_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
pp "github.com/plutov/PayPal-Go-SDK"
|
||||
)
|
||||
|
||||
func BillingExample() {
|
||||
plan := pp.BillingPlan{
|
||||
plan := BillingPlan{
|
||||
Name: "Plan with Regular and Trial Payment Definitions",
|
||||
Description: "Plan with regular and trial payment definitions.",
|
||||
Type: "fixed",
|
||||
PaymentDefinitions: []pp.PaymentDefinition{
|
||||
PaymentDefinitions: []PaymentDefinition{
|
||||
{
|
||||
Name: "Regular payment definition",
|
||||
Type: "REGULAR",
|
||||
Frequency: "MONTH",
|
||||
FrequencyInterval: "2",
|
||||
Amount: pp.AmountPayout{
|
||||
Amount: AmountPayout{
|
||||
Value: "100",
|
||||
Currency: "USD",
|
||||
},
|
||||
Cycles: "12",
|
||||
ChargeModels: []pp.ChargeModel{
|
||||
ChargeModels: []ChargeModel{
|
||||
{
|
||||
Type: "SHIPPING",
|
||||
Amount: pp.AmountPayout{
|
||||
Amount: AmountPayout{
|
||||
Value: "10",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: "TAX",
|
||||
Amount: pp.AmountPayout{
|
||||
Amount: AmountPayout{
|
||||
Value: "12",
|
||||
Currency: "USD",
|
||||
},
|
||||
|
@ -45,22 +43,22 @@ func BillingExample() {
|
|||
Type: "trial",
|
||||
Frequency: "week",
|
||||
FrequencyInterval: "5",
|
||||
Amount: pp.AmountPayout{
|
||||
Amount: AmountPayout{
|
||||
Value: "9.19",
|
||||
Currency: "USD",
|
||||
},
|
||||
Cycles: "2",
|
||||
ChargeModels: []pp.ChargeModel{
|
||||
ChargeModels: []ChargeModel{
|
||||
{
|
||||
Type: "SHIPPING",
|
||||
Amount: pp.AmountPayout{
|
||||
Amount: AmountPayout{
|
||||
Value: "1",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: "TAX",
|
||||
Amount: pp.AmountPayout{
|
||||
Amount: AmountPayout{
|
||||
Value: "2",
|
||||
Currency: "USD",
|
||||
},
|
||||
|
@ -68,8 +66,8 @@ func BillingExample() {
|
|||
},
|
||||
},
|
||||
},
|
||||
MerchantPreferences: &pp.MerchantPreferences{
|
||||
SetupFee: &pp.AmountPayout{
|
||||
MerchantPreferences: &MerchantPreferences{
|
||||
SetupFee: &AmountPayout{
|
||||
Value: "1",
|
||||
Currency: "USD",
|
||||
},
|
||||
|
@ -80,7 +78,7 @@ func BillingExample() {
|
|||
MaxFailAttempts: "0",
|
||||
},
|
||||
}
|
||||
c, err := pp.NewClient("clientID", "secretID", pp.APIBaseSandBox)
|
||||
c, err := NewClient("clientID", "secretID", APIBaseSandBox)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -94,18 +92,18 @@ func BillingExample() {
|
|||
}
|
||||
err = c.ActivatePlan(planResp.ID)
|
||||
fmt.Println(err)
|
||||
agreement := pp.BillingAgreement{
|
||||
agreement := BillingAgreement{
|
||||
Name: "Fast Speed Agreement",
|
||||
Description: "Agreement for Fast Speed Plan",
|
||||
StartDate: pp.JSONTime(time.Now().Add(time.Hour * 24)),
|
||||
Plan: pp.BillingPlan{ID: planResp.ID},
|
||||
Payer: pp.Payer{
|
||||
StartDate: JSONTime(time.Now().Add(time.Hour * 24)),
|
||||
Plan: BillingPlan{ID: planResp.ID},
|
||||
Payer: Payer{
|
||||
PaymentMethod: "paypal",
|
||||
},
|
||||
}
|
||||
resp, err := c.CreateBillingAgreement(agreement)
|
||||
fmt.Println(err, resp)
|
||||
|
||||
bps, err := c.ListBillingPlans(pp.BillingPlanListParams{Status: "ACTIVE"})
|
||||
bps, err := c.ListBillingPlans(BillingPlanListParams{Status: "ACTIVE"})
|
||||
fmt.Println(err, bps)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// 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) {
|
||||
if clientID == "" || secret == "" || APIBase == "" {
|
||||
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.
|
||||
// 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) {
|
||||
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/).
|
||||
The first thing you do is to create a Client (you can select API base URL using paypalsdk contants).
|
||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
||||
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 paypal contants).
|
||||
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
|
||||
Then you can get an access token from PayPal:
|
||||
accessToken, err := c.GetAccessToken()
|
||||
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() {
|
||||
// Initialize client
|
||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
||||
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build integration
|
||||
|
||||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package paypalsdk
|
||||
package paypal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -44,7 +44,7 @@ func (c *Client) GetWebProfile(profileID string) (*WebProfile, error) {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -76,7 +76,7 @@ func (c *Client) GetWebProfiles() ([]WebProfile, error) {
|
|||
func (c *Client) SetWebProfile(wp WebProfile) error {
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user