From 838828c0201f11d136aff7fed70c990a9077ccc4 Mon Sep 17 00:00:00 2001 From: imikod Date: Mon, 26 Mar 2018 14:48:13 +0300 Subject: [PATCH] merge structs --- billing.go | 30 +++++------------------------- types.go | 37 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 44 deletions(-) diff --git a/billing.go b/billing.go index cc5a6c3..367c75a 100644 --- a/billing.go +++ b/billing.go @@ -8,26 +8,6 @@ import ( "time" ) -type ( - // CreateAgreementResp struct - CreateAgreementResp struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Plan BillingPlan `json:"plan,omitempty"` - Links []Link `json:"links,omitempty"` - StartTime time.Time `json:"start_time,omitempty"` - } - - // ListBillingPlansResp struct - ListBillingPlansResp struct { - TotalItems string `json:"total_items,omitempty"` - TotalPages string `json:"total_pages,omitempty"` - Plans []BillingPlan `json:"plans,omitempty"` - Links []Link `json:"links,omitempty"` - } -) - // ActivatePlan activates a billing plan. // By default, a new plan is not activated. // Endpoint: PATCH /v1/payments/billing-plans/ @@ -77,14 +57,14 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*BillingPlan, error) { // CreateBillingAgreement creates an agreement for specified plan. // Endpoint: POST /v1/payments/billing-agreements -func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementResp, error) { +func (c *Client) CreateBillingAgreement(a BillingAgreement) (*BillingAgreement, error) { // PayPal needs only ID, so we will remove all fields except Plan ID a.Plan = BillingPlan{ ID: a.Plan.ID, } req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements"), a) - response := &CreateAgreementResp{} + response := &BillingAgreement{} if err != nil { return response, err } @@ -107,16 +87,16 @@ func (c *Client) DeletePlan(planID string) error { // ExecuteApprovedAgreement - Use this call to execute (complete) a PayPal agreement that has been approved by the payer. // Endpoint: POST /v1/payments/billing-agreements/token/agreement-execute -func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementResponse, error) { +func (c *Client) ExecuteApprovedAgreement(token string) (*BillingAgreement, error) { req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements/"+token+"/agreement-execute"), nil) if err != nil { - return &ExecuteAgreementResponse{}, err + return &BillingAgreement{}, err } req.SetBasicAuth(c.ClientID, c.Secret) req.Header.Set("Authorization", "Bearer "+c.Token.Token) - e := ExecuteAgreementResponse{} + e := BillingAgreement{} if err = c.SendWithAuth(req, &e); err != nil { return &e, err diff --git a/types.go b/types.go index b9dc8c2..74316a6 100644 --- a/types.go +++ b/types.go @@ -121,12 +121,16 @@ type ( // BillingAgreement struct BillingAgreement struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - StartDate JSONTime `json:"start_date,omitempty"` - Plan BillingPlan `json:"plan,omitempty"` - Payer Payer `json:"payer,omitempty"` - ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + StartDate JSONTime `json:"start_date,omitempty"` + Plan BillingPlan `json:"plan,omitempty"` + Payer Payer `json:"payer,omitempty"` + ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` + State string `json:"state,omitempty"` + AgreementDetails AgreementDetails `json:"agreement_details"` + Links []Link `json:"links"` } // BillingPlan struct @@ -252,19 +256,6 @@ type ( Details []ErrorResponseDetail `json:"details"` } - // ExecuteAgreementResponse struct - ExecuteAgreementResponse struct { - ID string `json:"id"` - State string `json:"state"` - Description string `json:"description,omitempty"` - Payer Payer `json:"payer"` - Plan BillingPlan `json:"plan"` - StartDate time.Time `json:"start_date"` - ShippingAddress ShippingAddress `json:"shipping_address"` - AgreementDetails AgreementDetails `json:"agreement_details"` - Links []Link `json:"links"` - } - // ExecuteResponse struct ExecuteResponse struct { ID string `json:"id"` @@ -305,6 +296,14 @@ type ( Enctype string `json:"enctype,omitempty"` } + // ListBillingPlansResp struct + ListBillingPlansResp struct { + TotalItems string `json:"total_items,omitempty"` + TotalPages string `json:"total_pages,omitempty"` + Plans []BillingPlan `json:"plans,omitempty"` + Links []Link `json:"links,omitempty"` + } + // MerchantPreferences struct MerchantPreferences struct { SetupFee *AmountPayout `json:"setup_fee,omitempty"`