idempotent create order api (#191)

This commit is contained in:
Yash Suresh Chandra 2021-01-26 02:22:19 +05:30 committed by GitHub
parent df9918548b
commit a5cff3c18c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,18 @@ func (c *Client) GetOrder(ctx context.Context, orderID string) (*Order, error) {
// CreateOrder - Use this call to create an order
// Endpoint: POST /v2/checkout/orders
func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, payer *CreateOrderPayer, appContext *ApplicationContext) (*Order, error) {
return c.CreateOrderWithPaypalRequestID(ctx, intent, purchaseUnits, payer, appContext, "")
}
// CreateOrderWithPaypalRequestID - Use this call to create an order with idempotency
// Endpoint: POST /v2/checkout/orders
func (c *Client) CreateOrderWithPaypalRequestID(ctx context.Context,
intent string,
purchaseUnits []PurchaseUnitRequest,
payer *CreateOrderPayer,
appContext *ApplicationContext,
requestID string,
) (*Order, error) {
type createOrderRequest struct {
Intent string `json:"intent"`
Payer *CreateOrderPayer `json:"payer,omitempty"`
@ -39,6 +51,10 @@ func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits [
return order, err
}
if requestID != "" {
req.Header.Set("PayPal-Request-Id", requestID)
}
if err = c.SendWithAuth(req, order); err != nil {
return order, err
}