creem

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

creem-go creem.io SDK implementation in Golang

Go Reference Go goreleaser GitHub go.mod Go version of a Go module GoReportCard GitHub license GitHub release

Installation

go install github.com/bububa/creem-go

Usage

Create Checkout Session
import (
    "github.com/bububa/creem-go"
    "github.com/bububa/creem-go/checkouts"
)
func main() {
  clt := creem.New(os.Getenv("CREEM_KEY"))
  req := checkouts.CreateRequest {
    ProductID: "xxx",
  }
  var ret checkouts.Checkout
  if err := checkouts.Create(context.Background(), &req, &ret); err != nil {
    panic(err)
  }
  fmt.Println(ret)
}
Get Checkout Session
import (
    "github.com/bububa/creem-go"
    "github.com/bububa/creem-go/checkouts"
)
func main() {
  clt := creem.New(os.Getenv("CREEM_KEY"))
  checkoutID := "xxx"
  var ret checkouts.Checkout
  if err := checkouts.Get(context.Background(), checkoutID, &ret); err != nil {
    panic(err)
  }
  fmt.Println(ret)
}
Webhook
package main

import (
    "fmt"
    "net/http"

    "github.com/bububa/creem-go/webhooks"
)

func eventHanderl(ctx context.Context, ev *webhooks.Event) error {
    fmt.Prinf("EVENT: %+v\n", ev)
    return nil
}

func main() {
    handler := webhooks.NewHandler(os.Getenv("CREEM_KEY"), eventHandler)
    http.HandleFunc("/", handler.ServeHTTP)

    port := ":8080"
    fmt.Printf("Starting server on http://localhost%s\n", port)
    if err := http.ListenAndServe(port, nil); err != nil {
        panic(err)
    }
}

For more details please check in pkg.go.dev

Documentation

Overview

Package creem creem.io golang SDK

Index

Constants

View Source
const (
	BaseURL     = "https://api.creem.io"
	TestBaseURL = "https://test-api.creem.io"
)

Variables

View Source
var (
	ErrUnknown           = errors.New("unknown error")
	ErrInvalidParameters = errors.New("check that the parameters were correct")
	ErrMissingAPIKey     = errors.New("the API key used was missing")
	ErrInvalidAPIKey     = errors.New("the API key used was invalid")
	ErrNoResourceFound   = errors.New("the resource was not found")
	ErrExceededRateLimit = errors.New("the rate limit was exceeded")
	ErrServerError       = errors.New("indicates an error with Creem servers")

	ErrCreateCheckoutSession = errors.New("create checkout session failed")
	ErrGetCheckoutSession    = errors.New("get checkout session failed")

	ErrCreateProduct = errors.New("create product failed")
	ErrGetProduct    = errors.New("get product failed")
	ErrListProduct   = errors.New("list products failed")

	ErrGetCustomer = errors.New("get customer failed")

	ErrListTransaction = errors.New("list transactions failed")

	ErrValidateLicense   = errors.New("validate license failed")
	ErrActivateLicense   = errors.New("activate license failed")
	ErrDeactivateLicense = errors.New("deactivate license failed")

	ErrCreateDiscount = errors.New("create discount failed")
	ErrDeleteDiscount = errors.New("delete discount failed")
	ErrGetDiscount    = errors.New("get discount failed")

	ErrGetSubscription     = errors.New("get subscription failed")
	ErrUpdateSubscription  = errors.New("update subscription failed")
	ErrUpgradeSubscription = errors.New("upgrade subscription failed")
	ErrCancelSubscription  = errors.New("cancel subscription failed")

	ErrInvalidSignature = errors.New("invalid signature")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(key string, opts ...Option) *Client

func (*Client) BaseURL

func (c *Client) BaseURL() string

func (*Client) Do

func (c *Client) Do(ctx context.Context, req Request, resp any) error

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(clt *http.Client) *Client

func (*Client) SetTestMode

func (c *Client) SetTestMode(v bool) *Client

func (*Client) SetVerbose added in v1.0.6

func (c *Client) SetVerbose(v bool) *Client

type CustomField added in v1.0.2

type CustomField struct {
	// Type the type of the field.
	Type CustomFieldType `json:"type,omitempty"`
	// Key Unique key for custom field. Must be unique to this field, alphanumeric, and up to 200 characters.
	// Maximum length: 200
	Key string `json:"key,omitempty"`
	// Label The label for the field, displayed to the customer, up to 50 characters
	Label string `json:"label,omitempty"`
	// Optional Whether the customer is required to complete the field. Defaults to false
	Optional bool `json:"optional,omitempty"`
	// Text configuration for type of text field.
	Text *TextField `json:"text,omitempty"`
}

CustomField collect additional information from your customer using custom fields. Up to 3 fields are supported.

type CustomFieldType added in v1.0.2

type CustomFieldType string

CustomFieldType the type of the field.

const (
	TextFieldType CustomFieldType = "text"
)

type DeleteRequest added in v1.0.2

type DeleteRequest struct{}

func (DeleteRequest) Method added in v1.0.2

func (r DeleteRequest) Method() string

type GetRequest added in v1.0.2

type GetRequest struct{}

func (GetRequest) Method added in v1.0.2

func (r GetRequest) Method() string

type Mode

type Mode string
const (
	TestMode    Mode = "test"
	ProdMode    Mode = "prod"
	SandboxMode Mode = "sandbox"
	LocalMode   Mode = "local"
)

type Option

type Option func(*Client)

func WithHTTPClient

func WithHTTPClient(clt *http.Client) Option

func WithTestMode

func WithTestMode(v bool) Option

func WithVerbose added in v1.0.6

func WithVerbose(v bool) Option

type Pagination

type Pagination struct {
	// TotalRecords Total number of records in the list
	TotalRecords int64 `json:"total_records,omitempty"`
	// TotalPages Total number of pages available
	TotalPages int64 `json:"total_pages,omitempty"`
	// CurrentPage The current page number
	CurrentPage int64 `json:"current_page,omitempty"`
	// NextPage The next page number, or null if there is no next page
	NextPage int64 `json:"next_page,omitempty"`
	// PrevPage The previous page number, or null if there is no previous page
	PrevPage int64 `json:"prev_page,omitempty"`
}

Pagination details for the list

type PostRequest added in v1.0.2

type PostRequest struct{}

func (PostRequest) Method added in v1.0.2

func (r PostRequest) Method() string

type Request added in v1.0.2

type Request interface {
	Gateway() string
	Method() string
}

type TextField added in v1.0.2

type TextField struct {
	// MaxLength Maximum character length constraint for the input.
	MaxLength int `json:"max_length,omitempty"`
	// MinLength Minimum character length requirement for the input.
	MinLength int `json:"min_length,omitempty"`
}

TextField configuration for type of text field.

Directories

Path Synopsis
Package checkouts Checkout related APIs
Package checkouts Checkout related APIs
Package customers Customers related API
Package customers Customers related API
Package discounts Discount related APIs
Package discounts Discount related APIs
Package products Product related APIs
Package products Product related APIs
Package subscriptions includes Subscriptions related APIs
Package subscriptions includes Subscriptions related APIs
Package transactions Transactions related API
Package transactions Transactions related API
Package webhooks webhooks related Utilities
Package webhooks webhooks related Utilities

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL