mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
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"`
|
||||
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
|
||||
}
|
||||
|
|
21
types.go
21
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 {
|
||||
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"`
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user