mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 02:11:02 +01:00
Added PayPal-Mock-Response for capture (#232)
This commit is contained in:
parent
ca6845e257
commit
d381642422
13
order.go
13
order.go
|
@ -2,6 +2,7 @@ package paypal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
@ -104,7 +105,7 @@ func (c *Client) AuthorizeOrder(ctx context.Context, orderID string, authorizeOr
|
|||
// CaptureOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||
// Endpoint: POST /v2/checkout/orders/ID/capture
|
||||
func (c *Client) CaptureOrder(ctx context.Context, orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) {
|
||||
return c.CaptureOrderWithPaypalRequestId(ctx, orderID, captureOrderRequest, "")
|
||||
return c.CaptureOrderWithPaypalRequestId(ctx, orderID, captureOrderRequest, "", nil)
|
||||
}
|
||||
|
||||
// CaptureOrder with idempotency - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||
|
@ -114,6 +115,7 @@ func (c *Client) CaptureOrderWithPaypalRequestId(ctx context.Context,
|
|||
orderID string,
|
||||
captureOrderRequest CaptureOrderRequest,
|
||||
requestID string,
|
||||
mockResponse *CaptureOrderMockResponse,
|
||||
) (*CaptureOrderResponse, error) {
|
||||
capture := &CaptureOrderResponse{}
|
||||
|
||||
|
@ -127,6 +129,15 @@ func (c *Client) CaptureOrderWithPaypalRequestId(ctx context.Context,
|
|||
req.Header.Set("PayPal-Request-Id", requestID)
|
||||
}
|
||||
|
||||
if mockResponse != nil {
|
||||
mock, err := json.Marshal(mockResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("PayPal-Mock-Response", string(mock))
|
||||
}
|
||||
|
||||
if err = c.SendWithAuth(req, capture); err != nil {
|
||||
return capture, err
|
||||
}
|
||||
|
|
5
types.go
5
types.go
|
@ -299,6 +299,11 @@ type (
|
|||
PaymentSource *PaymentSource `json:"payment_source"`
|
||||
}
|
||||
|
||||
// CaptureOrderMockResponse - https://developer.paypal.com/docs/api-basics/sandbox/request-headers/#test-api-error-handling-routines
|
||||
CaptureOrderMockResponse struct {
|
||||
MockApplicationCodes string `json:"mock_application_codes"`
|
||||
}
|
||||
|
||||
// RefundOrderRequest - https://developer.paypal.com/docs/api/payments/v2/#captures_refund
|
||||
RefundCaptureRequest struct {
|
||||
Amount *Money `json:"amount,omitempty"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user