diff --git a/README.md b/README.md index fd630c3..f6cc37e 100644 --- a/README.md +++ b/README.md @@ -44,21 +44,6 @@ auth, err := c.VoidAuthorization(authID) auth, err := c.ReauthorizeAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"}) ``` -### Get Sale by ID - -```go -sale, err := c.GetSale("36C38912MN9658832") -``` - -### Refund Sale by ID - -```go -// Full -refund, err := c.RefundSale(saleID, nil) -// Partial -refund, err := c.RefundSale(saleID, &paypal.Amount{Total: "7.00", Currency: "USD"}) -``` - ### Get Refund by ID ```go @@ -74,7 +59,11 @@ order, err := c.GetOrder("O-4J082351X3132253H") ### Create an Order ```go -order, err := c.CreateOrder(paypal.OrderIntentCapture, []paypal.PurchaseUnitRequest{paypal.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypal.Amount{Total: "7.00", Currency: "USD"}}}) +ctx := context.Background() +units := []paypal.PurchaseUnitRequest{} +source := &paypal.PaymentSource{} +appCtx := &paypalApplicationContext{} +order, err := c.CreateOrder(ctx, paypal.OrderIntentCapture, units, ource, appCtx) ``` ### Update Order by ID @@ -130,7 +119,7 @@ payout := paypal.Payout{ }, } -payoutResp, err := c.CreateSinglePayout(payout) +payoutResp, err := c.CreatePayout(payout) ``` ### Get payout by ID @@ -239,6 +228,7 @@ c.GetCreditCards(nil) ``` ### Webhooks + ```go // Create a webhook c.CreateWebhook(paypal.CreateWebhookRequest{ @@ -287,22 +277,22 @@ c.GenerateInvoiceNumber(ctx) // might return something like "0001" or "0010". invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33") ``` -* for now, we are yet to implement the ShowAllInvoices endpoint, so use the following cURL request for the same(this gives you the list of invoice-IDs for this customer) - ```bash - curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer " - ``` +- for now, we are yet to implement the ShowAllInvoices endpoint, so use the following cURL request for the same(this gives you the list of invoice-IDs for this customer) + + ```bash + curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer " + ``` -* refer to the beginning of this Usage section for obtaining a Token. - +- refer to the beginning of this Usage section for obtaining a Token. ## How to Contribute -* Fork a repository -* Add/Fix something -* Check that tests are passing -* Create PR +- Fork a repository +- Add/Fix something +- Check that tests are passing +- Create PR Current contributors: diff --git a/order.go b/order.go index 4d4241a..9f6e56f 100644 --- a/order.go +++ b/order.go @@ -23,10 +23,10 @@ func (c *Client) GetOrder(ctx context.Context, orderID string) (*Order, error) { return order, nil } -// CreateOrder - Use this call to create an order +// 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, "") +func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, paymentSource *PaymentSource, appContext *ApplicationContext) (*Order, error) { + return c.CreateOrderWithPaypalRequestID(ctx, intent, purchaseUnits, paymentSource, appContext, "") } // CreateOrderWithPaypalRequestID - Use this call to create an order with idempotency @@ -34,20 +34,20 @@ func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits [ func (c *Client) CreateOrderWithPaypalRequestID(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, - payer *CreateOrderPayer, + paymentSource *PaymentSource, appContext *ApplicationContext, requestID string, ) (*Order, error) { type createOrderRequest struct { Intent string `json:"intent"` - Payer *CreateOrderPayer `json:"payer,omitempty"` + PaymentSource *PaymentSource `json:"payment_source,omitempty"` PurchaseUnits []PurchaseUnitRequest `json:"purchase_units"` ApplicationContext *ApplicationContext `json:"application_context,omitempty"` } order := &Order{} - req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders"), createOrderRequest{Intent: intent, PurchaseUnits: purchaseUnits, Payer: payer, ApplicationContext: appContext}) + req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders"), createOrderRequest{Intent: intent, PurchaseUnits: purchaseUnits, PaymentSource: paymentSource, ApplicationContext: appContext}) if err != nil { return order, err } diff --git a/types.go b/types.go index 6d07587..a8df203 100644 --- a/types.go +++ b/types.go @@ -1051,8 +1051,9 @@ type ( // PaymentSource structure PaymentSource struct { - Card *PaymentSourceCard `json:"card,omitempty"` - Token *PaymentSourceToken `json:"token,omitempty"` + Card *PaymentSourceCard `json:"card,omitempty"` + Token *PaymentSourceToken `json:"token,omitempty"` + Paypal *PaymentSourcePaypal `json:"paypal,omitempty"` } // PaymentSourceCard structure @@ -1067,6 +1068,22 @@ type ( BillingAddress *CardBillingAddress `json:"billing_address"` } + // PaymentSourcePaypal structure + PaymentSourcePaypal struct { + ExperienceContext PaymentSourcePaypalExperienceContext `json:"experience_context"` + } + + PaymentSourcePaypalExperienceContext struct { + PaymentMethodPreference string `json:"payment_method_preference"` + BrandName string `json:"brand_name"` + Locale string `json:"locale"` + LandingPage string `json:"landing_page"` + ShippingPreference string `json:"shipping_preference"` + UserAction string `json:"user_action"` + ReturnURL string `json:"return_url"` + CancelURL string `json:"cancel_url"` + } + // CardBillingAddress structure CardBillingAddress struct { AddressLine1 string `json:"address_line_1"`