This commit is contained in:
Alex Pliutau 2024-06-03 10:09:31 +02:00
parent 6ebb0352bc
commit bfdf8e6e97
3 changed files with 44 additions and 37 deletions

View File

@ -44,21 +44,6 @@ auth, err := c.VoidAuthorization(authID)
auth, err := c.ReauthorizeAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"}) 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 ### Get Refund by ID
```go ```go
@ -74,7 +59,11 @@ order, err := c.GetOrder("O-4J082351X3132253H")
### Create an Order ### Create an Order
```go ```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 ### 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 ### Get payout by ID
@ -239,6 +228,7 @@ c.GetCreditCards(nil)
``` ```
### Webhooks ### Webhooks
```go ```go
// Create a webhook // Create a webhook
c.CreateWebhook(paypal.CreateWebhookRequest{ 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") 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) - 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 ```bash
curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \ curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: Bearer <Token>" -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 ## How to Contribute
* Fork a repository - Fork a repository
* Add/Fix something - Add/Fix something
* Check that tests are passing - Check that tests are passing
* Create PR - Create PR
Current contributors: Current contributors:

View File

@ -23,10 +23,10 @@ func (c *Client) GetOrder(ctx context.Context, orderID string) (*Order, error) {
return order, nil return order, nil
} }
// CreateOrder - Use this call to create an order // Create an order
// Endpoint: POST /v2/checkout/orders // Endpoint: POST /v2/checkout/orders
func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, payer *CreateOrderPayer, appContext *ApplicationContext) (*Order, error) { func (c *Client) CreateOrder(ctx context.Context, intent string, purchaseUnits []PurchaseUnitRequest, paymentSource *PaymentSource, appContext *ApplicationContext) (*Order, error) {
return c.CreateOrderWithPaypalRequestID(ctx, intent, purchaseUnits, payer, appContext, "") return c.CreateOrderWithPaypalRequestID(ctx, intent, purchaseUnits, paymentSource, appContext, "")
} }
// CreateOrderWithPaypalRequestID - Use this call to create an order with idempotency // 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, func (c *Client) CreateOrderWithPaypalRequestID(ctx context.Context,
intent string, intent string,
purchaseUnits []PurchaseUnitRequest, purchaseUnits []PurchaseUnitRequest,
payer *CreateOrderPayer, paymentSource *PaymentSource,
appContext *ApplicationContext, appContext *ApplicationContext,
requestID string, requestID string,
) (*Order, error) { ) (*Order, error) {
type createOrderRequest struct { type createOrderRequest struct {
Intent string `json:"intent"` Intent string `json:"intent"`
Payer *CreateOrderPayer `json:"payer,omitempty"` PaymentSource *PaymentSource `json:"payment_source,omitempty"`
PurchaseUnits []PurchaseUnitRequest `json:"purchase_units"` PurchaseUnits []PurchaseUnitRequest `json:"purchase_units"`
ApplicationContext *ApplicationContext `json:"application_context,omitempty"` ApplicationContext *ApplicationContext `json:"application_context,omitempty"`
} }
order := &Order{} 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 { if err != nil {
return order, err return order, err
} }

View File

@ -1053,6 +1053,7 @@ type (
PaymentSource struct { PaymentSource struct {
Card *PaymentSourceCard `json:"card,omitempty"` Card *PaymentSourceCard `json:"card,omitempty"`
Token *PaymentSourceToken `json:"token,omitempty"` Token *PaymentSourceToken `json:"token,omitempty"`
Paypal *PaymentSourcePaypal `json:"paypal,omitempty"`
} }
// PaymentSourceCard structure // PaymentSourceCard structure
@ -1067,6 +1068,22 @@ type (
BillingAddress *CardBillingAddress `json:"billing_address"` 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 structure
CardBillingAddress struct { CardBillingAddress struct {
AddressLine1 string `json:"address_line_1"` AddressLine1 string `json:"address_line_1"`