From e033a62fe2f8c9281e7e2c031ef28100b7b002be Mon Sep 17 00:00:00 2001 From: envy124 Date: Sat, 22 Jul 2017 14:53:27 +0300 Subject: [PATCH] CreateBillingPlan definition --- billing.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/billing.go b/billing.go index b6a9a32..3442f3d 100644 --- a/billing.go +++ b/billing.go @@ -1,3 +1,37 @@ package paypalsdk -import () +import ( + "fmt" + "time" +) + +type ( + // CreateBillingResp struct + CreateBillingResp struct { + ID string `json:"id,omitempty"` + State string `json:"state,omitempty"` + PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"` + MerchantPreferences MerchantPreferences `json:"merchant_preferences,omitempty"` + CreateTime time.Time `json:"create_time,omitempty"` + UpdateTime time.Time `json:"update_time,omitempty"` + Links []Link `json:"links,omitempty"` + } +) + +// CreateBillingPlan creates a billing plan in Paypal +// Endpoint: POST /v1/payments/billing-plans +func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) { + req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan) + if err != nil { + return &CreateBillingResp{}, err + } + + response := &CreateBillingResp{} + + err = c.SendWithAuth(req, response) + if err != nil { + return response, err + } + + return response, nil +}