Golang client for PayPal REST API

Overview

Go Report Card Build Status Godoc

Go client for PayPal REST API

Coverage

  • POST /v1/oauth2/token
  • POST /v1/identity/openidconnect/tokenservice
  • GET /v1/identity/openidconnect/userinfo/?schema=SCHEMA
  • POST /v1/payments/payouts
  • GET /v1/payments/payouts/ID
  • GET /v1/payments/payouts-item/ID
  • POST /v1/payments/payouts-item/ID/cancel
  • GET /v1/payment-experience/web-profiles
  • POST /v1/payment-experience/web-profiles
  • GET /v1/payment-experience/web-profiles/ID
  • PUT /v1/payment-experience/web-profiles/ID
  • DELETE /v1/payment-experience/web-profiles/ID
  • GET /v2/payments/authorizations/ID
  • POST /v2/payments/authorizations/ID/capture
  • POST /v2/payments/authorizations/ID/void
  • POST /v2/payments/authorizations/ID/reauthorize
  • GET /v1/payments/sale/ID
  • POST /v1/payments/sale/ID/refund
  • GET /v2/payments/refund/ID
  • POST /v1/reporting/transactions

Vault

  • POST /v1/vault/credit-cards
  • DELETE /v1/vault/credit-cards/ID
  • PATCH /v1/vault/credit-cards/ID
  • GET /v1/vault/credit-cards/ID
  • GET /v1/vault/credit-cards

Checkout

  • POST /v2/checkout/orders
  • GET /v2/checkout/orders/ID
  • PATCH /v2/checkout/orders/ID
  • POST /v2/checkout/orders/ID/authorize
  • POST /v2/checkout/orders/ID/capture

Billing plans (payments)

  • GET /v1/payments/billing-plans
  • POST /v1/payments/billing-plans
  • PATCH /v1/payments/billing-plans/ID
  • POST /v1/payments/billing-agreements
  • POST /v1/payments/billing-agreements/TOKEN/agreement-execute

Notifications

  • POST /v1/notifications/webhooks
  • GET /v1/notifications/webhooks
  • GET /v1/notifications/webhooks/ID
  • PATCH /v1/notifications/webhooks/ID
  • DELETE /v1/notifications/webhooks/ID
  • POST /v1/notifications/verify-webhook-signature

Products (Catalog)

  • POST /v1/catalogs/products
  • PATCH /v1/catalogs/products/ID
  • GET /v1/catalogs/products/ID
  • GET /v1/catalogs/products

Billing Plans (Subscriptions)

  • POST /v1/billing/plans
  • PATCH /v1/billing/plans/ID
  • GET /v1/billing/plans/ID
  • GET /v1/billing/plans
  • POST /v1/billing/plans/ID/activate
  • POST /v1/billing/plans/ID/deactivate
  • POST /v1/billing/plans/ID/update-pricing-schemes

Subscriptions

  • POST /v1/billing/subscriptions
  • PATCH /v1/billing/subscriptions/ID
  • GET /v1/billing/subscriptions/ID
  • POST /v1/billing/subscriptions/ID/activate
  • POST /v1/billing/subscriptions/ID/cancel
  • POST /v1/billing/subscriptions/ID/revise
  • POST /v1/billing/subscriptions/ID/capture
  • POST /v1/billing/subscriptions/ID/suspend
  • GET /v1/billing/subscriptions/ID/transactions

Missing endpoints

It is possible that some endpoints are missing in this SDK Client, but you can use built-in paypal functions to perform a request: NewClient -> NewRequest -> SendWithAuth

Usage

import "github.com/plutov/paypal/v4"

// Create a client instance
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
c.SetLog(os.Stdout) // Set log to terminal stdout

accessToken, err := c.GetAccessToken(context.Background())

How to Contribute

  • Fork a repository
  • Add/Fix something
  • Check that tests are passing
  • Create PR

Current contributors:

Tests

  • Unit tests: go test -v ./...
  • Integration tests: go test -tags=integration
Comments
  • Add examples to handle errors in documentation

    Add examples to handle errors in documentation

    Sometimes paypal returns errors like:

    400 Invalid request - see details

    And we have to type assert the error to get the details field but currently, in README.md there's no examples of error handling.

    opened by emigr2k1 9
  • add context

    add context

    What does this PR do?

    • add ctx argument to all request functions
    • update module version to v4
    • update minimum go version to 1.13
    • add GetWebhookEventTypes (in separate commit)

    these two integrations tests fails the same way before and after the change.

    -- FAIL: TestCreateVenmoPayout (0.51s)
        integration_test.go:69:
            	Error Trace:	integration_test.go:69
            	Error:      	Received unexpected error:
            	            	POST https://api.sandbox.paypal.com/v1/payments/payouts: 400 User business error., []
            	Test:       	TestCreateVenmoPayout
            	Messages:   	should accept venmo wallet
        assertion_compare.go:211:
            	Error Trace:	integration_test.go:70
            	Error:      	"0" is not greater than "0"
            	Test:       	TestCreateVenmoPayout
            	Messages:   	[]
    --- FAIL: TestStoreCreditCard (0.67s)
        integration_test.go:119: 200 code expected for valid CC card. Error: POST https://api.sandbox.paypal.com/v1/vault/credit-cards: 400 Invalid request - see details, [{Field:expire_month, expire_year Issue:Invalid expiration (cannot be in the past) Links:[]}]
    

    I created this patch using this script + fix all resulting compiler errors:

    files="authorization.go billing.go identity.go order.go payout.go products.go sale.go subscription.go subscription_plan.go transaction_search.go vault.go webhooks.go webprofile.go"
    
    sed -i 's/c.NewRequest(/c.NewRequest(ctx, /' ${files}
    sed -i 's/http.NewRequest(/http.NewRequestWithContext(ctx, /' ${files} client.go
    sed -r -i 's/func \(c \*Client\) ([^(]+)\((.*)/func (c *Client) \1\(ctx context.Context, \2/g' ${files}
    
    goimports -w .
    
    opened by thomasf 7
  • is there a plan support the api Version 2?

    is there a plan support the api Version 2?

    thanks for your paypal sdk for go! paypal has upgraded some api (Payments/Orders) to Version 2 and recommend to upgrade to Version 2; image Is there a plan to support Version 2?

    opened by YouEclipse 7
  • Get Order - Incomplete response object

    Get Order - Incomplete response object

    According to the documentation, returned struct from the endpoint // Endpoint: GET /v2/checkout/orders/ID is incomplete (PurchaseUnit, Shipping Address).

    Please add missing fields (shipping info, also shipping address JSON keys are invalid - line_1 instead of address_line_1, etc.), CapturedPurchaseUnit instead of `PurchaseUnit, etc.

    opened by DarioNevistic 5
  • Can't fill in all the required fields for CaptureOrderRequest while using paypal sandbox

    Can't fill in all the required fields for CaptureOrderRequest while using paypal sandbox

    Hi I am currently trying out this sdk before we decide to use it for our team, but I am unable to perform capture order correctly because fields like Billing Address and Security code in card information are not provided as part of the sandbox accounts. Can someone please help me unblock this ?

    opened by archthegit 5
  • Go Modules support

    Go Modules support

    We have already released v2, which means things are slightly different for us.

    Based on the suggestions here: https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

    We will go with the branch strategy.

    We will not create a new branch since we dont have CLI this should not break anyone since there is no reason to go get -u this package.

    LMK if you think we might be better off doing the directory version of support.

    Once we have this in place we can start a bit of refactoring :)

    opened by roopakv 5
  • Order ID Type Alias

    Order ID Type Alias

    I recently misinterpreted Paypal documentation causing me to treat the ID field for a capture response as a unique identifier for the capture event and not the order id. It occurs to me that this type of mistake would be harder to make if instead of strings the responses had type aliases defined.

    For instance:

    type OrderID string
    
    // CaptureOrderResponse is the response for capture order
    CaptureOrderResponse struct {
    	ID            OrderID                 `json:"id,omitempty"`
    	Status        string                 `json:"status,omitempty"`
    	Payer         *PayerWithNameAndPhone `json:"payer,omitempty"`
    	Address       *Address               `json:"address,omitempty"`
    	PurchaseUnits []CapturedPurchaseUnit `json:"purchase_units,omitempty"`
    }
    

    This would help the code be more self-documenting and hopefully prevent the issue I ran into. I am interested to hear your thoughts or suggestions on this?

    If it's acceptable, I would be happy to prep a PR targeting all order id fields in the defined payloads and swap with this new type.

    opened by jalandis 4
  • Include the 'items' in the response when capturing orders

    Include the 'items' in the response when capturing orders

    This was a requirement on a project I worked on, not sure if this will be helpful to the greater community? Thanks a lot for the great codebase. Cheers :)

    opened by chrishulbert 4
  • How can i verify payment?

    How can i verify payment?

    p, _ := paypal.NewClient("myClientId", "mySecret", paypal.APIBaseLive)
    token, _ = p.GetAccessToken()
    

    This code works just fine, in token var i got bearer token in key "access_token". And i have 17 length id that i got after made payment. How can i get status or something of this payment with this code?

    opened by shizzic 3
  • feat: Add missing fields into ErrorResponseDetail

    feat: Add missing fields into ErrorResponseDetail

    What does this PR do?

    This PR adds name and message fields into ErrorResponseDetail struct.

    Where should the reviewer start?

    types.go

    How should this be manually tested?

    Unmarshal an example response below using the ErrorResponse struct.

    Any background context you want to provide?

    These fields are not documented anywhere in the official documentation yet, but actually exists in an errored response:

    {
      "name": "BUSINESS_ERROR",
      "debug_id": "[REDACTED]",
      "message": "Business error",
      "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_ERROR",
      "details": [
        {
          "name": "TOKEN_NOT_FOUND",
          "message": "Not Found: Invalid BA-Token Identifier"
        }
      ]
    }
    
    opened by siketyan 3
  • Add cancel billing agreement function

    Add cancel billing agreement function

    What does this PR do?

    Adds function to allow users to cancel billing agreements with the id and a note (reason)

    Where should the reviewer start?

    The function is just hitting the cancel endpoint with an id

    How should this be manually tested?

    The function is hitting the endpoint with an id, there is a unit test as well

    Any background context you want to provide?

    follow api at https://developer.paypal.com/docs/limited-release/reference-transactions/#cancel-billing-agreement

    opened by rohanr-bolt 3
  • Removing deprecations

    Removing deprecations

    Hi. Thanks for your great job.

    Do you plan to replace application_context with https://developer.paypal.com/docs/api/orders/v2/#definition-application_context with experience_context ?

    Thanks.

    opened by voodoo-dn 1
  • POST https://api.sandbox.paypal.com/v2/checkout/orders: 401 Authentication failed due to invalid authentication credentials or a missing Authorization header.

    POST https://api.sandbox.paypal.com/v2/checkout/orders: 401 Authentication failed due to invalid authentication credentials or a missing Authorization header.

    The order is being created as in the testing (because the docs are not updated) and returning 401 authentication failed when creating an order

    c, err := paypal.NewClient(
      clientId,
      secret,
      paypal.APIBaseSandBox,
    )
    if err != nil {
      panic(err)
    }
    // c.SetLog(os.Stdout)
    
    ApplicationContext := &paypal.ApplicationContext{
      BrandName: "Imajo Broqueles",
      Locale:    "es-MX",
    }
    
    OrderPayer := &paypal.CreateOrderPayer{}
    
    PurchaseUnit := paypal.PurchaseUnitRequest{
      Amount: &paypal.PurchaseUnitAmount{
        Currency: "MXN",
        Value:    "100.00",
        Breakdown: &paypal.PurchaseUnitAmountBreakdown{
          ItemTotal: &paypal.Money{Currency: "MXN", Value: "100.00"},
        },
      },
    }
    
    // Create a new order
    
    paypalOrder, err := c.CreateOrder(
      context.Background(),
      paypal.OrderIntentCapture,
      []paypal.PurchaseUnitRequest{PurchaseUnit},
      OrderPayer,
      ApplicationContext,
    )
    
    if err != nil {
      fmt.Println(err)
      return
    }
    
    opened by gdlazcano 3
  • Suggestion: Mark all functions that represent deprecated paypal api resources as deprecated in godoc comment.

    Suggestion: Mark all functions that represent deprecated paypal api resources as deprecated in godoc comment.

    A comment string`that looks something like this so they are clearly marked in godoc

    // Deprecated: This API resource is deprecated by PayPal.
    

    Just to make godoc clearer like this https://pkg.go.dev/github.com/plutov/paypal/v4#Resource

    opened by thomasf 1
Releases(v4.7.0)
Owner
Alex Pliutau
Gopher https://www.youtube.com/packagemain
Alex Pliutau
Edtienda - PayPal Integration Course Code

PayPal Integration Para ejecutar el código debes realizar los siguientes pasos:

EDteam 1 Feb 3, 2022
Clusterpedia-client - clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Calvin Chen 4 Jan 7, 2022
Client-go - Clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

clusterpedia.io 9 Oct 25, 2022
go-whatsapp-rest-API is a Go library for the WhatsApp web which use Swagger as api interface

go-whatsapp-rest-API go-whatsapp-rest-API is a Go library for the WhatsApp web which use Swagger as api interface Multi-devices (MD) Support. This ver

null 17 Nov 30, 2022
Api-product - A basic REST-ish API that allows you to perform CRUD operations for Products

Description A basic REST-ish API that allows you to perform CRUD operations for

Abdul Salim 0 Jan 3, 2022
Lol-champions-api - A REST API app for CRUD' ing informations related to League of Legends champions, written with Go

LOL-CHAMPIONS-API Just a REST API app for CRUD' ing informations related to Leag

Furkan KARACA 3 Mar 17, 2022
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Kinesumer is a Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

당근마켓 69 Nov 28, 2022
A rest-api that works with golang as coin portfolio

Koinfolio A rest-api that works with golang as coin portfolio Technical Details Golang/Gin is used as application framework MongoDB is database Usage

Kürşad BİLGİN 2 Jun 1, 2022
Rest Api server, написанный на Golang

Задача: создать простой REST API, который будет позволять получать информацию про пиццу. Шаг 1. Желаемый функционал. Хотим собрать простой веб-сервер,

Ilya Shevchenko 0 Aug 26, 2022
Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Una prueba técnica: Servicio Golang REST API local, sobre Docker, gRPC, AWS Serverless y sobre Kubernetes en AWS EC2

Emilio del Cañal Calleja 4 May 7, 2022
Nutanix-client-go - Go client for the Nutanix Prism V3 API

nutanix-client-go This repository contains portions of the Nutanix API client code in nutanix/terraform-provider-nutanix. It has been extracted to red

Marvin Beckers 0 Jan 6, 2022
An API client for the Notion API implemented in Golang

An API client for the Notion API implemented in Golang

Anatoly Nosov 347 Nov 27, 2022
Client-server-golang-sqs - Client Server with SQS and golang

Client Server with SQS and golang Multi-threaded client-server demo with Go What

null 0 Feb 14, 2022
Go Twitter REST and Streaming API v1.1

go-twitter go-twitter is a Go client library for the Twitter API. Check the usage section or try the examples to see how to access the Twitter API. Fe

Dalton Hubble 1.6k Dec 8, 2022
Unofficial Go SDK for GoPay Payments REST API

Unofficial Go SDK for GoPay Payments REST API Installation go get https://github.com/apparently-studio/gopay-go-api Basic usage client := gopay.NewCl

Apparently Studio 3 Nov 18, 2022
Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs

PnPjs is a fluent JavaScript API for consuming SharePoint and Microsoft Graph REST APIs in a type-safe way. You can use it with SharePoint Framework,

Microsoft 365 Community 628 Dec 7, 2022
Use Google REST api to extract your personal Photo Library

Photo Go A better approach to extracting your photos from Google to your personal cloud. I'm moving my photos out of Google to a Synology NAS. create

James 2 Dec 7, 2021
A REST API microservices-based Twitter Clone server.

Simple API Twitter Clone A REST API microservices-based project to fetch, edit, post, and delete tweets. API documentation The API documentation is bu

null 1 May 13, 2022
Go REST API for movies

Greenlight API Greenlight is an api, i implemented by following the book Let's Go Further by Alex Edwards If you like what you see please consider buy

Ricardo Ribeiro 1 Jul 17, 2022