mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
fixes
This commit is contained in:
parent
7c9329fbd6
commit
ee955a5826
|
@ -44,6 +44,8 @@
|
|||
* POST /v1/payments/billing-agreements
|
||||
* POST /v1/payments/billing-agreements/**TOKEN**/agreement-execute
|
||||
* POST /v1/payments/billing-agreements/**ID**/cancel
|
||||
* POST /v1/payments/billing-agreements/**ID**/re-activate
|
||||
* POST /v1/payments/billing-agreements/**ID**/suspend
|
||||
|
||||
### 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**
|
||||
|
|
55
billing.go
55
billing.go
|
@ -16,20 +16,17 @@ func (c *Client) ActivatePlan(planID string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.SetBasicAuth(c.ClientID, c.Secret)
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
return c.SendWithAuth(req, nil)
|
||||
}
|
||||
|
||||
// CancelAgreement cancels a billing agreement.
|
||||
// Endpoint: POST /v1/payments/billing-agreements/{agreement_id}/cancel
|
||||
func (c *Client) CancelAgreement(agreementID string) error {
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+agreementID+"/cancel"), nil)
|
||||
buf := bytes.NewBuffer([]byte(`{"note": "Canceling the profile."}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+agreementID+"/cancel"), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.SetBasicAuth(c.ClientID, c.Secret)
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
|
||||
err = c.SendWithAuth(req, nil)
|
||||
|
||||
|
@ -79,8 +76,6 @@ func (c *Client) DeletePlan(planID string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.SetBasicAuth(c.ClientID, c.Secret)
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
return c.SendWithAuth(req, nil)
|
||||
}
|
||||
|
||||
|
@ -92,9 +87,6 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*BillingAgreement, erro
|
|||
return &BillingAgreement{}, err
|
||||
}
|
||||
|
||||
req.SetBasicAuth(c.ClientID, c.Secret)
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
|
||||
e := BillingAgreement{}
|
||||
|
||||
if err = c.SendWithAuth(req, &e); err != nil {
|
||||
|
@ -123,9 +115,6 @@ func (c *Client) ListBillingPlans(status interface{}, page interface{}) (*ListBi
|
|||
return &ListBillingPlansResp{}, err
|
||||
}
|
||||
|
||||
req.SetBasicAuth(c.ClientID, c.Secret)
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
|
||||
l := ListBillingPlansResp{}
|
||||
|
||||
err = c.SendWithAuth(req, &l)
|
||||
|
@ -138,3 +127,43 @@ func (c *Client) ListBillingPlans(status interface{}, page interface{}) (*ListBi
|
|||
|
||||
return &l, err
|
||||
}
|
||||
|
||||
// ReactivateAgreement reactivates a suspended billing agreement.
|
||||
// Endpoint: POST /v1/payments/billing-agreements/{agreement_id}/re-activate
|
||||
func (c *Client) ReactivateAgreement(agreementID string) error {
|
||||
buf := bytes.NewBuffer([]byte(`{"note": "Reactivating the profile."}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+agreementID+"/re-activate"), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.SendWithAuth(req, nil)
|
||||
|
||||
// A successful request returns the HTTP 204 No Content status code with no JSON response body.
|
||||
// This raises error "EOF"
|
||||
if err != nil && err.Error() == "EOF" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SuspendAgreement suspends a billing agreement.
|
||||
// Endpoint: POST /v1/payments/billing-agreements/{agreement_id}/suspend
|
||||
func (c *Client) SuspendAgreement(agreementID string) error {
|
||||
buf := bytes.NewBuffer([]byte(`{"note": "Suspending the profile."}`))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+agreementID+"/suspend"), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.SendWithAuth(req, nil)
|
||||
|
||||
// A successful request returns the HTTP 204 No Content status code with no JSON response body.
|
||||
// This raises error "EOF"
|
||||
if err != nil && err.Error() == "EOF" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user