forked from go-packages/paypal
ExecuteApprovedAgreement added
This commit is contained in:
parent
d4da804af2
commit
ce8c1014ec
25
billing.go
25
billing.go
|
@ -2,6 +2,7 @@ package paypalsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -66,3 +67,27 @@ func (c *Client) CreateBillingAgreement(a BillingAgreement) (*CreateAgreementRes
|
||||||
err = c.SendWithAuth(req, response)
|
err = c.SendWithAuth(req, response)
|
||||||
return response, err
|
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
|
||||||
|
}
|
||||||
|
|
25
types.go
25
types.go
|
@ -58,6 +58,18 @@ type (
|
||||||
Phone string `json:"phone,omitempty"`
|
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
|
||||||
Amount struct {
|
Amount struct {
|
||||||
Currency string `json:"currency"`
|
Currency string `json:"currency"`
|
||||||
|
@ -208,6 +220,19 @@ type (
|
||||||
Details string `json:"details"`
|
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
|
||||||
ExecuteResponse struct {
|
ExecuteResponse struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user