forked from go-packages/paypal
idempotent create order api (#191)
This commit is contained in:
parent
df9918548b
commit
a5cff3c18c
16
order.go
16
order.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user