go-paddle is a Go client library for accessing the Paddle API.

Overview

go-paddle

go-paddle release (latest SemVer) Test Status

go-paddle is a Go client library for accessing the Paddle API.

Installation

go get github.com/Fakerr/go-paddle

Alternatively the same can be achieved if you use import in a package:

import "github.com/Fakerr/go-paddle"

and run go get without paramters.

Usage

The package paddle comes with two different clients. A client for the Product, Subscription, Alert APIs that will require a vendor_id and a vendor_auth_code and a client for the Checkout API.

The services of a client divide the API into logical chunks and correspond to the structure of the Paddle API documentation at https://developer.paddle.com/api-reference/.

Product API, Subscription API, Alert API

import "github.com/Fakerr/go-paddle/paddle"

Construct a new Paddle client, then use the various services on the client to access different parts of the Paddle API. The client always requires a vendor_id and a vendor_auth_code arguments that you can get from the Paddle dashboard. For example:

client := paddle.NewClient(vendorId, vendorAuthCode, nil)

// List all users subscribed to any of your subscription plans
users, _, err := client.Users.List(context.Background(), nil)

Some API methods have optional parameters that can be passed. For example:

client := paddle.NewClient(vendorId, vendorAuthCode, nil)

// List all users subscribed to any of your subscription plans
opt := &UsersOptions{SubscriptionID: "1"}
users, _, err := client.Users.List(context.Background(), opt)

NOTE: Using the context package, one can easily pass cancelation signals and deadlines to various services of the client for handling a request. In case there is no context available, then context.Background() can be used as a starting point.

For more sample code snippets, head over to the example directory.

Checkout API

import "github.com/Fakerr/go-paddle/paddle"

Construct a new Paddle checkout client, then use the various services on the client to access different parts of the Paddle API.

client := paddle.NewCheckoutClient(nil)

// Retrieve prices for one or multiple products or plans
options := &PricesOptions{CustomerCountry: "tn"}
prices, _, err := client.Prices.Get(context.Background(), "1", options)

Sandbox environment

If you want to send requests against a sandbox environment, the package paddle provides two specific clients for that purpose:

client := paddle.NewSandboxClient(sandboxVendorId, sandboxVendorAuthCode, nil)

or to access the checkout API

client := paddle.NewSandboxCheckoutClient(nil)

Pagination

Some requests for resource collections (users, webhooks, etc.) support pagination. Pagination options are described in the paddle.ListOptions struct and passed to the list methods directly or as an embedded type of a more specific list options struct (for example paddle.UsersOptions).

client := paddle.NewClient(vendorId, vendorAuthCode, nil)

// List all users subscribed to any of your subscription plans
opt := &UsersOptions{
	SubscriptionID: "1",
	ListOptions: ListOptions{Page: 2},
}
users, _, err := client.Users.List(context.Background(), opt)

Webhooks

go-paddle comes with helper functions in order to facilitate the validatation and parsing of webhook events. For recognized event types, a value of the corresponding struct type will be returned.

Example usage:

func PaddleWebhookHandler(w http.ResponseWriter, r *http.Request) {
   payload, err := paddle.ValidatePayload(r, webhookSecretKey)
   if err != nil { ... }

   alert, err := paddle.ParsePayload(payload)
   if err != nil { ... }

   switch alert := alert.(type) {
   case *paddle.SubscriptionCreatedAlert:
       processSubscriptionCreatedAlert(alert)
   case *paddle.SubscriptionCanceledAlert:
       processSubscriptionCanceledAlert(alert)
   ...
   }
}

Todos

List of Paddle APIs that are not covered yet or are work in progress:

  • Licenses
  • Transactions

Contributing

Pull requests are welcome, along with any feedback or ideas. The calling pattern is pretty well established, so adding new methods is relatively straightforward.

License

This library is distributed under the MIT-style license found in the LICENSE file.

You might also like...
A High-level Machine Learning Library for Go
A High-level Machine Learning Library for Go

Overview Goro is a high-level machine learning library for Go built on Gorgonia. It aims to have the same feel as Keras. Usage import ( . "github.

Library for multi-armed bandit selection strategies, including efficient deterministic implementations of Thompson sampling and epsilon-greedy.
Library for multi-armed bandit selection strategies, including efficient deterministic implementations of Thompson sampling and epsilon-greedy.

Mab Multi-Armed Bandits Go Library Description Installation Usage Creating a bandit and selecting arms Numerical integration with numint Documentation

Bigmachine is a library for self-managing serverless computing in Go

Bigmachine Bigmachine is a toolkit for building self-managing serverless applications in Go. Bigmachine provides an API that lets a driver process for

A high performance go implementation of Wappalyzer Technology Detection Library

wappalyzergo A high performance port of the Wappalyzer Technology Detection Library to Go. Inspired by https://github.com/rverton/webanalyze. Features

A high-performance timeline tracing library for Golang, used by TiDB

Minitrace-Go A high-performance, ergonomic timeline tracing library for Golang. Basic Usage package main import ( "context" "fmt" "strcon

Self-contained Machine Learning and Natural Language Processing library in Go
Self-contained Machine Learning and Natural Language Processing library in Go

Self-contained Machine Learning and Natural Language Processing library in Go

Go (Golang) encrypted deep learning library; Fully homomorphic encryption over neural network graphs

DC DarkLantern A lantern is a portable case that protects light, A dark lantern is one who's light can be hidden at will. DC DarkLantern is a golang i

Bcfm-study-case - A simple http server using the Echo library in Go language
Bcfm-study-case - A simple http server using the Echo library in Go language

Task 1 Hakkında Burada Go dilinde Echo kütüphanesini kullanarak basit bir http s

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

NotionGo is a Go client library for accessing the Notion API v1.

NotionGo (WIP) NotionGo is a Go client library for accessing the Notion API v1. Installation NotionGo is compatible with modern Go releases in module

go-ftx go-ftx is a Go client library for accessing the FTX API

go-ftx go-ftx is a Go client library for accessing the FTX API

Go client library for accessing the Football Data API

football-data-sdk football-data-sdk is a Go client library for accessing the Football Data API. Successful queries return native Go structs. Services

Client library with golang for accessing Harbor API.

go-client Client library with golang for accessing Harbor API. Client Types There are 3 swagger files in this repo. api/ v2.0/ legacy_swag

brickset is a Go client library for accessing the brickset.com API v3.

brickset is a Go client library for accessing the brickset.com API v3.

Go library for accessing the MyAnimeList API: http://myanimelist.net/modules.php?go=api

go-myanimelist go-myanimelist is a Go client library for accessing the MyAnimeList API. Project Status The MyAnimeList API has been stable for years a

Go(lang) client library for accessing information of an Apache Mesos cluster.

megos Go(lang) client library for accessing an Apache Mesos cluster. Features Determine the Mesos leader Get the current state of every mesos node (ma

A GoLang wrapper for Politics & War's API. Forego the hassle of accessing the API directly!

A GoLang wrapper for Politics & War's API. Forego the hassle of accessing the API directly!

Go library for accessing the Codeship API v2

Codeship API v2 Client for Go Codeship API v2 client for Go. Documentation https://godoc.org/github.com/codeship/codeship-go Usage go get -u github.co

Comments
  • fix invalid Payment.IsOneOffCharge type

    fix invalid Payment.IsOneOffCharge type

    • api docs & returned type differs (expected int, got bool)

    https://developer.paddle.com/api-reference/b3A6MzA3NDQ3MzY-list-payments

    Response example on the left has boolean value for key is_one_off_charge, which causes the error.

    Added custom unmarshaller and temporary structure.

    opened by jancimertel 0
  • Coupons.Create returns empty coupon array

    Coupons.Create returns empty coupon array

    Paddle probably returns a 200 response, no error, but also an empty coupon string array

    My guess it that the response is 200, but the actuall success field is false and the error is not properly read from the error field since it only parses the successful response object.

    The coupon is created on paddle though.

    opened by eaigner 0
Releases(v1.1.0)
Owner
Walid Berrahal
Software Engineer
Walid Berrahal
Go Scoring API for PMML

Goscore Go scoring API for Predictive Model Markup Language (PMML). Currently supports Neural Network, Decision Tree, Random Forest and Gradient Boost

Asaf Schers 84 Dec 24, 2022
A simple OCR API server, seriously easy to be deployed by Docker, on Heroku as well

ocrserver Simple OCR server, as a small working sample for gosseract. Try now here https://ocr-example.herokuapp.com/, and deploy your own now. Deploy

Hiromu OCHIAI 541 Dec 28, 2022
Suricate-bank - API to transfer money between accounts at Suricate Bank,written in Go

⚠️ WORK IN PROGRESS ⚠️ Suricate Bank is an api that creates accounts and transfe

João Saraceni 12 Oct 8, 2022
Genetic Algorithms library written in Go / golang

Description Genetic Algorithms for Go/Golang Install $ go install git://github.com/thoj/go-galib.git Compiling examples: $ git clone git://github.com

Thomas Jager 193 Sep 27, 2022
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Gorgonia 4.8k Dec 30, 2022
Go package for OCR (Optical Character Recognition), by using Tesseract C++ library

gosseract OCR Golang OCR package, by using Tesseract C++ library. OCR Server Do you just want OCR server, or see the working example of this package?

Hiromu OCHIAI 2k Jan 3, 2023
onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.

This is a Go Interface to Open Neural Network Exchange (ONNX). Overview onnx-go contains primitives to decode a onnx binary model into a computation b

Olivier Wulveryck 456 Dec 24, 2022
A neural network library built in Go

go-mind A neural network library built in Go. Usage import "github.com/stevenmiller888/go-mind" m := mind.New(0.7, 10000, 3, "sigmoid") m.Learn([][]

Steven Miller 166 Aug 27, 2022
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Gorgonia 4.8k Dec 27, 2022
A Go library implementing an FST (finite state transducer)

vellum A Go library implementing an FST (finite state transducer) capable of: mapping between keys ([]byte) and a value (uint64) enumerating keys in l

bleve 134 Jan 8, 2023