forked from go-packages/paypal
BillingAgreement definition
This commit is contained in:
parent
77c97c8824
commit
1f84980013
31
billing.go
31
billing.go
|
@ -18,24 +18,27 @@ type (
|
||||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||||
Links []Link `json:"links,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
|
// CreateBillingPlan creates a billing plan in Paypal
|
||||||
// Endpoint: POST /v1/payments/billing-plans
|
// Endpoint: POST /v1/payments/billing-plans
|
||||||
func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) {
|
func (c *Client) CreateBillingPlan(plan BillingPlan) (*CreateBillingResp, error) {
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan)
|
||||||
if err != nil {
|
|
||||||
return &CreateBillingResp{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
response := &CreateBillingResp{}
|
response := &CreateBillingResp{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
err = c.SendWithAuth(req, response)
|
||||||
return response, nil
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activates a billing plan
|
// Activates a billing plan
|
||||||
|
@ -51,3 +54,15 @@ func (c *Client) ActivatePlan(planID string) error {
|
||||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||||
return c.SendWithAuth(req, nil)
|
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
|
||||||
|
}
|
||||||
|
|
29
types.go
29
types.go
|
@ -44,6 +44,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// JsonTime overrides MarshalJson method to format in ISO8601
|
||||||
|
JsonTime time.Time
|
||||||
|
|
||||||
// Address struct
|
// Address struct
|
||||||
Address struct {
|
Address struct {
|
||||||
Line1 string `json:"line1"`
|
Line1 string `json:"line1"`
|
||||||
|
@ -93,13 +96,24 @@ type (
|
||||||
SenderBatchHeader *SenderBatchHeader `json:"sender_batch_header,omitempty"`
|
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
|
||||||
BillingPlan struct {
|
BillingPlan struct {
|
||||||
Name string `json:"name,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
MerchantPreferences MerchantPreferences `json:"merchant_preferences,omitempty"`
|
PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"`
|
||||||
|
MerchantPreferences *MerchantPreferences `json:"merchant_preferences,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Capture struct
|
// Capture struct
|
||||||
|
@ -486,3 +500,8 @@ type (
|
||||||
func (r *ErrorResponse) Error() string {
|
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) {
|
||||||
|
stamp := fmt.Sprintf(`"%s"`, time.Time(t).UTC().Format(time.RFC3339))
|
||||||
|
return []byte(stamp), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user