Documentation
¶
Index ¶
- func SquareSupportedCurrencies() []currency.Type
- type Config
- type SquareProcessor
- func (sp *SquareProcessor) AddPaymentMethod(ctx context.Context, customerID, token string) (string, error)
- func (sp *SquareProcessor) Authorize(ctx context.Context, req processor.PaymentRequest) (*processor.PaymentResult, error)
- func (sp *SquareProcessor) CancelAuthorization(ctx context.Context, paymentID string) error
- func (sp *SquareProcessor) Capture(ctx context.Context, transactionID string, amount currency.Cents) (*processor.PaymentResult, error)
- func (sp *SquareProcessor) Charge(ctx context.Context, req processor.PaymentRequest) (*processor.PaymentResult, error)
- func (sp *SquareProcessor) CreateCustomer(ctx context.Context, email, name string, metadata map[string]interface{}) (string, error)
- func (sp *SquareProcessor) DeleteCustomer(ctx context.Context, customerID string) error
- func (sp *SquareProcessor) Environment() string
- func (sp *SquareProcessor) GetCustomer(ctx context.Context, customerID string) (map[string]interface{}, error)
- func (sp *SquareProcessor) GetTransaction(ctx context.Context, txID string) (*processor.Transaction, error)
- func (sp *SquareProcessor) IsAvailable(ctx context.Context) bool
- func (sp *SquareProcessor) LocationID() string
- func (sp *SquareProcessor) Refund(ctx context.Context, req processor.RefundRequest) (*processor.RefundResult, error)
- func (sp *SquareProcessor) RemovePaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
- func (sp *SquareProcessor) Type() processor.ProcessorType
- func (sp *SquareProcessor) UpdateCustomer(ctx context.Context, customerID string, updates map[string]interface{}) error
- func (sp *SquareProcessor) ValidateWebhook(ctx context.Context, payload []byte, signature string) (*processor.WebhookEvent, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SquareSupportedCurrencies ¶
SquareSupportedCurrencies returns currencies Square supports
Types ¶
type Config ¶
type Config struct {
AccessToken string
LocationID string
WebhookSecret string
// WebhookURL is the notification URL registered with Square's webhook
// subscription (e.g. https://api.hanzo.ai/v1/billing/webhooks/square).
// Required to validate live Square signatures; see SquareProcessor.webhookURL.
WebhookURL string
Environment string // "sandbox" or "production"
}
Config holds Square processor configuration
type SquareProcessor ¶
type SquareProcessor struct {
*processor.BaseProcessor
// contains filtered or unexported fields
}
SquareProcessor implements the processor.PaymentProcessor interface
func NewProcessor ¶
func NewProcessor(cfg Config) *SquareProcessor
NewProcessor creates a new Square processor
func (*SquareProcessor) AddPaymentMethod ¶
func (sp *SquareProcessor) AddPaymentMethod(ctx context.Context, customerID, token string) (string, error)
AddPaymentMethod attaches a card nonce (token) to an existing Square customer. Returns the card-on-file ID.
func (*SquareProcessor) Authorize ¶
func (sp *SquareProcessor) Authorize(ctx context.Context, req processor.PaymentRequest) (*processor.PaymentResult, error)
Authorize authorizes a payment without capturing
func (*SquareProcessor) CancelAuthorization ¶
func (sp *SquareProcessor) CancelAuthorization(ctx context.Context, paymentID string) error
CancelAuthorization voids a previously authorized (uncaptured) payment. Call this immediately after a successful pre-auth to release the hold.
func (*SquareProcessor) Capture ¶
func (sp *SquareProcessor) Capture(ctx context.Context, transactionID string, amount currency.Cents) (*processor.PaymentResult, error)
Capture captures a previously authorized payment
func (*SquareProcessor) Charge ¶
func (sp *SquareProcessor) Charge(ctx context.Context, req processor.PaymentRequest) (*processor.PaymentResult, error)
Charge processes a payment
func (*SquareProcessor) CreateCustomer ¶
func (sp *SquareProcessor) CreateCustomer(ctx context.Context, email, name string, metadata map[string]interface{}) (string, error)
CreateCustomer creates a customer profile in Square. Returns the Square customer ID on success.
func (*SquareProcessor) DeleteCustomer ¶
func (sp *SquareProcessor) DeleteCustomer(ctx context.Context, customerID string) error
DeleteCustomer removes a Square customer profile.
func (*SquareProcessor) Environment ¶
func (sp *SquareProcessor) Environment() string
Environment returns "sandbox" or "production" — the resolved Square API environment this processor talks to (it drives the API base URL). Non-secret.
func (*SquareProcessor) GetCustomer ¶
func (sp *SquareProcessor) GetCustomer(ctx context.Context, customerID string) (map[string]interface{}, error)
GetCustomer retrieves a Square customer profile by ID.
func (*SquareProcessor) GetTransaction ¶
func (sp *SquareProcessor) GetTransaction(ctx context.Context, txID string) (*processor.Transaction, error)
GetTransaction retrieves transaction details
func (*SquareProcessor) IsAvailable ¶
func (sp *SquareProcessor) IsAvailable(ctx context.Context) bool
IsAvailable checks if the processor is configured and available
func (*SquareProcessor) LocationID ¶
func (sp *SquareProcessor) LocationID() string
LocationID returns the configured Square merchant location id. Non-secret (it is also returned by the public /v1/billing/payment-config endpoint).
func (*SquareProcessor) Refund ¶
func (sp *SquareProcessor) Refund(ctx context.Context, req processor.RefundRequest) (*processor.RefundResult, error)
Refund processes a refund
func (*SquareProcessor) RemovePaymentMethod ¶
func (sp *SquareProcessor) RemovePaymentMethod(ctx context.Context, customerID, paymentMethodID string) error
RemovePaymentMethod disables (deletes) a card on file from a Square customer.
func (*SquareProcessor) Type ¶
func (sp *SquareProcessor) Type() processor.ProcessorType
Type returns the processor type
func (*SquareProcessor) UpdateCustomer ¶
func (sp *SquareProcessor) UpdateCustomer(ctx context.Context, customerID string, updates map[string]interface{}) error
UpdateCustomer updates mutable fields on a Square customer profile. Recognised keys: email, name, note.
func (*SquareProcessor) ValidateWebhook ¶
func (sp *SquareProcessor) ValidateWebhook(ctx context.Context, payload []byte, signature string) (*processor.WebhookEvent, error)
ValidateWebhook validates an incoming webhook and parses the event.
Square signs each notification as
base64(HMAC-SHA256(signatureKey, notificationURL + rawBody))
where notificationURL is the EXACT URL configured in the dashboard webhook subscription — not the body alone, and not a URL derived from the inbound request (which a proxy can rewrite). The signature arrives base64-encoded in the x-square-hmacsha256-signature header. We decode both the header and our computed digest to raw bytes and compare with hmac.Equal for a clean constant-time check.
In addition to the existing event_id idempotency, events older than webhookMaxAge are rejected as replays.