From c4226ce43c07265b304a2d0fe1144571261e79f4 Mon Sep 17 00:00:00 2001 From: Eric Lee Date: Tue, 24 Sep 2019 12:34:56 -0700 Subject: [PATCH] Fix authorizations (#119) Fix authorizations --- authorization.go | 6 +++--- types.go | 27 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/authorization.go b/authorization.go index cfeba23..8438fd6 100644 --- a/authorization.go +++ b/authorization.go @@ -10,7 +10,7 @@ import ( // Endpoint: GET /v2/payments/authorization/ID func (c *Client) GetAuthorization(authID string) (*Authorization, error) { buf := bytes.NewBuffer([]byte("")) - req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/payments/authorization/", authID), buf) + req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/payments/authorizations/", authID), buf) auth := &Authorization{} if err != nil { @@ -40,7 +40,7 @@ func (c *Client) CaptureAuthorization(authID string, paymentCaptureRequest *Paym // Endpoint: POST /v2/payments/authorization/ID/void func (c *Client) VoidAuthorization(authID string) (*Authorization, error) { buf := bytes.NewBuffer([]byte("")) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorization/"+authID+"/void"), buf) + req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorizations/"+authID+"/void"), buf) auth := &Authorization{} if err != nil { @@ -56,7 +56,7 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) { // Endpoint: POST /v2/payments/authorization/ID/reauthorize func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error) { buf := bytes.NewBuffer([]byte(`{"amount":{"currency":"` + a.Currency + `","total":"` + a.Total + `"}}`)) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorization/"+authID+"/reauthorize"), buf) + req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorizations/"+authID+"/reauthorize"), buf) auth := &Authorization{} if err != nil { diff --git a/types.go b/types.go index 7565d40..e4a15fd 100644 --- a/types.go +++ b/types.go @@ -132,17 +132,17 @@ type ( // Authorization struct Authorization struct { - Amount *Amount `json:"amount,omitempty"` - CreateTime *time.Time `json:"create_time,omitempty"` - UpdateTime *time.Time `json:"update_time,omitempty"` - State string `json:"state,omitempty"` - ParentPayment string `json:"parent_payment,omitempty"` - ID string `json:"id,omitempty"` - ValidUntil *time.Time `json:"valid_until,omitempty"` - Links []Link `json:"links,omitempty"` - ClearingTime string `json:"clearing_time,omitempty"` - ProtectionEligibility string `json:"protection_eligibility,omitempty"` - ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"` + ID string `json:"id,omitempty"` + CustomID string `json:"custom_id,omitempty"` + InvoiceID string `json:"invoice_id,omitempty"` + Status string `json:"status,omitempty"` + StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` + Amount *PurchaseUnitAmount `json:"amount,omitempty"` + SellerProtection *SellerProtection `json:"seller_protection,omitempty"` + CreateTime *time.Time `json:"create_time,omitempty"` + UpdateTime *time.Time `json:"update_time,omitempty"` + ExpirationTime *time.Time `json:"expiration_time,omitempty"` + Links []Link `json:"links,omitempty"` } // AuthorizeOrderResponse . @@ -183,6 +183,11 @@ type ( FinalCapture bool `json:"final_capture,omitempty"` } + SellerProtection struct { + Status string `json:"status,omitempty"` + DisputeCategories []string `json:"dispute_categories,omitempty"` + } + // https://developer.paypal.com/docs/api/payments/v2/#definition-capture_status_details CaptureStatusDetails struct { Reason string `json:"reason,omitempty"`