https://github.com/krasun/paddle
A Paddle API client for Go
https://github.com/krasun/paddle
Last synced: 2 months ago
JSON representation
A Paddle API client for Go
- Host: GitHub
- URL: https://github.com/krasun/paddle
- Owner: krasun
- License: mit
- Created: 2022-05-09T17:57:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-03T15:01:19.000Z (about 2 years ago)
- Last Synced: 2025-07-15T07:35:33.804Z (3 months ago)
- Language: Go
- Size: 53.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# paddle
[](https://github.com/krasun/paddle/actions/workflows/build.yml)
[](https://codecov.io/gh/krasun/paddle)
[](https://goreportcard.com/report/github.com/krasun/paddle)
[](https://godoc.org/github.com/krasun/paddle)A [Paddle API](https://www.paddle.com/) client for Go.
## Installation
```shell
go get github.com/krasun/paddle
```## Usage
Import the library:
```go
import "github.com/krasun/paddle"
```Calling API methods:
```go
var paddleClient *paddle.Client
switch environment {
case "sandbox":
paddleClient, err = paddle.NewSandboxClient(paddle.Authentication{paddleVendorID, paddleVendorAuthCode})
if err != nil {
log.Fatalf("failed to instantiate paddle %s client: %s", environment, err)
return
}
case "production":
paddleClient, err = paddle.NewProductionClient(paddle.Authentication{paddleVendorID, paddleVendorAuthCode})
if err != nil {
log.Fatalf("failed to instantiate paddle %s client: %s", environment, err)
return
}
default:
log.Fatalf("unsupported Paddle environment: %s", environment)
return
}options := &paddle.UpdateUserOptions{
// ...
Prorate: true,
BillImmediately: true,
// ...
}
response, _, err := paddleClient.Users.Update(ctx, options)
if err != nil {
log.Error(err)
return
}
```Handling webhooks:
```go
webhooks, err := paddle.NewWebhooks(paddlePublicKey)
if err != nil {
log.Fatalf("failed to instantiate Paddle webhooks client: %s", err)
return
}func handlePaddleWebhooks(webhooks *paddle.Webhooks, payments *payments) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()alert, err := webhooks.ParseRequest(r)
if err != nil {
log.Error(err)
http.Error(w, "Sorry, something went wrong", http.StatusInternalServerError)
return
}switch alert := alert.(type) {
// ...
case *paddle.SubscriptionCreatedAlert:
err := payments.processSubscriptionCreated(ctx, alert)
if err != nil {
log.Error(err)
http.Error(w, "Sorry, something went wrong", http.StatusInternalServerError)
return
}
case *paddle.SubscriptionUpdatedAlert:
// ...
return
case *paddle.SubscriptionCancelledAlert:
// ...
return
// ...
}
}
}
```## Tests
To run tests, just execute:
```
$ go test .
```## License
`paddle` is released under [the MIT license](LICENSE).