mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
Fix payment capture
This commit is contained in:
parent
c0ae3c0d06
commit
fee7108fae
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetAuthorization returns an authorization by ID
|
// 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.
|
// CaptureAuthorization captures and process an existing authorization.
|
||||||
// To use this method, the original payment must have Intent set to "authorize"
|
// To use this method, the original payment must have Intent set to "authorize"
|
||||||
// Endpoint: POST /v2/payments/authorization/ID/capture
|
// Endpoint: POST /v2/payments/authorizations/ID/capture
|
||||||
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
|
func (c *Client) CaptureAuthorization(authID string, paymentCaptureRequest *PaymentCaptureRequest) (*PaymentCaptureResponse, error) {
|
||||||
isFinalStr := strconv.FormatBool(isFinalCapture)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorizations/"+authID+"/capture"), paymentCaptureRequest)
|
||||||
|
paymentCaptureResponse := &PaymentCaptureResponse{}
|
||||||
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{}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return capture, err
|
return paymentCaptureResponse, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, capture)
|
err = c.SendWithAuth(req, paymentCaptureResponse)
|
||||||
return capture, err
|
return paymentCaptureResponse, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// VoidAuthorization voids a previously authorized payment
|
// VoidAuthorization voids a previously authorized payment
|
||||||
|
|
36
types.go
36
types.go
|
@ -162,6 +162,42 @@ type (
|
||||||
ApplicationContext ApplicationContext `json:"application_context,omitempty"`
|
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 - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
CaptureOrderRequest struct {
|
CaptureOrderRequest struct {
|
||||||
PaymentSource *PaymentSource `json:"payment_source"`
|
PaymentSource *PaymentSource `json:"payment_source"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user