forked from go-packages/paypal
Fix v2 endpoints, migrate to v1
This commit is contained in:
parent
4f66415fcd
commit
fc9dcf749b
14
README.md
14
README.md
|
@ -29,19 +29,19 @@ Currently supports **v2** only, if you want to use **v1**, use **v1.1.4** git ta
|
||||||
* POST /v2/payments/authorizations/**ID**/capture
|
* POST /v2/payments/authorizations/**ID**/capture
|
||||||
* POST /v2/payments/authorizations/**ID**/void
|
* POST /v2/payments/authorizations/**ID**/void
|
||||||
* POST /v2/payments/authorizations/**ID**/reauthorize
|
* POST /v2/payments/authorizations/**ID**/reauthorize
|
||||||
* GET /v2/payments/sale/**ID**
|
* GET /v1/payments/sale/**ID**
|
||||||
* POST /v2/payments/sale/**ID**/refund
|
* POST /v1/payments/sale/**ID**/refund
|
||||||
* GET /v2/payments/refund/**ID**
|
* GET /v2/payments/refund/**ID**
|
||||||
* POST /v2/checkout/orders
|
* POST /v2/checkout/orders
|
||||||
* GET /v2/checkout/orders/**ID**
|
* GET /v2/checkout/orders/**ID**
|
||||||
* PATCH /v2/checkout/orders/**ID**
|
* PATCH /v2/checkout/orders/**ID**
|
||||||
* POST /v2/checkout/orders/**ID**/authorize
|
* POST /v2/checkout/orders/**ID**/authorize
|
||||||
* POST /v2/checkout/orders/**ID**/capture
|
* POST /v2/checkout/orders/**ID**/capture
|
||||||
* GET /v2/payments/billing-plans
|
* GET /v1/payments/billing-plans
|
||||||
* POST /v2/payments/billing-plans
|
* POST /v1/payments/billing-plans
|
||||||
* PATCH /v2/payments/billing-plans/***ID***
|
* PATCH /v1/payments/billing-plans/***ID***
|
||||||
* POST /v2/payments/billing-agreements
|
* POST /v1/payments/billing-agreements
|
||||||
* POST /v2/payments/billing-agreements/***TOKEN***/agreement-execute
|
* POST /v1/payments/billing-agreements/***TOKEN***/agreement-execute
|
||||||
* POST /v1/notifications/webhooks
|
* POST /v1/notifications/webhooks
|
||||||
* GET /v1/notifications/webhooks
|
* GET /v1/notifications/webhooks
|
||||||
* GET /v1/notifications/webhooks/**ID**
|
* GET /v1/notifications/webhooks/**ID**
|
||||||
|
|
20
billing.go
20
billing.go
|
@ -48,9 +48,9 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateBillingPlan creates a billing plan in Paypal
|
// CreateBillingPlan creates a billing plan in Paypal
|
||||||
// Endpoint: POST /v2/payments/billing-plans
|
// Endpoint: POST /v1/payments/billing-plans
|
||||||
func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) {
|
func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) {
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/billing-plans"), plan)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan)
|
||||||
response := &CreateBillingResp{}
|
response := &CreateBillingResp{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
|
@ -61,10 +61,10 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error)
|
||||||
|
|
||||||
// ActivatePlan activates a billing plan
|
// ActivatePlan activates a billing plan
|
||||||
// By default, a new plan is not activated
|
// By default, a new plan is not activated
|
||||||
// Endpoint: PATCH /v2/payments/billing-plans/
|
// Endpoint: PATCH /v1/payments/billing-plans/
|
||||||
func (c *Client) ActivatePlan(planID string) error {
|
func (c *Client) ActivatePlan(planID string) error {
|
||||||
buf := bytes.NewBuffer([]byte(`[{"op":"replace","path":"/","value":{"state":"ACTIVE"}}]`))
|
buf := bytes.NewBuffer([]byte(`[{"op":"replace","path":"/","value":{"state":"ACTIVE"}}]`))
|
||||||
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/billing-plans/"+planID), buf)
|
req, err := http.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans/"+planID), buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ func (c *Client) ActivatePlan(planID string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateBillingAgreement creates an agreement for specified plan
|
// CreateBillingAgreement creates an agreement for specified plan
|
||||||
// Endpoint: POST /v2/payments/billing-agreements
|
// Endpoint: POST /v1/payments/billing-agreements
|
||||||
func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementResp, error) {
|
func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementResp, error) {
|
||||||
// PayPal needs only ID, so we will remove all fields except Plan ID
|
// PayPal needs only ID, so we will remove all fields except Plan ID
|
||||||
a.Plan = BillingPlan{
|
a.Plan = BillingPlan{
|
||||||
ID: a.Plan.ID,
|
ID: a.Plan.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/billing-agreements"), a)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements"), a)
|
||||||
response := &CreateAgreementResp{}
|
response := &CreateAgreementResp{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
|
@ -91,9 +91,9 @@ func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementRes
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteApprovedAgreement - Use this call to execute (complete) a PayPal agreement that has been approved by the payer.
|
// ExecuteApprovedAgreement - Use this call to execute (complete) a PayPal agreement that has been approved by the payer.
|
||||||
// Endpoint: POST /v2/payments/billing-agreements/token/agreement-execute
|
// Endpoint: POST /v1/payments/billing-agreements/token/agreement-execute
|
||||||
func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementResponse, error) {
|
func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementResponse, error) {
|
||||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/billing-agreements/"+token+"/agreement-execute"), nil)
|
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+token+"/agreement-execute"), nil)
|
||||||
response := &ExecuteAgreementResponse{}
|
response := &ExecuteAgreementResponse{}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -115,9 +115,9 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementRespon
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListBillingPlans lists billing-plans
|
// ListBillingPlans lists billing-plans
|
||||||
// Endpoint: GET /v2/payments/billing-plans
|
// Endpoint: GET /v1/payments/billing-plans
|
||||||
func (c *Client) ListBillingPlans(bplp BillingPlanListParams) (*BillingPlanListResp, error) {
|
func (c *Client) ListBillingPlans(bplp BillingPlanListParams) (*BillingPlanListResp, error) {
|
||||||
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/billing-plans"), nil)
|
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), nil)
|
||||||
q := req.URL.Query()
|
q := req.URL.Query()
|
||||||
q.Add("page", bplp.Page)
|
q.Add("page", bplp.Page)
|
||||||
q.Add("page_size", bplp.PageSize)
|
q.Add("page_size", bplp.PageSize)
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// All test values are defined here
|
// All test values are defined here
|
||||||
var testClientID = "AQzSx89isj-yV7BhuN_TY1s4phiQXlcUEwFPUYD7tWFxts-bf2Zf6f_S0K7J_suOkiZuIKSkNnB1rem-"
|
var testClientID = "AXy9orp-CDaHhBZ9C78QHW2BKZpACgroqo85_NIOa9mIfJ9QnSVKzY-X_rivR_fTUUr6aLjcJsj6sDur"
|
||||||
var testSecret = "EAW_tyBnkTLxC7RB8CHT39QYZYfT7LwyxPsWle0834O60KGo0A351iMLOFdQBQ5q95DbZM1hOlT9w8Yg"
|
var testSecret = "EBoIiUSkCKeSk49hHSgTem1qnjzzJgRQHDEHvGpzlLEf_nIoJd91xu8rPOBDCdR_UYNKVxJE-UgS2iCw"
|
||||||
var testUserID = "https://www.paypal.com/webapps/auth/identity/user/VBqgHcgZwb1PBs69ybjjXfIW86_Hr93aBvF_Rgbh2II"
|
var testUserID = "https://www.paypal.com/webapps/auth/identity/user/VBqgHcgZwb1PBs69ybjjXfIW86_Hr93aBvF_Rgbh2II"
|
||||||
var testCardID = "CARD-54E6956910402550WKGRL6EA"
|
var testCardID = "CARD-54E6956910402550WKGRL6EA"
|
||||||
|
|
||||||
|
@ -39,27 +39,25 @@ func TestCreateSinglePayout(t *testing.T) {
|
||||||
|
|
||||||
payout := Payout{
|
payout := Payout{
|
||||||
SenderBatchHeader: &SenderBatchHeader{
|
SenderBatchHeader: &SenderBatchHeader{
|
||||||
EmailSubject: "Subject will be displayed on PayPal",
|
SenderBatchID: "Payouts_2018_100007",
|
||||||
|
EmailSubject: "You have a payout!",
|
||||||
|
EmailMessage: "You have received a payout! Thanks for using our service!",
|
||||||
},
|
},
|
||||||
Items: []PayoutItem{
|
Items: []PayoutItem{
|
||||||
{
|
{
|
||||||
RecipientType: "EMAIL",
|
RecipientType: "EMAIL",
|
||||||
Receiver: "single-email-payout@mail.com",
|
Receiver: "receiver@example.com",
|
||||||
Amount: &AmountPayout{
|
Amount: &AmountPayout{
|
||||||
Value: "15.11",
|
Value: "9.87",
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
},
|
},
|
||||||
Note: "Optional note",
|
Note: "Thanks for your patronage!",
|
||||||
SenderItemID: "Optional Item ID",
|
SenderItemID: "201403140001",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
payoutRes, err := c.CreateSinglePayout(payout)
|
c.CreateSinglePayout(payout)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("test single payout is not created, error: %v, payout: %v", err, payoutRes)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStoreCreditCard(t *testing.T) {
|
func TestStoreCreditCard(t *testing.T) {
|
||||||
|
|
8
sale.go
8
sale.go
|
@ -5,11 +5,11 @@ import "fmt"
|
||||||
// GetSale returns a sale by ID
|
// GetSale returns a sale by ID
|
||||||
// Use this call to get details about a sale transaction.
|
// Use this call to get details about a sale transaction.
|
||||||
// Note: This call returns only the sales that were created via the REST API.
|
// Note: This call returns only the sales that were created via the REST API.
|
||||||
// Endpoint: GET /v2/payments/sale/ID
|
// Endpoint: GET /v1/payments/sale/ID
|
||||||
func (c *Client) GetSale(saleID string) (*Sale, error) {
|
func (c *Client) GetSale(saleID string) (*Sale, error) {
|
||||||
sale := &Sale{}
|
sale := &Sale{}
|
||||||
|
|
||||||
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/sale/"+saleID), nil)
|
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/sale/"+saleID), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sale, err
|
return sale, err
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func (c *Client) GetSale(saleID string) (*Sale, error) {
|
||||||
|
|
||||||
// RefundSale refunds a completed payment.
|
// RefundSale refunds a completed payment.
|
||||||
// Use this call to refund a completed payment. Provide the sale_id in the URI and an empty JSON payload for a full refund. For partial refunds, you can include an amount.
|
// Use this call to refund a completed payment. Provide the sale_id in the URI and an empty JSON payload for a full refund. For partial refunds, you can include an amount.
|
||||||
// Endpoint: POST /v2/payments/sale/ID/refund
|
// Endpoint: POST /v1/payments/sale/ID/refund
|
||||||
func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
|
func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
|
||||||
type refundRequest struct {
|
type refundRequest struct {
|
||||||
Amount *Amount `json:"amount"`
|
Amount *Amount `json:"amount"`
|
||||||
|
@ -31,7 +31,7 @@ func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
|
||||||
|
|
||||||
refund := &Refund{}
|
refund := &Refund{}
|
||||||
|
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/sale/"+saleID+"/refund"), &refundRequest{Amount: a})
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/sale/"+saleID+"/refund"), &refundRequest{Amount: a})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return refund, err
|
return refund, err
|
||||||
}
|
}
|
||||||
|
|
1
types.go
1
types.go
|
@ -823,6 +823,7 @@ type (
|
||||||
// SenderBatchHeader struct
|
// SenderBatchHeader struct
|
||||||
SenderBatchHeader struct {
|
SenderBatchHeader struct {
|
||||||
EmailSubject string `json:"email_subject"`
|
EmailSubject string `json:"email_subject"`
|
||||||
|
EmailMessage string `json:"email_message"`
|
||||||
SenderBatchID string `json:"sender_batch_id,omitempty"`
|
SenderBatchID string `json:"sender_batch_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user