Go SDK for the Atlos Gateway API, generated from OpenAPI specification.
This SDK provides a client and mock server implementation for the Atlos Payment Gateway API.
- Generated Client: HTTP client methods for all API endpoints
- Mock Server: Standard
net/httpserver implementation with postback notification support - Postback Handling: HMAC-SHA256 signature verification for payment confirmations
go get go.lumeweb.com/atlos-sdkThe client wraps the generated HTTP client and handles API secret authentication automatically.
package main
import (
"context"
"log"
"go.lumeweb.com/atlos-sdk"
)
func main() {
// Create a new client with your API secret
client, err := atlos.NewClient("your-api-secret")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Example: Create a payment
req := atlos.CreatePaymentPostRequest{
AssetCode: "USDC",
BlockchainCode: 1, // ETH blockchain code (numeric)
InvoiceId: "invoice-123",
IsEvm: "true",
UserAddress: nil,
}
payment, err := client.CreatePayment(ctx, req)
if err != nil {
log.Fatal(err)
}
log.Printf("Payment ID: %s", *payment.Id)
}Note: The SDK re-exports all generated types from the internal/client package at the top level for convenience. Types like CreatePaymentPostRequest, Payment, Asset, etc. are available directly from the atlos package without needing to import the internal package.
You can configure the client with options:
client, err := atlos.NewClient(
"your-api-secret",
atlos.WithEndpoint("https://custom-endpoint.example.com"),
)The client provides wrapper methods for all API endpoints:
| Method | Description | Returns |
|---|---|---|
AssetList(ctx, req) |
List available assets | []Asset, error |
InvoiceCreate(ctx, req) |
Create a new invoice | *InvoiceResponse, error |
InvoiceCancel(ctx, req) |
Cancel an invoice | error |
CreatePayment(ctx, req) |
Create a new payment | *Payment, error |
PaymentGet(ctx, req) |
Get payment details | *Payment, error |
SendToken(ctx, req) |
Send tokens to recipient | *SendTokenPostResponseBody, error |
CancelPayout(ctx, req) |
Cancel a payout | error |
FindByHash(ctx, req) |
Find transaction by hash | *FindByHashPostResponseBody, error |
TransactionList(ctx, req) |
List transactions | *TransactionListPostResponseBody, error |
Cancel(ctx, req) |
Cancel subscription | error |
PaymentWebSocket(ctx, req) |
Get WebSocket token for updates | []byte, error |
req := atlos.AssetListPostRequest{
MerchantId: "merchant-123",
OrderAmount: 100.0,
}
assets, err := client.AssetList(ctx, req)
if err != nil {
log.Fatal(err)
}
for _, asset := range assets {
log.Printf("Asset: %s (Code: %s)", *asset.Name, *asset.Code)
}req := atlos.InvoiceCreatePostRequest{
// Populate request fields
}
invoice, err := client.InvoiceCreate(ctx, req)
if err != nil {
log.Fatal(err)
}
log.Printf("Invoice created: %s", *invoice.Id)
}The mock server provides a full implementation of the API interface for testing, with support for postback notifications.
package main
import (
"log"
"net/http"
"go.lumeweb.com/atlos-sdk"
)
func main() {
// Create server with postback configuration
server, err := atlos.NewServer(
atlos.WithPostbackURL("https://example.com/postback"),
atlos.WithSharedSecret("your-api-secret"),
atlos.WithPostbackMode(atlos.PostbackImmediate),
)
if err != nil {
log.Fatal(err)
}
// Start server
handler := server.Handler()
log.Println("Starting mock server on :8080")
if err := http.ListenAndServe(":8080", handler); err != nil {
log.Fatal(err)
}
}The SDK includes comprehensive support for handling postback notifications, which are sent when payments are confirmed on the blockchain.
sender := atlos.NewPostbackSender("your-api-secret")
notification := &atlos.PostbackNotification{
TransactionId: "tx-123",
MerchantId: "merchant-456",
Amount: 20.00,
Status: 100,
// ... other fields
}
err := sender.Send("https://example.com/postback", notification)
if err != nil {
log.Fatal(err)
}handler := atlos.NewPostbackHandler("your-api-secret")
notification, err := handler.HandleRequest(req)
if err != nil {
log.Printf("Invalid postback: %v", err)
return
}
log.Printf("Valid postback received for transaction: %s", notification.TransactionId)The mock server provides methods to complete payments and trigger postbacks during tests.
The /Payment/Complete endpoint simulates blockchain confirmation:
reqBody := `{"PaymentId": "pay-123"}`
req, _ := http.NewRequest("POST", "/Payment/Complete", strings.NewReader(reqBody))
resp, err := http.DefaultClient.Do(req)This marks the payment as successful and generates a blockchain transaction hash.
Postback sending behavior is controlled by PostbackMode:
PostbackDisabled: No postbacks sentPostbackImmediate: Postbacks sent immediately when payment completesPostbackManual: Postbacks only sent via explicitSendPostback()call
payment, err := server.GetPayment("pay-123")
if err != nil {
log.Fatal(err)
}
invoice, err := server.GetInvoice("inv-456")
if err != nil {
log.Fatal(err)
}A CLI tool is provided for running a development server:
go run cmd/main.go --port 8080 --postback-url https://example.com/callback --shared-secret test-secretTo regenerate the client and server code after modifying the OpenAPI spec:
go generate ./...This uses the oapi-codegen configuration in oai-codegen.yaml and oai-codegen-server.yaml.
- Go 1.26 or later
- oapi-codegen v2.6.0 or later
go build ./...go test ./...Run specific test:
go test -v ./server_test.go ./server.go
go test -v -run TestServer_InvoiceCreatePostTest with race detection and coverage:
go test -race -coverprofile=coverage.out -covermode=atomic ./...To regenerate assets.go from the live API (requires API credentials):
ATLOS_API_SECRET=xxx ATLOS_MERCHANT_ID=yyy go run scripts/fetch-assets.go > assets.goatlos-sdk/
├── client.go # Main SDK client wrapper (public API)
├── server.go # Mock server implementation for testing
├── postback.go # Postback notification handlers
├── assets.go # Generated asset data (DO NOT EDIT)
├── oai-codegen.yaml # Code gen config for client/models
├── oai-codegen-server.yaml # Code gen config for server interface
├── swagger-spec.yaml # OpenAPI 3.0 specification
├── internal/
│ └── client/
│ ├── client.gen.go # Generated HTTP client & models (DO NOT EDIT)
│ └── server.gen.go # Generated server interface (DO NOT EDIT)
├── cmd/main.go # CLI development server
└── scripts/fetch-assets.go # Utility to regenerate assets.go
Two oapi-codegen configs handle different generation targets:
oai-codegen.yaml: Generates models and client tointernal/client/client.gen.gooai-codegen-server.yaml: Generates std-http-server interface tointernal/client/server.gen.go
The generated client supports all Atlos API endpoints:
POST /Wallet/SendToken- Create outgoing paymentPOST /Wallet/CancelPayout- Cancel payoutPOST /Asset/List- List available assetsPOST /Invoice/Create- Create invoicePOST /Invoice/Cancel- Cancel invoicePOST /Payment/WebSocket- WebSocket endpoint for payment updatesPOST /Payment/Create- Create paymentPOST /Payment/Get- Get payment detailsPOST /Payment/Complete- Test endpoint to simulate payment completion (mock only)POST /Transaction/List- List transactionsPOST /Transaction/FindByHash- Find transaction by hashPOST /Subscription/Cancel- Cancel subscription
API uses ApiSecret header (not Bearer token). Set via WithAPISecret() client option.
Never manually edit files marked // Code generated by... or // DO NOT EDIT.
The mock server uses sync.RWMutex for protecting maps. All methods acquiring locks ensure proper defer execution.
MIT