Documentation
¶
Overview ¶
Package smepay is the official Go SDK for the SMEPay External API.
It wraps the three payment calls (create, initiate, get status) and handles authentication, token reuse and errors for you.
client, err := smepay.New(smepay.Config{
ClientID: os.Getenv("SMEPAY_CLIENT_ID"),
ClientSecret: os.Getenv("SMEPAY_CLIENT_SECRET"),
Environment: smepay.Test, // or smepay.Live
})
Use the SDK only on your server; never expose the client secret.
Index ¶
- Constants
- type Client
- type Config
- type CreateParams
- type CreateResponse
- type CustomerDetails
- type Environment
- type Error
- type GetStatusParams
- type GetStatusResponse
- type InitiateParams
- type InitiateResponse
- type PaymentService
- func (s *PaymentService) Create(ctx context.Context, params CreateParams) (*CreateResponse, error)
- func (s *PaymentService) GetStatus(ctx context.Context, params GetStatusParams) (*GetStatusResponse, error)
- func (s *PaymentService) Initiate(ctx context.Context, params InitiateParams) (*InitiateResponse, error)
- type PaymentStatus
Constants ¶
const Version = "0.2.0"
Version is the SDK version, sent in the User-Agent header. Keep in sync with the git release tag (vX.Y.Z).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Payment holds the payment calls: Create → Initiate → GetStatus.
Payment *PaymentService
// contains filtered or unexported fields
}
Client calls the SMEPay External API. It is safe for concurrent use; create one and reuse it.
func New ¶
New creates a Client. Environment defaults to Test. A missing ClientID/ClientSecret or unknown Environment returns *Error with code "invalid_config".
func (*Client) Environment ¶
func (c *Client) Environment() Environment
Environment reports which SMEPay environment the client uses.
type Config ¶
type Config struct {
ClientID string
ClientSecret string // keep in an environment variable, never in code
Environment Environment
}
Config holds the credentials from the SMEPay dashboard.
type CreateParams ¶
type CreateParams struct {
Amount string `json:"amount"` // in rupees, as a string, e.g. "100.50"
OrderID string `json:"order_id"` // your own reference; unique for your business
CallbackURL string `json:"callback_url"` // receives the payment result webhook
CustomerDetails CustomerDetails `json:"customer_details"`
}
CreateParams for Payment.Create (POST /api/external/order/create).
type CreateResponse ¶
type CreateResponse struct {
Status bool `json:"status"`
OrderSlug string `json:"order_slug"` // pass to Payment.Initiate
OrderID string `json:"order_id"` // SMEPay's order ID
Amount float64 `json:"amount"`
PaymentStatus PaymentStatus `json:"payment_status"`
PaymentURL string `json:"payment_url"` // hosted SMEPay payment page
RefID string `json:"ref_id"` // your OrderID, echoed back
CustomerDetails CustomerDetails `json:"customer_details"`
Message string `json:"message"`
CallbackURL string `json:"callback_url,omitempty"`
}
CreateResponse from Payment.Create.
type CustomerDetails ¶
type CustomerDetails struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Mobile string `json:"mobile,omitempty"`
}
CustomerDetails of the payer; at least Email or Mobile is required.
type Environment ¶
type Environment string
Environment selects the SMEPay server. It must match your business's mode on SMEPay.
const ( // Test uses staging.smepay.in: no real money, no fees. Test Environment = "test" // Live uses extranet.smepay.in: real payments. Live Environment = "live" )
type Error ¶
type Error struct {
Code string
Message string
StatusCode int
Raw []byte
// contains filtered or unexported fields
}
Error is returned for every failed SDK call. Check it with errors.As:
var e *smepay.Error
if errors.As(err, &e) && e.Code == "duplicate_order_id" { ... }
API errors: Code is the API's "error" field, StatusCode the HTTP status and Raw the API reply body. SDK-side errors use the codes "invalid_config", "network_error", "timeout" and "invalid_response"; StatusCode is 0 when no reply was received.
type GetStatusParams ¶
type GetStatusParams struct {
OrderID string `json:"order_id,omitempty"`
ExternalReferenceID string `json:"external_reference_id,omitempty"`
CallbackURL string `json:"callback_url,omitempty"` // saved only if the order has none yet
}
GetStatusParams for Payment.GetStatus (POST /api/external/order/status). Set OrderID (SMEPay's) or ExternalReferenceID (yours); ExternalReferenceID is used first if both are set.
type GetStatusResponse ¶
type GetStatusResponse struct {
Status bool `json:"status"`
ExternalReferenceID string `json:"external_reference_id"` // your OrderID
OrderID string `json:"order_id"` // SMEPay's order ID
PaymentStatus PaymentStatus `json:"payment_status"`
Amount float64 `json:"amount"`
CreatedAt int64 `json:"created_at"` // Unix seconds
ProcessedAt *int64 `json:"processed_at"` // Unix seconds; nil until processed
UTR string `json:"utr,omitempty"` // bank reference, when available
}
GetStatusResponse from Payment.GetStatus.
type InitiateParams ¶
type InitiateParams struct {
Slug string `json:"slug"` // OrderSlug from Payment.Create
}
InitiateParams for Payment.Initiate (POST /api/external/order/initiate).
type InitiateResponse ¶
type InitiateResponse struct {
Status bool `json:"status"`
OrderID string `json:"order_id"` // SMEPay's order ID
ExternalReferenceID string `json:"external_reference_id"` // your OrderID
PaymentLink string `json:"payment_link"` // UPI payment link
TransactionID string `json:"transaction_id"`
QRCode string `json:"qr_code"` // base64-encoded PNG
PaymentStatus PaymentStatus `json:"payment_status"`
ExpiresAt int64 `json:"expires_at"` // Unix seconds
Intents map[string]string `json:"intents"` // UPI app key -> app payment link
Message string `json:"message"`
}
InitiateResponse from Payment.Initiate.
type PaymentService ¶
type PaymentService struct {
// contains filtered or unexported fields
}
PaymentService groups the payment calls: Create → Initiate → GetStatus.
func (*PaymentService) Create ¶
func (s *PaymentService) Create(ctx context.Context, params CreateParams) (*CreateResponse, error)
Create creates a payment order. Next step: Initiate with the returned OrderSlug.
func (*PaymentService) GetStatus ¶
func (s *PaymentService) GetStatus(ctx context.Context, params GetStatusParams) (*GetStatusResponse, error)
GetStatus fetches the current payment status of an order.
func (*PaymentService) Initiate ¶
func (s *PaymentService) Initiate(ctx context.Context, params InitiateParams) (*InitiateResponse, error)
Initiate starts the payment for an order and returns the UPI link, QR code and app intents.
type PaymentStatus ¶
type PaymentStatus string
PaymentStatus is a payment status returned by the API. Compare against the constants below; any new value the API adds is still accepted.
const ( StatusCreated PaymentStatus = "CREATED" StatusInitiated PaymentStatus = "INITIATED" StatusPending PaymentStatus = "PENDING" StatusSuccess PaymentStatus = "SUCCESS" StatusFailed PaymentStatus = "FAILED" StatusExpired PaymentStatus = "EXPIRED" StatusSettled PaymentStatus = "SETTLED" StatusRefunded PaymentStatus = "REFUNDED" StatusRefundPending PaymentStatus = "REFUND_PENDING" // Test-mode businesses get these instead of SUCCESS / FAILED / PENDING. StatusTestSuccess PaymentStatus = "TEST_SUCCESS" StatusTestFailed PaymentStatus = "TEST_FAILED" StatusTestPending PaymentStatus = "TEST_PENDING" )