github.com/plutov/paypal/v4@v4.7.1/README.md (about)

     1  [![Go Report Card](https://goreportcard.com/badge/plutov/paypal)](https://goreportcard.com/report/plutov/paypal)
     2  [![Build Status](https://travis-ci.org/plutov/paypal.svg?branch=master)](https://travis-ci.org/plutov/paypal)
     3  [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/plutov/paypal)
     4  
     5  # Go client for PayPal REST API
     6  
     7  ## Coverage
     8  
     9  ### Auth
    10  
    11  * POST /v1/oauth2/token
    12  
    13  ### /v1/payments
    14  
    15  * POST /v1/payments/payouts
    16  * GET /v1/payments/payouts/:id
    17  * GET /v1/payments/payouts-item/:id
    18  * POST /v1/payments/payouts-item/:id/cancel
    19  * GET /v1/payments/sale/:id
    20  * POST /v1/payments/sale/:id/refund
    21  * GET /v1/payments/billing-plans
    22  * POST /v1/payments/billing-plans
    23  * PATCH /v1/payments/billing-plans/:id
    24  * POST /v1/payments/billing-agreements
    25  * POST /v1/payments/billing-agreements/:token/agreement-execute
    26  
    27  ### /v2/payments
    28  
    29  * GET /v2/payments/authorizations/:id
    30  * GET /v2/payments/captures/:id
    31  * POST /v2/payments/authorizations/:id/capture
    32  * POST /v2/payments/authorizations/:id/void
    33  * POST /v2/payments/authorizations/:id/reauthorize
    34  * GET /v2/payments/refund/:id
    35  
    36  ### Identity
    37  * POST /v1/identity/openidconnect/tokenservice
    38  * GET /v1/identity/openidconnect/userinfo/?schema=:schema
    39  
    40  ### /v1/payment-experience
    41  
    42  * GET /v1/payment-experience/web-profiles
    43  * POST /v1/payment-experience/web-profiles
    44  * GET /v1/payment-experience/web-profiles/:id
    45  * PUT /v1/payment-experience/web-profiles/:id
    46  * DELETE /v1/payment-experience/web-profiles/:id
    47  
    48  ### /v1/reporting
    49  
    50  * POST /v1/reporting/transactions
    51  
    52  ### Vault
    53  
    54  * POST /v1/vault/credit-cards
    55  * DELETE /v1/vault/credit-cards/:id
    56  * PATCH /v1/vault/credit-cards/:id
    57  * GET /v1/vault/credit-cards/:id
    58  * GET /v1/vault/credit-cards
    59  
    60  ### Checkout
    61  
    62  * POST /v2/checkout/orders
    63  * GET /v2/checkout/orders/:id
    64  * PATCH /v2/checkout/orders/:id
    65  * POST /v2/checkout/orders/:id/authorize
    66  * POST /v2/checkout/orders/:id/capture
    67  
    68  ### Notifications
    69  * POST /v1/notifications/webhooks
    70  * GET /v1/notifications/webhooks
    71  * GET /v1/notifications/webhooks/:id
    72  * PATCH /v1/notifications/webhooks/:id
    73  * DELETE /v1/notifications/webhooks/:id
    74  * POST /v1/notifications/verify-webhook-signature
    75  
    76  ### Products (Catalog)
    77  
    78  * POST /v1/catalogs/products
    79  * PATCH /v1/catalogs/products/:id
    80  * GET /v1/catalogs/products/:id
    81  * GET /v1/catalogs/products
    82  
    83  ### Billing Plans (Subscriptions)
    84  
    85  * POST  /v1/billing/plans
    86  * PATCH /v1/billing/plans/:id
    87  * GET   /v1/billing/plans/:id
    88  * GET   /v1/billing/plans
    89  * POST  /v1/billing/plans/:id/activate
    90  * POST  /v1/billing/plans/:id/deactivate
    91  * POST  /v1/billing/plans/:id/update-pricing-schemes
    92  
    93  ### Subscriptions
    94  
    95  * POST /v1/billing/subscriptions
    96  * PATCH /v1/billing/subscriptions/:id
    97  * GET /v1/billing/subscriptions/:id
    98  * POST /v1/billing/subscriptions/:id/activate
    99  * POST /v1/billing/subscriptions/:id/cancel
   100  * POST /v1/billing/subscriptions/:id/revise
   101  * POST /v1/billing/subscriptions/:id/capture
   102  * POST /v1/billing/subscriptions/:id/suspend
   103  * GET /v1/billing/subscriptions/:id/transactions
   104  
   105  ### Invoicing
   106  
   107  * POST /v2/invoicing/generate-next-invoice-number
   108  * GET /v2/invoicing/invoices/:id
   109   
   110  ## Missing endpoints
   111  
   112  It is possible that some endpoints are missing in this Client, but you can use built-in `paypal` functions to perform a request: `NewClient -> NewRequest -> SendWithAuth`
   113  
   114  ## Usage
   115  
   116  ```go
   117  import "github.com/plutov/paypal/v4"
   118  
   119  // Create a client instance
   120  c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
   121  c.SetLog(os.Stdout) // Set log to terminal stdout
   122  ```
   123  
   124  ## Get authorization by ID
   125  
   126  ```go
   127  auth, err := c.GetAuthorization("2DC87612EK520411B")
   128  ```
   129  
   130  ### Capture authorization
   131  
   132  ```go
   133  capture, err := c.CaptureAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"}, true)
   134  ```
   135  
   136  ### Void authorization
   137  
   138  ```go
   139  auth, err := c.VoidAuthorization(authID)
   140  ```
   141  
   142  ### Reauthorize authorization
   143  
   144  ```go
   145  auth, err := c.ReauthorizeAuthorization(authID, &paypal.Amount{Total: "7.00", Currency: "USD"})
   146  ```
   147  
   148  ### Get Sale by ID
   149  
   150  ```go
   151  sale, err := c.GetSale("36C38912MN9658832")
   152  ```
   153  
   154  ### Refund Sale by ID
   155  
   156  ```go
   157  // Full
   158  refund, err := c.RefundSale(saleID, nil)
   159  // Partial
   160  refund, err := c.RefundSale(saleID, &paypal.Amount{Total: "7.00", Currency: "USD"})
   161  ```
   162  
   163  ### Get Refund by ID
   164  
   165  ```go
   166  refund, err := c.GetRefund("O-4J082351X3132253H")
   167  ```
   168  
   169  ### Get Order by ID
   170  
   171  ```go
   172  order, err := c.GetOrder("O-4J082351X3132253H")
   173  ```
   174  
   175  ### Create an Order
   176  
   177  ```go
   178  order, err := c.CreateOrder(paypal.OrderIntentCapture, []paypal.PurchaseUnitRequest{paypal.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypal.Amount{Total: "7.00", Currency: "USD"}}})
   179  ```
   180  
   181  ### Update Order by ID
   182  
   183  ```go
   184  order, err := c.UpdateOrder("O-4J082351X3132253H", []paypal.PurchaseUnitRequest{})
   185  ```
   186  
   187  ### Authorize Order
   188  
   189  ```go
   190  auth, err := c.AuthorizeOrder(orderID, paypal.AuthorizeOrderRequest{})
   191  ```
   192  
   193  ### Capture Order
   194  
   195  ```go
   196  capture, err := c.CaptureOrder(orderID, paypal.CaptureOrderRequest{})
   197  ```
   198  
   199  ### Identity
   200  
   201  ```go
   202  token, err := c.GrantNewAccessTokenFromAuthCode("<Authorization-Code>", "http://example.com/myapp/return.php")
   203  // ... or by refresh token
   204  token, err := c.GrantNewAccessTokenFromRefreshToken("<Refresh-Token>")
   205  ```
   206  
   207  ### Retreive user information
   208  
   209  ```go
   210  userInfo, err := c.GetUserInfo("openid")
   211  ```
   212  
   213  ### Create single payout to email
   214  
   215  ```go
   216  payout := paypal.Payout{
   217      SenderBatchHeader: &paypal.SenderBatchHeader{
   218          EmailSubject: "Subject will be displayed on PayPal",
   219      },
   220      Items: []paypal.PayoutItem{
   221          paypal.PayoutItem{
   222              RecipientType: "EMAIL",
   223              Receiver:      "single-email-payout@mail.com",
   224              Amount: &paypal.AmountPayout{
   225                  Value:    "15.11",
   226                  Currency: "USD",
   227              },
   228              Note:         "Optional note",
   229              SenderItemID: "Optional Item ID",
   230          },
   231      },
   232  }
   233  
   234  payoutResp, err := c.CreateSinglePayout(payout)
   235  ```
   236  
   237  ### Get payout by ID
   238  
   239  ```go
   240  payout, err := c.GetPayout("PayoutBatchID")
   241  ```
   242  
   243  ### Get payout item by ID
   244  
   245  ```go
   246  payoutItem, err := c.GetPayoutItem("PayoutItemID")
   247  ```
   248  
   249  ### Cancel unclaimed payout item by ID
   250  
   251  ```go
   252  payoutItem, err := c.CancelPayoutItem("PayoutItemID")
   253  ```
   254  
   255  ### Create web experience profile
   256  
   257  ```go
   258  webprofile := WebProfile{
   259      Name: "YeowZa! T-Shirt Shop",
   260      Presentation: Presentation{
   261          BrandName:  "YeowZa! Paypal",
   262          LogoImage:  "http://www.yeowza.com",
   263          LocaleCode: "US",
   264      },
   265  
   266      InputFields: InputFields{
   267          AllowNote:       true,
   268          NoShipping:      NoShippingDisplay,
   269          AddressOverride: AddrOverrideFromCall,
   270      },
   271  
   272      FlowConfig: FlowConfig{
   273          LandingPageType:   LandingPageTypeBilling,
   274          BankTXNPendingURL: "http://www.yeowza.com",
   275      },
   276  }
   277  
   278  result, err := c.CreateWebProfile(webprofile)
   279  ```
   280  
   281  ### Get web experience profile
   282  
   283  ```go
   284  webprofile, err := c.GetWebProfile("XP-CP6S-W9DY-96H8-MVN2")
   285  ```
   286  
   287  ### List web experience profile
   288  
   289  ```go
   290  webprofiles, err := c.GetWebProfiles()
   291  ```
   292  
   293  ### Update web experience profile
   294  
   295  ```go
   296  webprofile := WebProfile{
   297      ID: "XP-CP6S-W9DY-96H8-MVN2",
   298      Name: "Shop YeowZa! YeowZa! ",
   299  }
   300  err := c.SetWebProfile(webprofile)
   301  ```
   302  
   303  ### Delete web experience profile
   304  
   305  ```go
   306  err := c.DeleteWebProfile("XP-CP6S-W9DY-96H8-MVN2")
   307  ```
   308  
   309  ### Vault
   310  
   311  ```go
   312  // Store CC
   313  c.StoreCreditCard(paypal.CreditCard{
   314      Number:      "4417119669820331",
   315      Type:        "visa",
   316      ExpireMonth: "11",
   317      ExpireYear:  "2020",
   318      CVV2:        "874",
   319      FirstName:   "Foo",
   320      LastName:    "Bar",
   321  })
   322  
   323  // Delete it
   324  c.DeleteCreditCard("CARD-ID-123")
   325  
   326  // Edit it
   327  c.PatchCreditCard("CARD-ID-123", []paypal.CreditCardField{
   328      paypal.CreditCardField{
   329          Operation: "replace",
   330          Path:      "/billing_address/line1",
   331          Value:     "New value",
   332      },
   333  })
   334  
   335  // Get it
   336  c.GetCreditCard("CARD-ID-123")
   337  
   338  // Get all stored credit cards
   339  c.GetCreditCards(nil)
   340  ```
   341  
   342  ### Webhooks
   343  ```go
   344  // Create a webhook
   345  c.CreateWebhook(paypal.CreateWebhookRequest{
   346      URL: "webhook URL",
   347      EventTypes: []paypal.WebhookEventType{
   348          paypal.WebhookEventType{
   349              Name: "PAYMENT.AUTHORIZATION.CREATED",
   350          },
   351      },
   352  })
   353  
   354  // Update a registered webhook
   355  c.UpdateWebhook("WebhookID", []paypal.WebhookField{
   356      paypal.WebhookField{
   357          Operation: "replace",
   358          Path:      "/event_types",
   359          Value: []interface{}{
   360              map[string]interface{}{
   361                  "name": "PAYMENT.SALE.REFUNDED",
   362              },
   363          },
   364      },
   365  })
   366  
   367  // Get a registered webhook
   368  c.GetWebhook("WebhookID")
   369  
   370  // Delete a webhook
   371  c.DeleteWebhook("WebhookID")
   372  
   373  // List registered webhooks
   374  c.ListWebhooks(paypal.AncorTypeApplication)
   375  ```
   376  
   377  ### Generate Next Invoice Number
   378  ```go
   379  // GenerateInvoiceNumber: generates the next invoice number that is available to the merchant.
   380  c.GenerateInvoiceNumber(ctx) // might return something like "0001" or "0010".
   381  ```
   382  
   383  ### Get Invoice Details by ID
   384  ```go
   385  // the second argument is an ID, it should be valid
   386  invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33")
   387  ```
   388  * 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)
   389      ```bash
   390      curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \
   391      -H "Content-Type: application/json" \
   392      -H "Authorization: Bearer <Token>" 
   393      ```
   394  
   395  * refer to the beginning of this Usage section for obtaining a Token.
   396      
   397  
   398  ## How to Contribute
   399  
   400  * Fork a repository
   401  * Add/Fix something
   402  * Check that tests are passing
   403  * Create PR
   404  
   405  Current contributors:
   406  
   407  - [Roopak Venkatakrishnan](https://github.com/roopakv)
   408  - [Alex Pliutau](https://github.com/plutov)
   409  
   410  ## Tests
   411  
   412  * Unit tests: `go test -v ./...`
   413  * Integration tests: `go test -tags=integration`