Fix linter issues

This commit is contained in:
Alex Pliutau 2017-10-02 22:30:39 -05:00
parent 1bdb88fd4b
commit 36bba2d583
3 changed files with 115 additions and 114 deletions

View File

@ -1,107 +1,108 @@
package paypalsdk_test package paypalsdk_test
import ( import (
"fmt" "fmt"
pp "github.com/logpacker/PayPal-Go-SDK" "time"
"time"
) pp "github.com/logpacker/PayPal-Go-SDK"
)
func BillingExample() {
plan := pp.BillingPlan{ func BillingExample() {
Name: "Plan with Regular and Trial Payment Definitions", plan := pp.BillingPlan{
Description: "Plan with regular and trial payment definitions.", Name: "Plan with Regular and Trial Payment Definitions",
Type: "fixed", Description: "Plan with regular and trial payment definitions.",
PaymentDefinitions: []pp.PaymentDefinition{ Type: "fixed",
pp.PaymentDefinition{ PaymentDefinitions: []pp.PaymentDefinition{
Name: "Regular payment definition", pp.PaymentDefinition{
Type: "REGULAR", Name: "Regular payment definition",
Frequency: "MONTH", Type: "REGULAR",
FrequencyInterval: "2", Frequency: "MONTH",
Amount: pp.AmountPayout{ FrequencyInterval: "2",
Value: "100", Amount: pp.AmountPayout{
Currency: "USD", Value: "100",
}, Currency: "USD",
Cycles: "12", },
ChargeModels: []pp.ChargeModel{ Cycles: "12",
pp.ChargeModel{ ChargeModels: []pp.ChargeModel{
Type: "SHIPPING", pp.ChargeModel{
Amount: pp.AmountPayout{ Type: "SHIPPING",
Value: "10", Amount: pp.AmountPayout{
Currency: "USD", Value: "10",
}, Currency: "USD",
}, },
pp.ChargeModel{ },
Type: "TAX", pp.ChargeModel{
Amount: pp.AmountPayout{ Type: "TAX",
Value: "12", Amount: pp.AmountPayout{
Currency: "USD", Value: "12",
}, Currency: "USD",
}, },
}, },
}, },
pp.PaymentDefinition{ },
Name: "Trial payment definition", pp.PaymentDefinition{
Type: "trial", Name: "Trial payment definition",
Frequency: "week", Type: "trial",
FrequencyInterval: "5", Frequency: "week",
Amount: pp.AmountPayout{ FrequencyInterval: "5",
Value: "9.19", Amount: pp.AmountPayout{
Currency: "USD", Value: "9.19",
}, Currency: "USD",
Cycles: "2", },
ChargeModels: []pp.ChargeModel{ Cycles: "2",
pp.ChargeModel{ ChargeModels: []pp.ChargeModel{
Type: "SHIPPING", pp.ChargeModel{
Amount: pp.AmountPayout{ Type: "SHIPPING",
Value: "1", Amount: pp.AmountPayout{
Currency: "USD", Value: "1",
}, Currency: "USD",
}, },
pp.ChargeModel{ },
Type: "TAX", pp.ChargeModel{
Amount: pp.AmountPayout{ Type: "TAX",
Value: "2", Amount: pp.AmountPayout{
Currency: "USD", Value: "2",
}, Currency: "USD",
}, },
}, },
}, },
}, },
MerchantPreferences: &pp.MerchantPreferences{ },
SetupFee: &pp.AmountPayout{ MerchantPreferences: &pp.MerchantPreferences{
Value: "1", SetupFee: &pp.AmountPayout{
Currency: "USD", Value: "1",
}, Currency: "USD",
ReturnUrl: "http://www.paypal.com", },
CancelUrl: "http://www.paypal.com/cancel", ReturnURL: "http://www.paypal.com",
AutoBillAmount: "YES", CancelURL: "http://www.paypal.com/cancel",
InitialFailAmountAction: "CONTINUE", AutoBillAmount: "YES",
MaxFailAttempts: "0", InitialFailAmountAction: "CONTINUE",
}, MaxFailAttempts: "0",
} },
c, err := pp.NewClient("clientID", "secretID", pp.APIBaseSandBox) }
if err != nil { c, err := pp.NewClient("clientID", "secretID", pp.APIBaseSandBox)
panic(err) if err != nil {
} panic(err)
_, err = c.GetAccessToken() }
if err != nil { _, err = c.GetAccessToken()
panic(err) if err != nil {
} panic(err)
planResp, err := c.CreateBillingPlan(plan) }
if err != nil { planResp, err := c.CreateBillingPlan(plan)
panic(err) if err != nil {
} panic(err)
err = c.ActivatePlan(planResp.ID) }
fmt.Println(err) err = c.ActivatePlan(planResp.ID)
agreement := pp.BillingAgreement{ fmt.Println(err)
Name: "Fast Speed Agreement", agreement := pp.BillingAgreement{
Description: "Agreement for Fast Speed Plan", Name: "Fast Speed Agreement",
StartDate: pp.JsonTime(time.Now().Add(time.Hour * 24)), Description: "Agreement for Fast Speed Plan",
Plan: pp.BillingPlan{ID: planResp.ID}, StartDate: pp.JSONTime(time.Now().Add(time.Hour * 24)),
Payer: pp.Payer{ Plan: pp.BillingPlan{ID: planResp.ID},
PaymentMethod: "paypal", Payer: pp.Payer{
}, PaymentMethod: "paypal",
} },
resp, err := c.CreateBillingAgreement(agreement) }
fmt.Println(err, resp) resp, err := c.CreateBillingAgreement(agreement)
} fmt.Println(err, resp)
}

View File

@ -58,7 +58,6 @@ func (c *Client) SetHTTPClient(client *http.Client) error {
return nil return nil
} }
// SetAccessToken sets saved token to current client // SetAccessToken sets saved token to current client
func (c *Client) SetAccessToken(token string) error { func (c *Client) SetAccessToken(token string) error {
c.Token = &TokenResponse{ c.Token = &TokenResponse{

View File

@ -44,8 +44,8 @@ const (
) )
type ( type (
// JsonTime overrides MarshalJson method to format in ISO8601 // JSONTime overrides MarshalJson method to format in ISO8601
JsonTime time.Time JSONTime time.Time
// Address struct // Address struct
Address struct { Address struct {
@ -113,7 +113,7 @@ type (
BillingAgreement struct { BillingAgreement struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
StartDate JsonTime `json:"start_date,omitempty"` StartDate JSONTime `json:"start_date,omitempty"`
Plan BillingPlan `json:"plan,omitempty"` Plan BillingPlan `json:"plan,omitempty"`
Payer Payer `json:"payer,omitempty"` Payer Payer `json:"payer,omitempty"`
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
@ -287,8 +287,8 @@ type (
// MerchantPreferences struct // MerchantPreferences struct
MerchantPreferences struct { MerchantPreferences struct {
SetupFee *AmountPayout `json:"setup_fee,omitempty"` SetupFee *AmountPayout `json:"setup_fee,omitempty"`
ReturnUrl string `json:"return_url,omitempty"` ReturnURL string `json:"return_url,omitempty"`
CancelUrl string `json:"cancel_url,omitempty"` CancelURL string `json:"cancel_url,omitempty"`
AutoBillAmount string `json:"auto_bill_amount,omitempty"` AutoBillAmount string `json:"auto_bill_amount,omitempty"`
InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"` InitialFailAmountAction string `json:"initial_fail_amount_action,omitempty"`
MaxFailAttempts string `json:"max_fail_attempts,omitempty"` MaxFailAttempts string `json:"max_fail_attempts,omitempty"`
@ -539,7 +539,8 @@ 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) 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) { // MarshalJSON for JSONTime
func (t JSONTime) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339)) stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
return []byte(stamp), nil return []byte(stamp), nil
} }