mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"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
|
// CaptureOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
// Endpoint: POST /v2/checkout/orders/ID/capture
|
// Endpoint: POST /v2/checkout/orders/ID/capture
|
||||||
func (c *Client) CaptureOrder(ctx context.Context, orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) {
|
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
|
// 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,
|
orderID string,
|
||||||
captureOrderRequest CaptureOrderRequest,
|
captureOrderRequest CaptureOrderRequest,
|
||||||
requestID string,
|
requestID string,
|
||||||
|
mockResponse *CaptureOrderMockResponse,
|
||||||
) (*CaptureOrderResponse, error) {
|
) (*CaptureOrderResponse, error) {
|
||||||
capture := &CaptureOrderResponse{}
|
capture := &CaptureOrderResponse{}
|
||||||
|
|
||||||
|
@ -127,6 +129,15 @@ func (c *Client) CaptureOrderWithPaypalRequestId(ctx context.Context,
|
||||||
req.Header.Set("PayPal-Request-Id", requestID)
|
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 {
|
if err = c.SendWithAuth(req, capture); err != nil {
|
||||||
return capture, err
|
return capture, err
|
||||||
}
|
}
|
||||||
|
|
5
types.go
5
types.go
|
@ -299,6 +299,11 @@ type (
|
||||||
PaymentSource *PaymentSource `json:"payment_source"`
|
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
|
// RefundOrderRequest - https://developer.paypal.com/docs/api/payments/v2/#captures_refund
|
||||||
RefundCaptureRequest struct {
|
RefundCaptureRequest struct {
|
||||||
Amount *Money `json:"amount,omitempty"`
|
Amount *Money `json:"amount,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user