Skip to content

Commit bfdf8e6

Browse files
committed
1 parent 6ebb035 commit bfdf8e6

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

README.md

+19-29
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ auth, err := c.VoidAuthorization(authID)
4444
auth, err := c.ReauthorizeAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"})
4545
```
4646

47-
### Get Sale by ID
48-
49-
```go
50-
sale, err := c.GetSale("36C38912MN9658832")
51-
```
52-
53-
### Refund Sale by ID
54-
55-
```go
56-
// Full
57-
refund, err := c.RefundSale(saleID, nil)
58-
// Partial
59-
refund, err := c.RefundSale(saleID, &paypal.Amount{Total: "7.00", Currency: "USD"})
60-
```
61-
6247
### Get Refund by ID
6348

6449
```go
@@ -74,7 +59,11 @@ order, err := c.GetOrder("O-4J082351X3132253H")
7459
### Create an Order
7560

7661
```go
77-
order, err := c.CreateOrder(paypal.OrderIntentCapture, []paypal.PurchaseUnitRequest{paypal.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypal.Amount{Total: "7.00", Currency: "USD"}}})
62+
ctx := context.Background()
63+
units := []paypal.PurchaseUnitRequest{}
64+
source := &paypal.PaymentSource{}
65+
appCtx := &paypalApplicationContext{}
66+
order, err := c.CreateOrder(ctx, paypal.OrderIntentCapture, units, ource, appCtx)
7867
```
7968

8069
### Update Order by ID
@@ -130,7 +119,7 @@ payout := paypal.Payout{
130119
},
131120
}
132121

133-
payoutResp, err := c.CreateSinglePayout(payout)
122+
payoutResp, err := c.CreatePayout(payout)
134123
```
135124

136125
### Get payout by ID
@@ -239,6 +228,7 @@ c.GetCreditCards(nil)
239228
```
240229

241230
### Webhooks
231+
242232
```go
243233
// Create a webhook
244234
c.CreateWebhook(paypal.CreateWebhookRequest{
@@ -287,22 +277,22 @@ c.GenerateInvoiceNumber(ctx) // might return something like "0001" or "0010".
287277
invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33")
288278
```
289279

290-
* 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)
291-
```bash
292-
curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \
293-
-H "Content-Type: application/json" \
294-
-H "Authorization: Bearer <Token>"
295-
```
280+
- 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)
281+
282+
```bash
283+
curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \
284+
-H "Content-Type: application/json" \
285+
-H "Authorization: Bearer <Token>"
286+
```
296287

297-
* refer to the beginning of this Usage section for obtaining a Token.
298-
288+
- refer to the beginning of this Usage section for obtaining a Token.
299289

300290
## How to Contribute
301291

302-
* Fork a repository
303-
* Add/Fix something
304-
* Check that tests are passing
305-
* Create PR
292+
- Fork a repository
293+
- Add/Fix something
294+
- Check that tests are passing
295+
- Create PR
306296

307297
Current contributors:
308298

order.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ func (c *Client) GetOrder(ctx context.Context, orderID string) (*Order, error) {
2323
return order, nil
2424
}
2525

26-
// CreateOrder - Use this call to create an order
26+
// Create an order
2727
// Endpoint: POST /v2/checkout/orders
28-
func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, payer *CreateOrderPayer, appContext *ApplicationContext) (*Order, error) {
29-
return c.CreateOrderWithPaypalRequestID(ctx, intent, purchaseUnits, payer, appContext, "")
28+
func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, paymentSource *PaymentSource, appContext *ApplicationContext) (*Order, error) {
29+
return c.CreateOrderWithPaypalRequestID(ctx, intent, purchaseUnits, paymentSource, appContext, "")
3030
}
3131

3232
// CreateOrderWithPaypalRequestID - Use this call to create an order with idempotency
3333
// Endpoint: POST /v2/checkout/orders
3434
func (c *Client) CreateOrderWithPaypalRequestID(ctx context.Context,
3535
intent string,
3636
purchaseUnits []PurchaseUnitRequest,
37-
payer *CreateOrderPayer,
37+
paymentSource *PaymentSource,
3838
appContext *ApplicationContext,
3939
requestID string,
4040
) (*Order, error) {
4141
type createOrderRequest struct {
4242
Intent string `json:"intent"`
43-
Payer *CreateOrderPayer `json:"payer,omitempty"`
43+
PaymentSource *PaymentSource `json:"payment_source,omitempty"`
4444
PurchaseUnits []PurchaseUnitRequest `json:"purchase_units"`
4545
ApplicationContext *ApplicationContext `json:"application_context,omitempty"`
4646
}
4747

4848
order := &Order{}
4949

50-
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders"), createOrderRequest{Intent: intent, PurchaseUnits: purchaseUnits, Payer: payer, ApplicationContext: appContext})
50+
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders"), createOrderRequest{Intent: intent, PurchaseUnits: purchaseUnits, PaymentSource: paymentSource, ApplicationContext: appContext})
5151
if err != nil {
5252
return order, err
5353
}

types.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,9 @@ type (
10511051

10521052
// PaymentSource structure
10531053
PaymentSource struct {
1054-
Card *PaymentSourceCard `json:"card,omitempty"`
1055-
Token *PaymentSourceToken `json:"token,omitempty"`
1054+
Card *PaymentSourceCard `json:"card,omitempty"`
1055+
Token *PaymentSourceToken `json:"token,omitempty"`
1056+
Paypal *PaymentSourcePaypal `json:"paypal,omitempty"`
10561057
}
10571058

10581059
// PaymentSourceCard structure
@@ -1067,6 +1068,22 @@ type (
10671068
BillingAddress *CardBillingAddress `json:"billing_address"`
10681069
}
10691070

1071+
// PaymentSourcePaypal structure
1072+
PaymentSourcePaypal struct {
1073+
ExperienceContext PaymentSourcePaypalExperienceContext `json:"experience_context"`
1074+
}
1075+
1076+
PaymentSourcePaypalExperienceContext struct {
1077+
PaymentMethodPreference string `json:"payment_method_preference"`
1078+
BrandName string `json:"brand_name"`
1079+
Locale string `json:"locale"`
1080+
LandingPage string `json:"landing_page"`
1081+
ShippingPreference string `json:"shipping_preference"`
1082+
UserAction string `json:"user_action"`
1083+
ReturnURL string `json:"return_url"`
1084+
CancelURL string `json:"cancel_url"`
1085+
}
1086+
10701087
// CardBillingAddress structure
10711088
CardBillingAddress struct {
10721089
AddressLine1 string `json:"address_line_1"`

0 commit comments

Comments
 (0)