Golang SDK

The Go SDK provides a clean and idiomatic Go interface for integrating with BagelPay.

The BagelPay Golang SDK is available as on GitHub for those who prefer to explore the source code directly.

The API document is here.

📦 Installation Guide

go get github.com/bagelpay/bagelpay-sdk-go

🚀 Quick Start

30-Second Quick Demo

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/bagelpay/bagelpay-sdk-go/src/bagelpay"
)

func main() {
	// Initialize the client
	client := bagelpay.NewClient(bagelpay.ClientConfig{
		APIKey:   "your-api-key",
		TestMode: true,
	})

	ctx := context.Background()

	// Create a product
	product, err := client.CreateProduct(ctx, bagelpay.CreateProductRequest{
		Name:              fmt.Sprintf("Premium Subscription %d", time.Now().Unix()),
		Description:       "Monthly premium subscription with unique identifier",
		Price:             29.99,
		Currency:          "USD",
		BillingType:       "subscription",
		TaxInclusive:      false,
		TaxCategory:       "digital_products",
		RecurringInterval: "monthly",
		TrialDays:         7,
	})

	if err != nil {
		log.Fatalf("Failed to create product: %v", err)
	}

	fmt.Printf("✅ Product URL: %s\n", *product.ProductURL)
}

Core Features

🛍️ Product Management

  • Create and manage products

  • Support for both subscriptions and one-time payments

  • Flexible pricing and billing intervals

  • Tax configuration options

💳 Checkout & Payments

  • Secure checkout session creation

  • Customizable success/cancel URLs

  • Metadata support for tracking

  • Real-time payment status

👥 Customer Management

  • Customer creation and retrieval

  • Subscription management

  • Payment history tracking

📊 Analytics & Reporting

  • Transaction listing and filtering

  • Subscription analytics

  • Customer insights

API Reference

Client Initialization

Convenience Constructors

Products

Create Product

List Products

Get Product

Update Product

Archive/Unarchive Product

Checkout

Create Checkout Session

Transactions

List Transactions

Subscriptions

List Subscriptions

Get Subscription

Cancel Subscription

Customers

List Customers

Error Handling

The SDK provides specific error types for better error handling:

Error Types

  • BagelPayError: Base error type

  • BagelPayAPIError: API-specific errors

  • BagelPayAuthenticationError: Authentication failures (401)

  • BagelPayValidationError: Request validation errors (400)

  • BagelPayNotFoundError: Resource not found errors (404)

  • BagelPayRateLimitError: Rate limit exceeded (429)

  • BagelPayServerError: Server-side errors (5xx)

Go Type Support

The SDK provides full Go type definitions and helper functions:

Environment Configuration

Test Mode

Use test mode for development and testing:

Production Mode

For production environments:

🚀 Webhook Integration

Examples

The SDK includes comprehensive examples in the examples/ directory:

  • Basic Usage (examples/basic_usage/): Complete SDK functionality demonstration

  • Checkout Payments (examples/checkout_payments/): Various checkout scenarios

  • Product Management (examples/product_management/): Product CRUD operations

  • Subscription & Customer Management (examples/subscription_customer_management/): Subscription and customer operations

To run an example:

Support

Last updated