multisafepay

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusCompleted       = "completed"
	StatusInitialized     = "initialized"
	StatusDeclined        = "declined"
	StatusCancelled       = "cancelled"
	StatusVoid            = "void"
	StatusUncleared       = "uncleared"
	StatusRefunded        = "refunded"
	StatusPartialRefunded = "partial_refunded"
	StatusReserved        = "reserved"
	StatusChargedBack     = "chargedback"
	StatusShipped         = "shipped"
)

The constants below correspond to all possible transaction statuses. See: https://docs.multisafepay.com/api/#transaction-statuses

View Source
const LiveAPIURL = "https://api.multisafepay.com/v1/json"

LiveAPIURL is used to access the 'normal' API

View Source
const RFC3339NZ = "2006-01-02T15:04:05"

RFC3339NZ is time.RFC3339 without timezones

View Source
const TestAPIURL = "https://testapi.multisafepay.com/v1/json"

TestAPIURL is used to access the testing API

Variables

This section is empty.

Functions

func IsValidStatus

func IsValidStatus(status string) bool

IsValidStatus returns true if the status string is one of the possible responses as mentioned in the MultiSafePay documentation See: https://docs.multisafepay.com/api/#transaction-statuses

Types

type APIError

type APIError struct {
	Method  string
	URL     string
	Status  string
	Message string
}

APIError reports error responses from API requests, i.e. when the status is anything other than 200

func (APIError) Error

func (e APIError) Error() string

Error implements builtin error interface

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles all interaction with the MultiSafePay API

func NewClient

func NewClient(url, apiKey string) *Client

NewClient creates a new client with a provided URL and API key

func (*Client) CreateOrder

func (c *Client) CreateOrder(o Order) (*PostOrderResponse, error)

CreateOrder creates a new order

func (*Client) Get

func (c *Client) Get(route string) (io.ReadCloser, error)

Get will perform a GET-request to the API

func (*Client) GetOrder

func (c *Client) GetOrder(orderID string) (*GetOrderResponse, error)

GetOrder fetches an order

func (*Client) Post

func (c *Client) Post(route string, data interface{}) (io.ReadCloser, error)

Post will perform a POST-request to the API with JSON-encoded data

type Cost

type Cost struct {
	TransactionID ID      `json:"transaction_id"`
	Description   string  `json:"description"`
	Type          string  `json:"type"`
	Status        string  `json:"status"`
	Created       Time    `json:"created"`
	Amount        float64 `json:"amount"`
}

Cost is a cost as presented in: https://docs.multisafepay.com/api/#retrieve-an-order

type Customer

type Customer struct {
	Locale      string `json:"locale,omitempty"`
	IPAddress   string `json:"ip_address,omitempty"`
	FirstName   string `json:"first_name,omitempty"`
	LastName    string `json:"last_name,omitempty"`
	Company     string `json:"company,omitempty"`
	Address1    string `json:"address1,omitempty"`
	HouseNumber string `json:"house_number,omitempty"`
	ZIPCode     string `json:"zip_code,omitempty"`
	City        string `json:"city,omitempty"`
	Country     string `json:"country,omitempty"`
	Phone       string `json:"phone,omitempty"`
	Email       string `json:"email,omitempty"`
	Referrer    string `json:"referrer,omitempty"`
	UserAgent   string `json:"user_agent,omitempty"`
}

Customer structure, see: https://docs.multisafepay.com/api/#customer-object

type ErrorResponse

type ErrorResponse struct {
	Response

	Data      interface{} `json:"data,omitempty"`
	ErrorCode int         `json:"error_code"`
	ErrorInfo string      `json:"error_info"`
}

ErrorResponse contains information about errors as reported by the API

type GetOrderResponse

type GetOrderResponse struct {
	Response

	Data struct {
		TransactionID       ID                     `json:"transaction_id"`
		OrderID             ID                     `json:"order_id"`
		Created             Time                   `json:"created"`
		Currency            string                 `json:"currency"`
		Amount              int                    `json:"amount"`
		Description         string                 `json:"description"`
		AmountRefunded      int                    `json:"amount_refunded"`
		Status              string                 `json:"status,omitempty"`
		FinancialStatus     string                 `json:"financial_status"`
		Reason              string                 `json:"reason"`
		ReasonCode          string                 `json:"reason_code"`
		FastCheckout        string                 `json:"fastcheckout"`
		Modified            Time                   `json:"modified"`
		Customer            *Customer              `json:"customer"`
		PaymentDetails      map[string]interface{} `json:"payment_details"`
		Costs               []Cost                 `json:"costs"`
		RelatedTransactions []struct {
			Amount        int    `json:"amount"`
			Costs         []Cost `json:"costs"`
			Created       Time   `json:"created"`
			Currency      string `json:"currency"`
			Description   string `json:"description"`
			Modified      Time   `json:"modified"`
			Status        string `json:"status"`
			TransactionID ID     `json:"transaction_id"`
		} `json:"related_transactions"`
		PaymentMethods []map[string]interface{} `json:"payment_methods"`
	}
}

GetOrderResponse is a response to GET /orders/{order_id}: https://docs.multisafepay.com/api/#retrieve-an-order

type ID

type ID string

ID is a type for decoding IDs in JSON responses from MultiSafePay that do not obey a strict rule with regards to which type is returned. When the API determines that the order ID string only contains numbers, it returns the value as a `number` type, instead of the `string` type. This type's value is guaranteed to be represented as a string in JSON.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type Order

type Order struct {
	Type           string          `json:"type,omitempty"`
	OrderID        ID              `json:"order_id,omitempty"`
	Gateway        string          `json:"gateway,omitempty"`
	Currency       string          `json:"currency,omitempty"`
	Amount         int             `json:"amount,omitempty"`
	Description    string          `json:"description,omitempty"`
	PaymentOptions *PaymentOptions `json:"payment_options,omitempty"`
	Customer       *Customer       `json:"customer,omitempty"`
	SecondChance   struct {
		SendEmail bool `json:"send_email"`
	} `json:"second_chance"`
}

Order structure, see: https://docs.multisafepay.com/api/#orders

type PaymentOptions

type PaymentOptions struct {
	NotificationURL    string `json:"notification_url,omitempty"`
	NotificationMethod string `json:"notification_method,omitempty"`
	RedirectURL        string `json:"redirect_url,omitempty"`
	CancelURL          string `json:"cancel_url,omitempty"`
	CloseWindow        string `json:"close_window,omitempty"`
}

PaymentOptions structure, see: https://docs.multisafepay.com/api/#payment-option-object

type PostOrderResponse

type PostOrderResponse struct {
	Response

	Data struct {
		OrderID    ID     `json:"order_id"`
		PaymentURL string `json:"payment_url,omitempty"`
	} `json:"data"`
}

PostOrderResponse is a response to POST /orders: https://docs.multisafepay.com/api/#orders

type Response

type Response struct {
	Success bool `json:"success"`
}

Response from the API, contains a boolean to indicate success

type Time

type Time struct {
	time.Time
}

Time format used by MultiSafePay. RFC3339 without timezone

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL