From cd4c6831c7d8fa24c5338cf762c08cef9349e938 Mon Sep 17 00:00:00 2001 From: envy124 Date: Thu, 20 Jul 2017 12:07:11 +0300 Subject: [PATCH 01/11] billing structures --- billing.go | 3 + billing_test.go | 164 ++++++++++++++++++++++++++++++++++++++++++++++++ types.go | 48 ++++++++++++-- 3 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 billing.go create mode 100644 billing_test.go diff --git a/billing.go b/billing.go new file mode 100644 index 0000000..b6a9a32 --- /dev/null +++ b/billing.go @@ -0,0 +1,3 @@ +package paypalsdk + +import () diff --git a/billing_test.go b/billing_test.go new file mode 100644 index 0000000..d8e75dc --- /dev/null +++ b/billing_test.go @@ -0,0 +1,164 @@ +package paypalsdk + +import ( + "encoding/json" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestJsonStructure(t *testing.T) { + expected_str := `{ + "name": "Plan with Regular and Trial Payment Definitions", + "description": "Plan with regular and trial payment definitions.", + "type": "fixed", + "payment_definitions": [ + { + "name": "Regular payment definition", + "type": "REGULAR", + "frequency": "MONTH", + "frequency_interval": "2", + "amount": + { + "value": "100", + "currency": "USD" + }, + "cycles": "12", + "charge_models": [ + { + "type": "SHIPPING", + "amount": + { + "value": "10", + "currency": "USD" + } + }, + { + "type": "TAX", + "amount": + { + "value": "12", + "currency": "USD" + } + }] + }, + { + "name": "Trial payment definition", + "type": "trial", + "frequency": "week", + "frequency_interval": "5", + "amount": + { + "value": "9.19", + "currency": "USD" + }, + "cycles": "2", + "charge_models": [ + { + "type": "SHIPPING", + "amount": + { + "value": "1", + "currency": "USD" + } + }, + { + "type": "TAX", + "amount": + { + "value": "2", + "currency": "USD" + } + }] + }], + "merchant_preferences": + { + "setup_fee": + { + "value": "1", + "currency": "USD" + }, + "return_url": "http://www.paypal.com", + "cancel_url": "http://www.paypal.com/cancel", + "auto_bill_amount": "YES", + "initial_fail_amount_action": "CONTINUE", + "max_fail_attempts": "0" + } +}` + plan := BillingPlan{ + Name: "Plan with Regular and Trial Payment Definitions", + Description: "Plan with regular and trial payment definitions.", + Type: "fixed", + PaymentDefinitions: []PaymentDefinition{ + PaymentDefinition{ + Name: "Regular payment definition", + Type: "REGULAR", + Frequency: "MONTH", + FrequencyInterval: "2", + Amount: AmountPayout{ + Value: "100", + Currency: "USD", + }, + Cycles: "12", + ChargeModels: []ChargeModel{ + ChargeModel{ + Type: "SHIPPING", + Amount: AmountPayout{ + Value: "10", + Currency: "USD", + }, + }, + ChargeModel{ + Type: "TAX", + Amount: AmountPayout{ + Value: "12", + Currency: "USD", + }, + }, + }, + }, + PaymentDefinition{ + Name: "Trial payment definition", + Type: "trial", + Frequency: "week", + FrequencyInterval: "5", + Amount: AmountPayout{ + Value: "9.19", + Currency: "USD", + }, + Cycles: "2", + ChargeModels: []ChargeModel{ + ChargeModel{ + Type: "SHIPPING", + Amount: AmountPayout{ + Value: "1", + Currency: "USD", + }, + }, + ChargeModel{ + Type: "TAX", + Amount: AmountPayout{ + Value: "2", + Currency: "USD", + }, + }, + }, + }, + }, + MerchantPreferences: MerchantPreferences{ + SetupFee: AmountPayout{ + Value: "1", + Currency: "USD", + }, + ReturnUrl: "http://www.paypal.com", + CancelUrl: "http://www.paypal.com/cancel", + AutoBillAmount: "YES", + InitialFailAmountAction: "CONTINUE", + MaxFailAttempts: "0", + }, + } + _, err := json.Marshal(&plan) + expected := new(BillingPlan) + json.Unmarshal([]byte(expected_str), expected) + assert.NoError(t, err) + assert.Equal(t, expected, &plan, "Wrong billing builder") +} diff --git a/types.go b/types.go index 074a46f..1860cfa 100644 --- a/types.go +++ b/types.go @@ -93,6 +93,15 @@ type ( SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"` } + // BillingPlan struct + BillingPlan struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"` + MerchantPreferences MerchantPreferences `json:"merchant_preferences,omitempty"` + } + // Capture struct Capture struct { Amount *Amount `json:"amount,omitempty"` @@ -105,14 +114,20 @@ type ( Links []Link `json:"links,omitempty"` } + // ChargeModel struct + ChargeModel struct { + Type string `json:"type,omitempty"` + Amount AmountPayout `json:"amount,omitempty"` + } + // Client represents a Paypal REST API Client Client struct { - Client *http.Client - ClientID string - Secret string - APIBase string - Log io.Writer // If user set log file name all requests will be logged there - Token *TokenResponse + Client *http.Client + ClientID string + Secret string + APIBase string + Log io.Writer // If user set log file name all requests will be logged there + Token *TokenResponse tokenExpiresAt time.Time } @@ -218,6 +233,16 @@ type ( Enctype string `json:"enctype,omitempty"` } + // MerchantPreferences struct + MerchantPreferences struct { + SetupFee AmountPayout `json:"setup_fee,omitempty"` + ReturnUrl string `json:"return_url,omitempty"` + CancelUrl string `json:"cancel_url,omitempty"` + AutoBillAmount string `json:"auto_bill_amount,omitempty"` + InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"` + MaxFailAttempts string `json:"max_fail_attempts,omitempty"` + } + // Order struct Order struct { ID string `json:"id,omitempty"` @@ -263,6 +288,17 @@ type ( ExperienceProfileID string `json:"experience_profile_id,omitempty"` } + // PaymentDefinition struct + PaymentDefinition struct { + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` + Frequency string `json:"frequency,omitempty"` + FrequencyInterval string `json:"frequency_interval,omitempty"` + Amount AmountPayout `json:"amount,omitempty"` + Cycles string `json:"cycles,omitempty"` + ChargeModels []ChargeModel `json:"charge_models,omitempty"` + } + // PaymentResponse structure PaymentResponse struct { ID string `json:"id"` From f12db629955bc0d07bcb72d765cb99b08b8cc8ab Mon Sep 17 00:00:00 2001 From: envy124 Date: Sat, 22 Jul 2017 14:48:16 +0300 Subject: [PATCH 02/11] PaymentDefinition add ID field --- types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/types.go b/types.go index 1860cfa..e0e8edc 100644 --- a/types.go +++ b/types.go @@ -290,6 +290,7 @@ type ( // PaymentDefinition struct PaymentDefinition struct { + ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` Frequency string `json:"frequency,omitempty"` From e033a62fe2f8c9281e7e2c031ef28100b7b002be Mon Sep 17 00:00:00 2001 From: envy124 Date: Sat, 22 Jul 2017 14:53:27 +0300 Subject: [PATCH 03/11] 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 +} From 77c97c88240a055650576466bcb2d6681a97ada2 Mon Sep 17 00:00:00 2001 From: envy124 Date: Sat, 22 Jul 2017 15:54:57 +0300 Subject: [PATCH 04/11] ActivatePlan definition --- billing.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/billing.go b/billing.go index 3442f3d..4798f9d 100644 --- a/billing.go +++ b/billing.go @@ -1,7 +1,9 @@ package paypalsdk import ( + "bytes" "fmt" + "net/http" "time" ) @@ -35,3 +37,17 @@ func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) return response, nil } + +// Activates a billing plan +// By default, a new plan is not activated +// Endpoint: PATCH /v1/payments/billing-plans/ +func (c *Client) ActivatePlan(planID string) error { + buf := bytes.NewBuffer([]byte("[{\"op\":\"replace\",\"path\":\"/\",\"value\":{\"state\":\"ACTIVE\"}}]")) + req, err := http.NewRequest("PATCH", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans/"+planID), buf) + if err != nil { + return err + } + req.SetBasicAuth(c.ClientID, c.Secret) + req.Header.Set("Authorization", "Bearer "+c.Token.Token) + return c.SendWithAuth(req, nil) +} From 1f84980013ca33fa8e70b988868d015a21c8c809 Mon Sep 17 00:00:00 2001 From: envy124 Date: Sun, 23 Jul 2017 08:47:17 +0300 Subject: [PATCH 05/11] BillingAgreement definition --- billing.go | 31 +++++++++++++++++++++++-------- types.go | 29 ++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/billing.go b/billing.go index 4798f9d..052050c 100644 --- a/billing.go +++ b/billing.go @@ -18,24 +18,27 @@ type ( UpdateTime time.Time `json:"update_time,omitempty"` Links []Link `json:"links,omitempty"` } + + // CreateAgreementResp struct + CreateAgreementResp struct { + 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"` + } ) // 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 + err = c.SendWithAuth(req, response) + return response, err } // Activates a billing plan @@ -51,3 +54,15 @@ func (c *Client) ActivatePlan(planID string) error { req.Header.Set("Authorization", "Bearer "+c.Token.Token) return c.SendWithAuth(req, nil) } + +// Creates an agreement for specified plan +// Endpoint: POST /v1/payments/billing-agreements +func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementResp, error) { + req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements"), a) + response := &CreateAgreementResp{} + if err != nil { + return response, err + } + err = c.SendWithAuth(req, response) + return response, err +} diff --git a/types.go b/types.go index e0e8edc..70b97bb 100644 --- a/types.go +++ b/types.go @@ -44,6 +44,9 @@ const ( ) type ( + // JsonTime overrides MarshalJson method to format in ISO8601 + JsonTime time.Time + // Address struct Address struct { Line1 string `json:"line1"` @@ -93,13 +96,24 @@ type ( SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"` } + // 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"` + } + // BillingPlan struct BillingPlan struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Type string `json:"type,omitempty"` - PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"` - MerchantPreferences MerchantPreferences `json:"merchant_preferences,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"` + MerchantPreferences *MerchantPreferences `json:"merchant_preferences,omitempty"` } // Capture struct @@ -486,3 +500,8 @@ type ( func (r *ErrorResponse) Error() string { return fmt.Sprintf("%v %v: %d %s", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message) } + +func (t JsonTime) MarshalJSON() ([]byte, error) { + stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339)) + return []byte(stamp), nil +} From 3f9821784c0cbed445d10ee357dfc1f6c77e0a56 Mon Sep 17 00:00:00 2001 From: envy124 Date: Thu, 27 Jul 2017 17:46:02 +0300 Subject: [PATCH 06/11] example billing test --- billing_test.go | 153 +++++++++++++++--------------------------------- 1 file changed, 48 insertions(+), 105 deletions(-) diff --git a/billing_test.go b/billing_test.go index d8e75dc..2557bd5 100644 --- a/billing_test.go +++ b/billing_test.go @@ -1,142 +1,65 @@ -package paypalsdk +package paypalsdk_test import ( - "encoding/json" - "github.com/stretchr/testify/assert" - "testing" + "fmt" + pp "github.com/logpacker/PayPal-Go-SDK" + "time" ) -func TestJsonStructure(t *testing.T) { - expected_str := `{ - "name": "Plan with Regular and Trial Payment Definitions", - "description": "Plan with regular and trial payment definitions.", - "type": "fixed", - "payment_definitions": [ - { - "name": "Regular payment definition", - "type": "REGULAR", - "frequency": "MONTH", - "frequency_interval": "2", - "amount": - { - "value": "100", - "currency": "USD" - }, - "cycles": "12", - "charge_models": [ - { - "type": "SHIPPING", - "amount": - { - "value": "10", - "currency": "USD" - } - }, - { - "type": "TAX", - "amount": - { - "value": "12", - "currency": "USD" - } - }] - }, - { - "name": "Trial payment definition", - "type": "trial", - "frequency": "week", - "frequency_interval": "5", - "amount": - { - "value": "9.19", - "currency": "USD" - }, - "cycles": "2", - "charge_models": [ - { - "type": "SHIPPING", - "amount": - { - "value": "1", - "currency": "USD" - } - }, - { - "type": "TAX", - "amount": - { - "value": "2", - "currency": "USD" - } - }] - }], - "merchant_preferences": - { - "setup_fee": - { - "value": "1", - "currency": "USD" - }, - "return_url": "http://www.paypal.com", - "cancel_url": "http://www.paypal.com/cancel", - "auto_bill_amount": "YES", - "initial_fail_amount_action": "CONTINUE", - "max_fail_attempts": "0" - } -}` - plan := BillingPlan{ +func Example() { + plan := pp.BillingPlan{ Name: "Plan with Regular and Trial Payment Definitions", Description: "Plan with regular and trial payment definitions.", Type: "fixed", - PaymentDefinitions: []PaymentDefinition{ - PaymentDefinition{ + PaymentDefinitions: []pp.PaymentDefinition{ + pp.PaymentDefinition{ Name: "Regular payment definition", Type: "REGULAR", Frequency: "MONTH", FrequencyInterval: "2", - Amount: AmountPayout{ + Amount: pp.AmountPayout{ Value: "100", Currency: "USD", }, Cycles: "12", - ChargeModels: []ChargeModel{ - ChargeModel{ + ChargeModels: []pp.ChargeModel{ + pp.ChargeModel{ Type: "SHIPPING", - Amount: AmountPayout{ + Amount: pp.AmountPayout{ Value: "10", Currency: "USD", }, }, - ChargeModel{ + pp.ChargeModel{ Type: "TAX", - Amount: AmountPayout{ + Amount: pp.AmountPayout{ Value: "12", Currency: "USD", }, }, }, }, - PaymentDefinition{ + pp.PaymentDefinition{ Name: "Trial payment definition", Type: "trial", Frequency: "week", FrequencyInterval: "5", - Amount: AmountPayout{ + Amount: pp.AmountPayout{ Value: "9.19", Currency: "USD", }, Cycles: "2", - ChargeModels: []ChargeModel{ - ChargeModel{ + ChargeModels: []pp.ChargeModel{ + pp.ChargeModel{ Type: "SHIPPING", - Amount: AmountPayout{ + Amount: pp.AmountPayout{ Value: "1", Currency: "USD", }, }, - ChargeModel{ + pp.ChargeModel{ Type: "TAX", - Amount: AmountPayout{ + Amount: pp.AmountPayout{ Value: "2", Currency: "USD", }, @@ -144,8 +67,8 @@ func TestJsonStructure(t *testing.T) { }, }, }, - MerchantPreferences: MerchantPreferences{ - SetupFee: AmountPayout{ + MerchantPreferences: &pp.MerchantPreferences{ + SetupFee: pp.AmountPayout{ Value: "1", Currency: "USD", }, @@ -156,9 +79,29 @@ func TestJsonStructure(t *testing.T) { MaxFailAttempts: "0", }, } - _, err := json.Marshal(&plan) - expected := new(BillingPlan) - json.Unmarshal([]byte(expected_str), expected) - assert.NoError(t, err) - assert.Equal(t, expected, &plan, "Wrong billing builder") + c, err := pp.NewClient("clientID", "secretID", pp.APIBaseSandBox) + if err != nil { + panic(err) + } + _, err = c.GetAccessToken() + if err != nil { + panic(err) + } + planResp, err := c.CreateBillingPlan(plan) + if err != nil { + panic(err) + } + err = c.ActivatePlan(planResp.ID) + fmt.Println(err) + agreement := pp.BillingAgreement{ + Name: "Fast Speed Agreement", + Description: "Agreement for Fast Speed Plan", + StartDate: pp.JsonTime(time.Now().Add(time.Hour * 24)), + Plan: pp.BillingPlan{ID: planResp.ID}, + Payer: pp.Payer{ + PaymentMethod: "paypal", + }, + } + resp, err := c.CreateBillingAgreement(agreement) + fmt.Println(err, resp) } From d4da804af2035959b96f478da64f2a48e350df60 Mon Sep 17 00:00:00 2001 From: envy124 Date: Thu, 24 Aug 2017 09:08:31 +0300 Subject: [PATCH 07/11] MerchantPreferences.SetupFee omitempty --- types.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types.go b/types.go index 70b97bb..16cff3d 100644 --- a/types.go +++ b/types.go @@ -249,12 +249,12 @@ type ( // MerchantPreferences struct MerchantPreferences struct { - SetupFee AmountPayout `json:"setup_fee,omitempty"` - ReturnUrl string `json:"return_url,omitempty"` - CancelUrl string `json:"cancel_url,omitempty"` - AutoBillAmount string `json:"auto_bill_amount,omitempty"` - InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"` - MaxFailAttempts string `json:"max_fail_attempts,omitempty"` + SetupFee *AmountPayout `json:"setup_fee,omitempty"` + ReturnUrl string `json:"return_url,omitempty"` + CancelUrl string `json:"cancel_url,omitempty"` + AutoBillAmount string `json:"auto_bill_amount,omitempty"` + InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"` + MaxFailAttempts string `json:"max_fail_attempts,omitempty"` } // Order struct From ce8c1014ec493153e579e33038b3c7749f235b61 Mon Sep 17 00:00:00 2001 From: envy124 Date: Thu, 24 Aug 2017 13:22:46 +0300 Subject: [PATCH 08/11] ExecuteApprovedAgreement added --- billing.go | 25 +++++++++++++++++++++++++ types.go | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/billing.go b/billing.go index 052050c..18a18cb 100644 --- a/billing.go +++ b/billing.go @@ -2,6 +2,7 @@ package paypalsdk import ( "bytes" + "errors" "fmt" "net/http" "time" @@ -66,3 +67,27 @@ func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementRes err = c.SendWithAuth(req, response) return response, err } + +// 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) { + 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 + } + + req.SetBasicAuth(c.ClientID, c.Secret) + req.Header.Set("Authorization", "Bearer "+c.Token.Token) + + e := ExecuteAgreementResponse{} + err = c.SendWithAuth(req, &e) + if err != nil { + return &e, err + } + + if e.ID == "" { + return &e, errors.New("Unable to execute agreement with token=" + token) + } + + return &e, err +} diff --git a/types.go b/types.go index 16cff3d..9a76801 100644 --- a/types.go +++ b/types.go @@ -58,6 +58,18 @@ type ( Phone string `json:"phone,omitempty"` } + // AgreementDetails struct + AgreementDetails struct { + OutstandingBalance AmountPayout `json:"outstanding_balance"` + CyclesRemaining int `json:"cycles_remaining"` + CyclesCompleted int `json:"cycles_completed"` + NextBillingDate time.Time `json:"next_billing_date"` + LastPaymentDate time.Time `json:"last_payment_date"` + LastPaymentAmount AmountPayout `json:"last_payment_amount"` + FinalPaymentDate time.Time `json:"final_payment_date"` + FailedPaymentCount int `json:"failed_payment_count"` + } + // Amount struct Amount struct { Currency string `json:"currency"` @@ -208,6 +220,19 @@ type ( Details string `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"` From 08b9849c2056c0caf39e661572c4440d669b37fa Mon Sep 17 00:00:00 2001 From: envy124 Date: Thu, 24 Aug 2017 17:43:41 +0300 Subject: [PATCH 09/11] BillingExample name config fixed --- billing_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/billing_test.go b/billing_test.go index 2557bd5..6fb1f9b 100644 --- a/billing_test.go +++ b/billing_test.go @@ -6,7 +6,7 @@ import ( "time" ) -func Example() { +func BillingExample() { plan := pp.BillingPlan{ Name: "Plan with Regular and Trial Payment Definitions", Description: "Plan with regular and trial payment definitions.", @@ -68,7 +68,7 @@ func Example() { }, }, MerchantPreferences: &pp.MerchantPreferences{ - SetupFee: pp.AmountPayout{ + SetupFee: &pp.AmountPayout{ Value: "1", Currency: "USD", }, From f788a0929c46f58e3aed15d0fd9176ca17db8603 Mon Sep 17 00:00:00 2001 From: envy124 Date: Thu, 24 Aug 2017 18:03:34 +0300 Subject: [PATCH 10/11] int in str unmarshall fixed --- types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types.go b/types.go index 9a76801..cbaa1c4 100644 --- a/types.go +++ b/types.go @@ -61,13 +61,13 @@ type ( // AgreementDetails struct AgreementDetails struct { OutstandingBalance AmountPayout `json:"outstanding_balance"` - CyclesRemaining int `json:"cycles_remaining"` - CyclesCompleted int `json:"cycles_completed"` + CyclesRemaining int `json:"cycles_remaining,string"` + CyclesCompleted int `json:"cycles_completed,string"` NextBillingDate time.Time `json:"next_billing_date"` LastPaymentDate time.Time `json:"last_payment_date"` LastPaymentAmount AmountPayout `json:"last_payment_amount"` FinalPaymentDate time.Time `json:"final_payment_date"` - FailedPaymentCount int `json:"failed_payment_count"` + FailedPaymentCount int `json:"failed_payment_count,string"` } // Amount struct From 87b4c45133be0671a36e069acef74007f40b3f94 Mon Sep 17 00:00:00 2001 From: envy124 Date: Wed, 6 Sep 2017 11:15:21 +0300 Subject: [PATCH 11/11] billing endpoints --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 12692f3..65978f9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ * PATCH /v1/vault/credit-cards/**ID** * GET /v1/vault/credit-cards/**ID** * GET /v1/vault/credit-cards + * POST /v1/payments/billing-plans + * PATCH /v1/payments/billing-plans/***ID*** + * POST /v1/payments/billing-agreements + * POST /v1/payments/billing-agreements/***TOKEN***/agreement-execute ### 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**