forked from go-packages/paypal
Merge pull request #39 from logpacker/bugfix/go_linting
Fix linter issues
This commit is contained in:
commit
9e9173db8d
215
billing_test.go
215
billing_test.go
|
@ -1,107 +1,108 @@
|
|||
package paypalsdk_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
pp "github.com/logpacker/PayPal-Go-SDK"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BillingExample() {
|
||||
plan := pp.BillingPlan{
|
||||
Name: "Plan with Regular and Trial Payment Definitions",
|
||||
Description: "Plan with regular and trial payment definitions.",
|
||||
Type: "fixed",
|
||||
PaymentDefinitions: []pp.PaymentDefinition{
|
||||
pp.PaymentDefinition{
|
||||
Name: "Regular payment definition",
|
||||
Type: "REGULAR",
|
||||
Frequency: "MONTH",
|
||||
FrequencyInterval: "2",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "100",
|
||||
Currency: "USD",
|
||||
},
|
||||
Cycles: "12",
|
||||
ChargeModels: []pp.ChargeModel{
|
||||
pp.ChargeModel{
|
||||
Type: "SHIPPING",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "10",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
pp.ChargeModel{
|
||||
Type: "TAX",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "12",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pp.PaymentDefinition{
|
||||
Name: "Trial payment definition",
|
||||
Type: "trial",
|
||||
Frequency: "week",
|
||||
FrequencyInterval: "5",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "9.19",
|
||||
Currency: "USD",
|
||||
},
|
||||
Cycles: "2",
|
||||
ChargeModels: []pp.ChargeModel{
|
||||
pp.ChargeModel{
|
||||
Type: "SHIPPING",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "1",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
pp.ChargeModel{
|
||||
Type: "TAX",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "2",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
MerchantPreferences: &pp.MerchantPreferences{
|
||||
SetupFee: &pp.AmountPayout{
|
||||
Value: "1",
|
||||
Currency: "USD",
|
||||
},
|
||||
ReturnUrl: "http://www.paypal.com",
|
||||
CancelUrl: "http://www.paypal.com/cancel",
|
||||
AutoBillAmount: "YES",
|
||||
InitialFailAmountAction: "CONTINUE",
|
||||
MaxFailAttempts: "0",
|
||||
},
|
||||
}
|
||||
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)
|
||||
}
|
||||
package paypalsdk_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
pp "github.com/logpacker/PayPal-Go-SDK"
|
||||
)
|
||||
|
||||
func BillingExample() {
|
||||
plan := pp.BillingPlan{
|
||||
Name: "Plan with Regular and Trial Payment Definitions",
|
||||
Description: "Plan with regular and trial payment definitions.",
|
||||
Type: "fixed",
|
||||
PaymentDefinitions: []pp.PaymentDefinition{
|
||||
pp.PaymentDefinition{
|
||||
Name: "Regular payment definition",
|
||||
Type: "REGULAR",
|
||||
Frequency: "MONTH",
|
||||
FrequencyInterval: "2",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "100",
|
||||
Currency: "USD",
|
||||
},
|
||||
Cycles: "12",
|
||||
ChargeModels: []pp.ChargeModel{
|
||||
pp.ChargeModel{
|
||||
Type: "SHIPPING",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "10",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
pp.ChargeModel{
|
||||
Type: "TAX",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "12",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pp.PaymentDefinition{
|
||||
Name: "Trial payment definition",
|
||||
Type: "trial",
|
||||
Frequency: "week",
|
||||
FrequencyInterval: "5",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "9.19",
|
||||
Currency: "USD",
|
||||
},
|
||||
Cycles: "2",
|
||||
ChargeModels: []pp.ChargeModel{
|
||||
pp.ChargeModel{
|
||||
Type: "SHIPPING",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "1",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
pp.ChargeModel{
|
||||
Type: "TAX",
|
||||
Amount: pp.AmountPayout{
|
||||
Value: "2",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
MerchantPreferences: &pp.MerchantPreferences{
|
||||
SetupFee: &pp.AmountPayout{
|
||||
Value: "1",
|
||||
Currency: "USD",
|
||||
},
|
||||
ReturnURL: "http://www.paypal.com",
|
||||
CancelURL: "http://www.paypal.com/cancel",
|
||||
AutoBillAmount: "YES",
|
||||
InitialFailAmountAction: "CONTINUE",
|
||||
MaxFailAttempts: "0",
|
||||
},
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ func (c *Client) SetHTTPClient(client *http.Client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
// SetAccessToken sets saved token to current client
|
||||
func (c *Client) SetAccessToken(token string) error {
|
||||
c.Token = &TokenResponse{
|
||||
|
|
13
types.go
13
types.go
|
@ -44,8 +44,8 @@ const (
|
|||
)
|
||||
|
||||
type (
|
||||
// JsonTime overrides MarshalJson method to format in ISO8601
|
||||
JsonTime time.Time
|
||||
// JSONTime overrides MarshalJson method to format in ISO8601
|
||||
JSONTime time.Time
|
||||
|
||||
// Address struct
|
||||
Address struct {
|
||||
|
@ -113,7 +113,7 @@ type (
|
|||
BillingAgreement struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
StartDate JsonTime `json:"start_date,omitempty"`
|
||||
StartDate JSONTime `json:"start_date,omitempty"`
|
||||
Plan BillingPlan `json:"plan,omitempty"`
|
||||
Payer Payer `json:"payer,omitempty"`
|
||||
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
|
||||
|
@ -287,8 +287,8 @@ type (
|
|||
// MerchantPreferences struct
|
||||
MerchantPreferences struct {
|
||||
SetupFee *AmountPayout `json:"setup_fee,omitempty"`
|
||||
ReturnUrl string `json:"return_url,omitempty"`
|
||||
CancelUrl string `json:"cancel_url,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"`
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
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))
|
||||
return []byte(stamp), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user