Merge pull request #75 from meitarim/master

added ListBillingPlans
This commit is contained in:
Alex Pliutau 2019-01-14 10:17:11 +01:00 committed by GitHub
commit 7a8d9e5531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -28,6 +28,23 @@ type (
Links []Link `json:"links,omitempty"`
StartTime time.Time `json:"start_time,omitempty"`
}
// BillingPlanListParams struct
BillingPlanListParams struct {
Page string `json:"page,omitempty"` //Default: 0.
Status string `json:"status,omitempty"` //Allowed values: CREATED, ACTIVE, INACTIVE, ALL.
PageSize string `json:"page_size,omitempty"` //Default: 10.
TotalRequired string `json:"total_required,omitempty"` //Default: no.
}
//BillingPlanListResp struct
BillingPlanListResp struct {
Plans []BillingPlan `json:"plans,omitempty"`
TotalItems string `json:"total_items,omitempty"`
TotalPages string `json:"total_pages,omitempty"`
Links []Link `json:"links,omitempty"`
}
)
// CreateBillingPlan creates a billing plan in Paypal
@ -96,3 +113,21 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementRespon
return &e, err
}
// ListBillingPlans lists billing-plans
// Endpoint: GET /v1/payments/billing-plans
func (c *Client) ListBillingPlans(bplp BillingPlanListParams) (*BillingPlanListResp, error) {
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), nil)
q := req.URL.Query()
q.Add("page", bplp.Page)
q.Add("page_size", bplp.PageSize)
q.Add("status", bplp.Status)
q.Add("total_required", bplp.TotalRequired)
req.URL.RawQuery = q.Encode()
response := &BillingPlanListResp{}
if err != nil {
return response, err
}
err = c.SendWithAuth(req, response)
return response, err
}

View File

@ -105,4 +105,7 @@ func BillingExample() {
}
resp, err := c.CreateBillingAgreement(agreement)
fmt.Println(err, resp)
bps, err := c.ListBillingPlans(pp.BillingPlanListParams{Status: "ACTIVE"})
fmt.Println(err, bps)
}