diff --git a/authorization.go b/authorization.go index 30c5300..cfeba23 100644 --- a/authorization.go +++ b/authorization.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "net/http" - "strconv" ) // GetAuthorization returns an authorization by ID @@ -24,20 +23,17 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) { // CaptureAuthorization captures and process an existing authorization. // To use this method, the original payment must have Intent set to "authorize" -// Endpoint: POST /v2/payments/authorization/ID/capture -func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) { - isFinalStr := strconv.FormatBool(isFinalCapture) - - buf := bytes.NewBuffer([]byte(`{"amount":{"currency":"` + a.Currency + `,"total":"` + a.Total + `"},"is_final_capture":` + isFinalStr + `}`)) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorization/"+authID+"/capture"), buf) - capture := &Capture{} +// Endpoint: POST /v2/payments/authorizations/ID/capture +func (c *Client) CaptureAuthorization(authID string, paymentCaptureRequest *PaymentCaptureRequest) (*PaymentCaptureResponse, error) { + req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorizations/"+authID+"/capture"), paymentCaptureRequest) + paymentCaptureResponse := &PaymentCaptureResponse{} if err != nil { - return capture, err + return paymentCaptureResponse, err } - err = c.SendWithAuth(req, capture) - return capture, err + err = c.SendWithAuth(req, paymentCaptureResponse) + return paymentCaptureResponse, err } // VoidAuthorization voids a previously authorized payment diff --git a/types.go b/types.go index 42f4d75..ee99dee 100644 --- a/types.go +++ b/types.go @@ -162,6 +162,42 @@ type ( ApplicationContext ApplicationContext `json:"application_context,omitempty"` } + // https://developer.paypal.com/docs/api/payments/v2/#definition-platform_fee + PlatformFee struct { + Amount *Money `json:"amount,omitempty"` + Payee *PayeeForOrders `json:"payee,omitempty"` + } + + // https://developer.paypal.com/docs/api/payments/v2/#definition-payment_instruction + PaymentInstruction struct { + PlatformFees []PlatformFee `json:"platform_fees,omitempty"` + DisbursementMode string `json:"disbursement_mode,omitempty"` + } + + // https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture + PaymentCaptureRequest struct { + InvoiceID string `json:"invoice_id,omitempty"` + NoteToPayer string `json:"note_to_payer,omitempty"` + SoftDescriptor string `json:"soft_descriptor,omitempty"` + Amount *Money `json:"amount,omitempty"` + FinalCapture bool `json:"final_capture,omitempty"` + } + + // https://developer.paypal.com/docs/api/payments/v2/#definition-capture_status_details + CaptureStatusDetails struct { + Reason string `json:"reason,omitempty"` + } + + PaymentCaptureResponse struct { + Status string `json:"status,omitempty"` + StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` + ID string `json:"id,omitempty"` + Amount *Money `json:"amount,omitempty"` + InvoiceID string `json:"invoice_id,omitempty"` + FinalCapture bool `json:"final_capture,omitempty"` + DisbursementMode string `json:"disbursement_mode,omitempty"` + } + // CaptureOrderRequest - https://developer.paypal.com/docs/api/orders/v2/#orders_capture CaptureOrderRequest struct { PaymentSource *PaymentSource `json:"payment_source"`