Documentation ¶
Index ¶
- Constants
- Variables
- func CheckResponse(r *http.Response) error
- func DoRequestWithClient(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)
- type ArgError
- type Client
- type ClientOpt
- type Config
- type ConflictError
- type CreatePaymentResponse
- type ErrorResponse
- type GetWebhookRequest
- type GetWebhookResponse
- type Level
- type LeveledLogger
- type LeveledLoggerInterface
- type ListOptions
- type Payment
- type PaymentParams
- type PaymentService
- type PaymentServiceOp
- func (ps *PaymentServiceOp) Cancel(ctx context.Context, paymentId string) error
- func (ps *PaymentServiceOp) Capture(ctx context.Context, paymentId string, amount int) error
- func (ps *PaymentServiceOp) Create(ctx context.Context, paymentParams *PaymentParams) (*CreatePaymentResponse, error)
- func (ps *PaymentServiceOp) Find(ctx context.Context, paymentId string) (*Payment, error)
- func (ps PaymentServiceOp) Get(ctx context.Context, opts ListOptions) (*PaymentsRoot, error)
- type PaymentsRoot
- type Refund
- type RefundParams
- type RefundService
- type RefundServiceOp
- type RefundsListOptions
- type RefundsRoot
- type RequestCompletionCallback
- type Response
- type Webhook
- type WebhookCreateParams
- type WebhookEvent
- type WebhookEventEnum
- type WebhookService
- type WebhookServiceOp
- func (s *WebhookServiceOp) Create(ctx context.Context, createRequest *WebhookCreateParams) (*Webhook, error)
- func (s *WebhookServiceOp) Delete(ctx context.Context, webhookId string) error
- func (s *WebhookServiceOp) Find(ctx context.Context, webhookId string) (*Webhook, error)
- func (s WebhookServiceOp) Get(ctx context.Context) (*WebhooksRoot, error)
- func (s WebhookServiceOp) Update(ctx context.Context, webhookId string, request *WebhookUpdateParams) (*Webhook, error)
- type WebhookUpdateParams
- type WebhooksRoot
- type WebhooksVerifier
Constants ¶
const ( LibraryVersion = "1.0.0" DefaultBaseURL = "https://api.mobilepay.dk" TestBaseUrl = "https://api.sandbox.mobilepay.dk" DefaultTimeout = 10 * time.Second )
https://mobilepaydev.github.io/MobilePay-Payments-API/docs/payments-refunds/create-payments
Variables ¶
var (
ErrMissingVerifierProperties = errors.New("missing required verifier properties signature or webhook url")
)
Functions ¶
func CheckResponse ¶ added in v0.0.3
Types ¶
type ArgError ¶ added in v0.0.3
type ArgError struct {
// contains filtered or unexported fields
}
ArgError is an error that represents an error with an input to mobilepay app payment. It identifies the argument and the cause (if possible).
type Client ¶ added in v0.0.3
type Client struct { // Base URL for API requests. BaseURL *url.URL // User agent for client UserAgent string Logger LeveledLoggerInterface // MobilePay API services used for communicating with the API. Payment *PaymentServiceOp // we are using a struct over an interface to support multiple interfaces implemented by the struct properties. Webhook WebhookService // contains filtered or unexported fields }
type Config ¶
type Config struct { HTTPClient *http.Client Logger LeveledLoggerInterface URL string }
URL is the base url to the Mobilepay API. You can use the constants defined in this package: DefaultBaseURL or TestBaseUrl
type ConflictError ¶ added in v0.0.3
type CreatePaymentResponse ¶ added in v0.0.3
type ErrorResponse ¶ added in v0.0.3
type ErrorResponse struct { // HTTP response that caused this error Response *http.Response `json:"-"` // Error message Message string `json:"message,omitempty"` Conflict *ConflictError `json:"conflict"` StatusCode int `json:"statusCode"` }
An ErrorResponse reports the error caused by an API request
func (*ErrorResponse) Error ¶ added in v0.0.3
func (r *ErrorResponse) Error() string
type GetWebhookRequest ¶ added in v0.0.3
type GetWebhookRequest struct { }
type GetWebhookResponse ¶ added in v0.0.3
type GetWebhookResponse struct {
Webhooks []Webhook `json:"webhooks"`
}
type Level ¶ added in v0.0.3
type Level uint32
Level represents a logging level.
const ( // LevelNull sets a logger to show no messages at all. LevelNull Level = 0 // LevelError sets a logger to show error messages only. LevelError Level = 1 // LevelWarn sets a logger to show warning messages or anything more // severe. LevelWarn Level = 2 // LevelInfo sets a logger to show informational messages or anything more // severe. LevelInfo Level = 3 // LevelDebug sets a logger to show informational messages or anything more // severe. LevelDebug Level = 4 )
type LeveledLogger ¶ added in v0.0.3
type LeveledLogger struct { // Level is the minimum logging level that will be emitted by this logger. // // For example, a Level set to LevelWarn will emit warnings and errors, but // not informational or debug messages. // // Always set this with a constant like LevelWarn because the individual // values are not guaranteed to be stable. Level Level // contains filtered or unexported fields }
LeveledLogger is a leveled logger implementation.
It prints warnings and errors to `os.Stderr` and other messages to `os.Stdout`.
func (*LeveledLogger) Debugf ¶ added in v0.0.3
func (l *LeveledLogger) Debugf(format string, v ...interface{})
Debugf logs a debug message using Printf conventions.
func (*LeveledLogger) Errorf ¶ added in v0.0.3
func (l *LeveledLogger) Errorf(format string, v ...interface{})
Errorf logs a warning message using Printf conventions.
func (*LeveledLogger) Infof ¶ added in v0.0.3
func (l *LeveledLogger) Infof(format string, v ...interface{})
Infof logs an informational message using Printf conventions.
func (*LeveledLogger) Warnf ¶ added in v0.0.3
func (l *LeveledLogger) Warnf(format string, v ...interface{})
Warnf logs a warning message using Printf conventions.
type LeveledLoggerInterface ¶ added in v0.0.3
type LeveledLoggerInterface interface { // Debugf logs a debug message using Printf conventions. Debugf(format string, v ...interface{}) // Errorf logs a warning message using Printf conventions. Errorf(format string, v ...interface{}) // Infof logs an informational message using Printf conventions. Infof(format string, v ...interface{}) // Warnf logs a warning message using Printf conventions. Warnf(format string, v ...interface{}) }
LeveledLoggerInterface provides a basic leveled logging interface for printing debug, informational, warning, and error messages.
var DebugLeveledLogger LeveledLoggerInterface = &LeveledLogger{ Level: LevelDebug, }
var DefaultLeveledLogger LeveledLoggerInterface = &LeveledLogger{ Level: LevelError, }
DefaultLeveledLogger is the default logger that the library will use to log errors, warnings, and informational messages.
var InfoLeveledLogger LeveledLoggerInterface = &LeveledLogger{ Level: LevelDebug, }
var WarnLeveledLogger LeveledLoggerInterface = &LeveledLogger{ Level: LevelWarn, }
type ListOptions ¶ added in v0.0.3
type Payment ¶ added in v0.0.3
type Payment struct { PaymentId string `json:"paymentId,omitempty"` Amount int `json:"amount,omitempty"` Description string `json:"description,omitempty"` PaymentPointId string `json:"paymentPointId,omitempty"` Reference string `json:"reference,omitempty"` MobilePayAppRedirectUri string `json:"mobilePayAppRedirectUri,omitempty"` State string `json:"state,omitempty"` InitiatedOn string `json:"initiatedOn,omitempty"` LastUpdatedOn string `json:"lastUpdatedOn,omitempty"` MerchantId string `json:"merchantId,omitempty"` IsoCurrencyCode string `json:"isoCurrencyCode,omitempty"` PaymentPointName string `json:"paymentPointName,omitempty"` }
type PaymentParams ¶ added in v0.0.3
type PaymentService ¶ added in v0.0.3
type PaymentService interface { Get(context.Context, ListOptions) (*PaymentsRoot, error) Find(context.Context, string) (*Payment, error) Create(context.Context, *PaymentParams) (*CreatePaymentResponse, error) Cancel(ctx context.Context, paymentId string) error Capture(ctx context.Context, paymentId string, amount int) error }
type PaymentServiceOp ¶ added in v0.0.3
type PaymentServiceOp struct { Refund RefundService // contains filtered or unexported fields }
func (*PaymentServiceOp) Cancel ¶ added in v0.0.3
func (ps *PaymentServiceOp) Cancel(ctx context.Context, paymentId string) error
func (*PaymentServiceOp) Create ¶ added in v0.0.3
func (ps *PaymentServiceOp) Create(ctx context.Context, paymentParams *PaymentParams) (*CreatePaymentResponse, error)
func (PaymentServiceOp) Get ¶ added in v0.0.3
func (ps PaymentServiceOp) Get(ctx context.Context, opts ListOptions) (*PaymentsRoot, error)
type PaymentsRoot ¶ added in v0.0.3
type RefundParams ¶ added in v0.0.3
type RefundService ¶ added in v0.0.3
type RefundService interface { List(ctx context.Context, opt *RefundsListOptions) (*RefundsRoot, error) Create(ctx context.Context, createRequest *RefundParams) (*Refund, error) }
type RefundServiceOp ¶ added in v0.0.3
type RefundServiceOp struct {
// contains filtered or unexported fields
}
func (*RefundServiceOp) Create ¶ added in v0.0.3
func (rs *RefundServiceOp) Create(ctx context.Context, refundParams *RefundParams) (*Refund, error)
func (RefundServiceOp) List ¶ added in v0.0.3
func (rs RefundServiceOp) List(ctx context.Context, opts *RefundsListOptions) (*RefundsRoot, error)
type RefundsListOptions ¶ added in v0.0.3
type RefundsListOptions struct { ListOptions PaymentId string `url:"paymentId"` PaymentPointId string `url:"paymentPointId,omitempty"` CreatedBefore string `url:"createdBefore,omitempty"` CreatedAfter string `url:"createdAfter,omitempty"` }
type RefundsRoot ¶ added in v0.0.3
type RequestCompletionCallback ¶ added in v0.0.3
RequestCompletionCallback defines the type of the request callback function
type Webhook ¶ added in v0.0.3
type Webhook struct { WebhookId string `json:"webhookId"` SignatureKey string `json:"signatureKey"` Url string `json:"url"` Events []WebhookEvent `json:"events"` }
type WebhookCreateParams ¶ added in v0.0.3
type WebhookCreateParams struct { // Find of subscribed events. Events []WebhookEvent `json:"events"` // URL to where webhook requests will be sent. Must be HTTPS. Scheme and host will be converted to lower case. Result can be seen in the response. Url string `json:"url"` }
WebhookCreateParams represents a request to create a payment.
type WebhookEvent ¶ added in v0.0.3
type WebhookEvent string
type WebhookEventEnum ¶ added in v0.0.3
type WebhookEventEnum int
const ( Unknown WebhookEventEnum = iota PaymentReserved PaymentExpired PaymentPointActivated )
func (WebhookEventEnum) Name ¶ added in v0.0.3
func (webhookEvent WebhookEventEnum) Name() WebhookEvent
type WebhookService ¶ added in v0.0.3
type WebhookServiceOp ¶ added in v0.0.3
type WebhookServiceOp struct {
// contains filtered or unexported fields
}
func (*WebhookServiceOp) Create ¶ added in v0.0.3
func (s *WebhookServiceOp) Create(ctx context.Context, createRequest *WebhookCreateParams) (*Webhook, error)
Create webhook
func (*WebhookServiceOp) Delete ¶ added in v0.0.3
func (s *WebhookServiceOp) Delete(ctx context.Context, webhookId string) error
func (*WebhookServiceOp) Find ¶ added in v0.0.3
Get individual webhook. It requires a non-empty webhook id.
func (WebhookServiceOp) Get ¶ added in v0.0.3
func (s WebhookServiceOp) Get(ctx context.Context) (*WebhooksRoot, error)
List all webhooks.
func (WebhookServiceOp) Update ¶ added in v0.0.3
func (s WebhookServiceOp) Update(ctx context.Context, webhookId string, request *WebhookUpdateParams) (*Webhook, error)
type WebhookUpdateParams ¶ added in v0.0.3
type WebhookUpdateParams struct { Url string `json:"url"` Events []WebhookEvent `json:"events"` }
WebhookUpdateParams represents a request to update a webhook record.
type WebhooksRoot ¶ added in v0.0.3
type WebhooksRoot struct {
Webhooks []Webhook `json:"webhooks"`
}
webhooksRoot represents a response from the MobilePay App Payment API
type WebhooksVerifier ¶ added in v0.0.3
type WebhooksVerifier struct {
// contains filtered or unexported fields
}
func NewWebhooksVerifier ¶ added in v0.0.3
func NewWebhooksVerifier(header http.Header, webhookUrl, webhookSignatureKey string) (wv WebhooksVerifier, err error)
NewWebhooksVerifier is a helper function to verify incoming webhooks from Mobilepay. See https://mobilepaydev.github.io/MobilePay-Payments-API/docs/webhooks-api webhookUrl is your webhook url that you used to create the webhook. webhookSignatureKey is returned by Mobilepay when you create a webhook.
func (WebhooksVerifier) Ensure ¶ added in v0.0.3
func (v WebhooksVerifier) Ensure() error