Documentation
¶
Overview ¶
Package paylio provides a Go client library for the Paylio subscription API.
Index ¶
- Constants
- type APIConnectionError
- type APIError
- type AuthenticationError
- type CancelOptions
- type Client
- type ErrorParams
- type InvalidRequestError
- type ListOptions
- type NotFoundError
- type Option
- type PaginatedList
- type PaylioError
- type Period
- type Plan
- type RateLimitError
- type Subscription
- type SubscriptionCancel
- type SubscriptionHistoryItem
- type SubscriptionService
- func (s *SubscriptionService) Cancel(ctx context.Context, subscriptionID string, opts *CancelOptions) (*SubscriptionCancel, error)
- func (s *SubscriptionService) List(ctx context.Context, userID string, opts *ListOptions) (*PaginatedList[SubscriptionHistoryItem], error)
- func (s *SubscriptionService) Retrieve(ctx context.Context, userID string) (*Subscription, error)
Constants ¶
const ( // DefaultBaseURL is the default base URL for the Paylio API. DefaultBaseURL = "https://api.paylio.pro/flying/v1" // DefaultTimeout is the default request timeout. DefaultTimeout = 30 * time.Second )
const Version = "0.1.3"
Version is the current version of the paylio-go SDK.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIConnectionError ¶
type APIConnectionError struct{ *PaylioError }
APIConnectionError indicates a network failure or timeout.
func NewAPIConnectionError ¶
func NewAPIConnectionError(p ErrorParams) *APIConnectionError
NewAPIConnectionError creates an APIConnectionError from the given params.
func (*APIConnectionError) Unwrap ¶
func (e *APIConnectionError) Unwrap() error
Unwrap returns the underlying PaylioError.
type APIError ¶
type APIError struct{ *PaylioError }
APIError indicates a server error or unexpected HTTP status.
func NewAPIError ¶
func NewAPIError(p ErrorParams) *APIError
NewAPIError creates an APIError from the given params.
type AuthenticationError ¶
type AuthenticationError struct{ *PaylioError }
AuthenticationError indicates an invalid or missing API key (HTTP 401).
func NewAuthenticationError ¶
func NewAuthenticationError(p ErrorParams) *AuthenticationError
NewAuthenticationError creates an AuthenticationError from the given params.
func (*AuthenticationError) Unwrap ¶
func (e *AuthenticationError) Unwrap() error
Unwrap returns the underlying PaylioError.
type CancelOptions ¶
type CancelOptions struct {
CancelNow bool
}
CancelOptions configures subscription cancellation behavior.
type Client ¶
type Client struct {
// Subscription provides access to subscription operations.
Subscription *SubscriptionService
// contains filtered or unexported fields
}
Client is the entry point for the Paylio SDK.
type ErrorParams ¶
type ErrorParams struct {
Message string
HTTPStatus int
HTTPBody string
JSONBody map[string]any
Headers map[string]string
Code string
}
ErrorParams holds the parameters for constructing a PaylioError.
type InvalidRequestError ¶
type InvalidRequestError struct{ *PaylioError }
InvalidRequestError indicates bad request parameters (HTTP 400).
func NewInvalidRequestError ¶
func NewInvalidRequestError(p ErrorParams) *InvalidRequestError
NewInvalidRequestError creates an InvalidRequestError from the given params.
func (*InvalidRequestError) Unwrap ¶
func (e *InvalidRequestError) Unwrap() error
Unwrap returns the underlying PaylioError.
type ListOptions ¶
ListOptions configures pagination for subscription list requests.
type NotFoundError ¶
type NotFoundError struct{ *PaylioError }
NotFoundError indicates a resource was not found (HTTP 404).
func NewNotFoundError ¶
func NewNotFoundError(p ErrorParams) *NotFoundError
NewNotFoundError creates a NotFoundError from the given params.
func (*NotFoundError) Unwrap ¶
func (e *NotFoundError) Unwrap() error
Unwrap returns the underlying PaylioError.
type Option ¶
type Option func(*clientConfig)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL sets a custom base URL for API requests.
func WithHTTPClient ¶
WithHTTPClient sets a custom net/http client.
func WithTimeout ¶
WithTimeout sets a custom request timeout.
type PaginatedList ¶
type PaginatedList[T any] struct { Items []T `json:"items"` Total int `json:"total"` Page int `json:"page"` PageSize int `json:"page_size"` TotalPages int `json:"total_pages"` }
PaginatedList is a generic paginated response container.
func (*PaginatedList[T]) HasMore ¶
func (p *PaginatedList[T]) HasMore() bool
HasMore returns true if there are additional pages of results.
type PaylioError ¶
type PaylioError struct {
Message string
HTTPStatus int
HTTPBody string
JSONBody map[string]any
Headers map[string]string
Code string
}
PaylioError is the base error type for all Paylio SDK errors.
func (*PaylioError) Error ¶
func (e *PaylioError) Error() string
type Plan ¶
type Plan struct {
Slug string `json:"slug"`
Name string `json:"name"`
Interval string `json:"interval"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
}
Plan represents a subscription plan.
type RateLimitError ¶
type RateLimitError struct{ *PaylioError }
RateLimitError indicates rate limit exceeded (HTTP 429).
func NewRateLimitError ¶
func NewRateLimitError(p ErrorParams) *RateLimitError
NewRateLimitError creates a RateLimitError from the given params.
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
Unwrap returns the underlying PaylioError.
type Subscription ¶
type Subscription struct {
ID string `json:"id"`
Object string `json:"object"`
Status string `json:"status"`
UserID string `json:"user_id"`
Plan Plan `json:"plan"`
SubscriptionPeriod Period `json:"subscription_period"`
CancelAtPeriodEnd bool `json:"cancel_at_period_end"`
CanceledAt *string `json:"canceled_at"`
Provider string `json:"provider"`
CreatedAt string `json:"created_at"`
}
Subscription represents a user's subscription.
type SubscriptionCancel ¶
type SubscriptionCancel struct {
ID string `json:"id"`
Object string `json:"object"`
Success bool `json:"success"`
CancelAtPeriodEnd bool `json:"cancel_at_period_end"`
}
SubscriptionCancel represents the result of canceling a subscription.
type SubscriptionHistoryItem ¶
type SubscriptionHistoryItem struct {
ID string `json:"id"`
UserID string `json:"user_id"`
PlanSlug string `json:"plan_slug"`
PlanName string `json:"plan_name"`
PlanAmount float64 `json:"plan_amount"`
PlanCurrency string `json:"plan_currency"`
PlanInterval string `json:"plan_interval"`
Status string `json:"status"`
CurrentPeriodStart string `json:"current_period_start"`
CurrentPeriodEnd string `json:"current_period_end"`
CreatedAt string `json:"created_at"`
}
SubscriptionHistoryItem represents a single item in subscription history.
type SubscriptionService ¶
type SubscriptionService struct {
// contains filtered or unexported fields
}
SubscriptionService provides methods for interacting with subscriptions.
func (*SubscriptionService) Cancel ¶
func (s *SubscriptionService) Cancel(ctx context.Context, subscriptionID string, opts *CancelOptions) (*SubscriptionCancel, error)
Cancel cancels a subscription. By default cancels at end of billing period. Set CancelOptions.CancelNow to true for immediate cancellation.
func (*SubscriptionService) List ¶
func (s *SubscriptionService) List(ctx context.Context, userID string, opts *ListOptions) (*PaginatedList[SubscriptionHistoryItem], error)
List fetches paginated subscription history for a user.
func (*SubscriptionService) Retrieve ¶
func (s *SubscriptionService) Retrieve(ctx context.Context, userID string) (*Subscription, error)
Retrieve fetches the current subscription for a user.