forked from go-packages/paypal
Auth capture idempotency and refund idempotency (#143)
* Idempotency for capture auth
This commit is contained in:
parent
907cf40be1
commit
7827c1418f
|
@ -25,6 +25,17 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
|
|||
// To use this method, the original payment must have Intent set to "authorize"
|
||||
// Endpoint: POST /v2/payments/authorizations/ID/capture
|
||||
func (c *Client) CaptureAuthorization(authID string, paymentCaptureRequest *PaymentCaptureRequest) (*PaymentCaptureResponse, error) {
|
||||
return c.CaptureAuthorizationWithPaypalRequestId(authID, paymentCaptureRequest, "")
|
||||
}
|
||||
|
||||
// CaptureAuthorization captures and process an existing authorization with idempotency.
|
||||
// To use this method, the original payment must have Intent set to "authorize"
|
||||
// Endpoint: POST /v2/payments/authorizations/ID/capture
|
||||
func (c *Client) CaptureAuthorizationWithPaypalRequestId(
|
||||
authID string,
|
||||
paymentCaptureRequest *PaymentCaptureRequest,
|
||||
requestID string,
|
||||
) (*PaymentCaptureResponse, error) {
|
||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/authorizations/"+authID+"/capture"), paymentCaptureRequest)
|
||||
paymentCaptureResponse := &PaymentCaptureResponse{}
|
||||
|
||||
|
@ -32,6 +43,10 @@ func (c *Client) CaptureAuthorization(authID string, paymentCaptureRequest *Paym
|
|||
return paymentCaptureResponse, err
|
||||
}
|
||||
|
||||
if requestID != "" {
|
||||
req.Header.Set("PayPal-Request-Id", requestID)
|
||||
}
|
||||
|
||||
err = c.SendWithAuth(req, paymentCaptureResponse)
|
||||
return paymentCaptureResponse, err
|
||||
}
|
||||
|
|
14
order.go
14
order.go
|
@ -113,6 +113,16 @@ func (c *Client) CaptureOrderWithPaypalRequestId(
|
|||
// RefundCapture - https://developer.paypal.com/docs/api/payments/v2/#captures_refund
|
||||
// Endpoint: POST /v2/payments/captures/ID/refund
|
||||
func (c *Client) RefundCapture(captureID string, refundCaptureRequest RefundCaptureRequest) (*RefundResponse, error) {
|
||||
return c.RefundCaptureWithPaypalRequestId(captureID, refundCaptureRequest, "")
|
||||
}
|
||||
|
||||
// RefundCapture with idempotency - https://developer.paypal.com/docs/api/payments/v2/#captures_refund
|
||||
// Endpoint: POST /v2/payments/captures/ID/refund
|
||||
func (c *Client) RefundCaptureWithPaypalRequestId(
|
||||
captureID string,
|
||||
refundCaptureRequest RefundCaptureRequest,
|
||||
requestID string,
|
||||
) (*RefundResponse, error) {
|
||||
refund := &RefundResponse{}
|
||||
|
||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/captures/"+captureID+"/refund"), refundCaptureRequest)
|
||||
|
@ -120,6 +130,10 @@ func (c *Client) RefundCapture(captureID string, refundCaptureRequest RefundCapt
|
|||
return refund, err
|
||||
}
|
||||
|
||||
if requestID != "" {
|
||||
req.Header.Set("PayPal-Request-Id", requestID)
|
||||
}
|
||||
|
||||
if err = c.SendWithAuth(req, refund); err != nil {
|
||||
return refund, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user