Documentation
¶
Overview ¶
Package wire is the official Go SDK for the Wire payment API (https://wire.mn).
Create a client with an API key and call resource services:
client := wire.NewClient("sk_live_...")
pi, err := client.PaymentIntents.Create(ctx, &wire.PaymentIntentCreateParams{Amount: 50000})
Index ¶
- Constants
- Variables
- type Charge
- type ChargeService
- type Client
- type Deleted
- type Error
- type Event
- type EventService
- type Iter
- type List
- type ListParams
- type Option
- type PaymentIntent
- type PaymentIntentConfirmParams
- type PaymentIntentCreateParams
- type PaymentIntentService
- func (s *PaymentIntentService) Cancel(ctx context.Context, id string) (*PaymentIntent, error)
- func (s *PaymentIntentService) Confirm(ctx context.Context, id string, p *PaymentIntentConfirmParams) (*PaymentIntent, error)
- func (s *PaymentIntentService) Create(ctx context.Context, p *PaymentIntentCreateParams) (*PaymentIntent, error)
- func (s *PaymentIntentService) List(ctx context.Context, p *ListParams) *Iter[PaymentIntent]
- func (s *PaymentIntentService) Retrieve(ctx context.Context, id string) (*PaymentIntent, error)
- type WebhookEndpoint
- type WebhookEndpointCreateParams
- type WebhookEndpointService
- func (s *WebhookEndpointService) Create(ctx context.Context, p *WebhookEndpointCreateParams) (*WebhookEndpoint, error)
- func (s *WebhookEndpointService) Delete(ctx context.Context, id string) (*Deleted, error)
- func (s *WebhookEndpointService) List(ctx context.Context, p *ListParams) *Iter[WebhookEndpoint]
- func (s *WebhookEndpointService) Retrieve(ctx context.Context, id string) (*WebhookEndpoint, error)
- func (s *WebhookEndpointService) Update(ctx context.Context, id string, p *WebhookEndpointUpdateParams) (*WebhookEndpoint, error)
- type WebhookEndpointUpdateParams
- type WebhooksService
Constants ¶
const DefaultBaseURL = "https://api.wire.mn"
DefaultBaseURL is the production Wire API endpoint.
const DefaultTolerance = 300 * time.Second
DefaultTolerance is the max allowed clock skew between signature timestamp and now.
const SignatureHeader = "WirePayment-Signature"
SignatureHeader is the header carrying the webhook signature.
Variables ¶
var ErrInvalidSignature = errors.New("wire: webhook signature verification failed")
ErrInvalidSignature is returned when a webhook signature does not verify.
Functions ¶
This section is empty.
Types ¶
type Charge ¶
type Charge struct {
ID string `json:"id"`
Object string `json:"object"`
PaymentIntent string `json:"payment_intent"`
Operator string `json:"operator"`
OperatorChargeID *string `json:"operator_charge_id"`
Status string `json:"status"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"`
AmountRefunded int64 `json:"amount_refunded"`
FailureCode *string `json:"failure_code"`
FailureMessage *string `json:"failure_message"`
Livemode bool `json:"livemode"`
Created int64 `json:"created"`
}
Charge is a single attempt to move money via an operator.
type ChargeService ¶
type ChargeService struct {
// contains filtered or unexported fields
}
ChargeService accesses /v1/charges.
func (*ChargeService) List ¶
func (s *ChargeService) List(ctx context.Context, p *ListParams) *Iter[Charge]
List returns an auto-paginating iterator over charges.
type Client ¶
type Client struct {
PaymentIntents *PaymentIntentService
Charges *ChargeService
Events *EventService
WebhookEndpoints *WebhookEndpointService
Webhooks *WebhooksService
// contains filtered or unexported fields
}
Client is a Wire API client. Create it with NewClient.
type Deleted ¶
type Deleted struct {
ID string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
}
Deleted is the response shape for delete operations.
type Error ¶
type Error struct {
Type string `json:"type"`
Code string `json:"code"`
Message string `json:"message"`
Param string `json:"param"`
RequestID string `json:"request_id"`
DocURL string `json:"doc_url"`
OperatorDeclineCode string `json:"operator_decline_code"`
StatusCode int `json:"-"`
}
Error is a typed Wire API error. Use errors.As to extract it.
type Event ¶
type Event struct {
ID string `json:"id"`
Object string `json:"object"`
Type string `json:"type"`
APIVersion string `json:"api_version"`
Data json.RawMessage `json:"data"`
Livemode bool `json:"livemode"`
Created int64 `json:"created"`
}
Event is a record of something that happened, delivered via webhooks.
type EventService ¶
type EventService struct {
// contains filtered or unexported fields
}
EventService accesses /v1/events.
func (*EventService) List ¶
func (s *EventService) List(ctx context.Context, p *ListParams) *Iter[Event]
List returns an auto-paginating iterator over events.
type Iter ¶
type Iter[T any] struct { // contains filtered or unexported fields }
Iter is a lazy auto-paginator over a cursor-paginated collection.
it := client.Charges.List(ctx, nil)
for it.Next() {
ch := it.Current()
}
if err := it.Err(); err != nil { ... }
func (*Iter[T]) Current ¶
func (it *Iter[T]) Current() T
Current returns the item the iterator is positioned on.
type List ¶
type List[T any] struct { Object string `json:"object"` Data []T `json:"data"` HasMore bool `json:"has_more"` }
List is one page of a cursor-paginated collection.
type ListParams ¶
ListParams are shared pagination parameters.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBackoff ¶
WithBackoff sets the base backoff duration between retries.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (e.g. a local dev server).
func WithHTTPClient ¶
WithHTTPClient injects a custom *http.Client.
func WithMaxRetries ¶
WithMaxRetries sets the max retry count for 429/5xx/network errors.
func WithTimeout ¶
WithTimeout sets the per-request timeout on the default HTTP client.
type PaymentIntent ¶
type PaymentIntent struct {
ID string `json:"id"`
Object string `json:"object"`
Amount int64 `json:"amount"`
Currency string `json:"currency"`
Status string `json:"status"`
ClientSecret string `json:"client_secret"`
AutomaticOperator bool `json:"automatic_operator"`
AllowedOperators []string `json:"allowed_operators"`
SelectedOperator *string `json:"selected_operator"`
NextAction json.RawMessage `json:"next_action"`
Metadata map[string]string `json:"metadata"`
Livemode bool `json:"livemode"`
Created int64 `json:"created"`
ExpiresAt *int64 `json:"expires_at"`
}
PaymentIntent is the primary object for accepting a payment.
type PaymentIntentConfirmParams ¶
type PaymentIntentConfirmParams struct {
ReturnURL string `json:"return_url,omitempty"`
IdempotencyKey string `json:"-"`
}
PaymentIntentConfirmParams are the optional inputs to Confirm.
type PaymentIntentCreateParams ¶
type PaymentIntentCreateParams struct {
Amount int64 `json:"amount"`
Currency string `json:"currency,omitempty"`
AutomaticOperator *bool `json:"automatic_operator,omitempty"`
AllowedOperators []string `json:"allowed_operators,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
IdempotencyKey string `json:"-"`
}
PaymentIntentCreateParams are the inputs to Create.
type PaymentIntentService ¶
type PaymentIntentService struct {
// contains filtered or unexported fields
}
PaymentIntentService accesses /v1/payment_intents.
func (*PaymentIntentService) Cancel ¶
func (s *PaymentIntentService) Cancel(ctx context.Context, id string) (*PaymentIntent, error)
Cancel cancels a payment intent.
func (*PaymentIntentService) Confirm ¶
func (s *PaymentIntentService) Confirm(ctx context.Context, id string, p *PaymentIntentConfirmParams) (*PaymentIntent, error)
Confirm submits a payment intent for processing.
func (*PaymentIntentService) Create ¶
func (s *PaymentIntentService) Create(ctx context.Context, p *PaymentIntentCreateParams) (*PaymentIntent, error)
Create starts a new payment intent.
func (*PaymentIntentService) List ¶
func (s *PaymentIntentService) List(ctx context.Context, p *ListParams) *Iter[PaymentIntent]
List returns an auto-paginating iterator over payment intents.
func (*PaymentIntentService) Retrieve ¶
func (s *PaymentIntentService) Retrieve(ctx context.Context, id string) (*PaymentIntent, error)
Retrieve fetches a payment intent by id.
type WebhookEndpoint ¶
type WebhookEndpoint struct {
ID string `json:"id"`
Object string `json:"object"`
URL string `json:"url"`
EnabledEvents []string `json:"enabled_events"`
Status string `json:"status"`
Secret string `json:"secret,omitempty"` // returned only at creation
Livemode bool `json:"livemode"`
Created int64 `json:"created"`
}
WebhookEndpoint is a merchant-registered URL that receives events.
type WebhookEndpointCreateParams ¶
type WebhookEndpointCreateParams struct {
URL string `json:"url"`
EnabledEvents []string `json:"enabled_events,omitempty"`
IdempotencyKey string `json:"-"`
}
WebhookEndpointCreateParams are the inputs to Create.
type WebhookEndpointService ¶
type WebhookEndpointService struct {
// contains filtered or unexported fields
}
WebhookEndpointService accesses /v1/webhook_endpoints.
func (*WebhookEndpointService) Create ¶
func (s *WebhookEndpointService) Create(ctx context.Context, p *WebhookEndpointCreateParams) (*WebhookEndpoint, error)
Create registers a webhook endpoint. The signing secret is returned once.
func (*WebhookEndpointService) List ¶
func (s *WebhookEndpointService) List(ctx context.Context, p *ListParams) *Iter[WebhookEndpoint]
List returns an auto-paginating iterator over webhook endpoints.
func (*WebhookEndpointService) Retrieve ¶
func (s *WebhookEndpointService) Retrieve(ctx context.Context, id string) (*WebhookEndpoint, error)
Retrieve fetches a webhook endpoint by id.
func (*WebhookEndpointService) Update ¶
func (s *WebhookEndpointService) Update(ctx context.Context, id string, p *WebhookEndpointUpdateParams) (*WebhookEndpoint, error)
Update modifies a webhook endpoint (Stripe-style POST update).
type WebhookEndpointUpdateParams ¶
type WebhookEndpointUpdateParams struct {
URL *string `json:"url,omitempty"`
EnabledEvents []string `json:"enabled_events,omitempty"`
Status *string `json:"status,omitempty"`
IdempotencyKey string `json:"-"`
}
WebhookEndpointUpdateParams are the partial-update inputs.
type WebhooksService ¶
type WebhooksService struct{}
WebhooksService verifies inbound webhook signatures.
func (*WebhooksService) Verify ¶
func (s *WebhooksService) Verify(payload []byte, header, secret string) (*Event, error)
Verify checks a webhook payload's signature and returns the parsed Event. payload must be the raw request body bytes (verify BEFORE JSON parsing).
func (*WebhooksService) VerifyWithTolerance ¶
func (s *WebhooksService) VerifyWithTolerance(payload []byte, header, secret string, tolerance time.Duration) (*Event, error)
VerifyWithTolerance is Verify with a custom timestamp tolerance.