Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
plutov committed Jun 3, 2024
1 parent 6ebb035 commit bfdf8e6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
48 changes: 19 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -130,7 +119,7 @@ payout := paypal.Payout{
},
}

payoutResp, err := c.CreateSinglePayout(payout)
payoutResp, err := c.CreatePayout(payout)
```

### Get payout by ID
Expand Down Expand Up @@ -239,6 +228,7 @@ c.GetCreditCards(nil)
```

### Webhooks

```go
// Create a webhook
c.CreateWebhook(paypal.CreateWebhookRequest{
Expand Down Expand Up @@ -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 <Token>"
```
- 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 <Token>"
```

* 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:

Expand Down
12 changes: 6 additions & 6 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ 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
// Endpoint: POST /v2/checkout/orders
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
}
Expand Down
21 changes: 19 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down

0 comments on commit bfdf8e6

Please sign in to comment.