ExecuteApprovedAgreement added

This commit is contained in:
envy124 2017-08-24 13:22:46 +03:00
parent d4da804af2
commit ce8c1014ec
2 changed files with 50 additions and 0 deletions

View File

@ -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
}

View File

@ -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"`