Documentation ¶
Overview ¶
Package revolut provides an SDK to access the Revolut for Business API.
Index ¶
- Constants
- func ValidKey(s string) bool
- func ValidTransactionType(t string) bool
- type Account
- type Address
- type BankDetails
- type Card
- type Client
- func (c *Client) AddExternalCounterparty(cp ExternalCounterparty) (*ExternalCounterpartyResponse, error)
- func (c *Client) AddRevolutCounterparty(cp InternalCounterparty) (*CounterpartyResponse, error)
- func (c *Client) CancelPayment(id string) error
- func (c *Client) Delete(path string) ([]byte, int, error)
- func (c *Client) DeleteCounterparty(id string) error
- func (c *Client) GetAccount(id string) (*Account, error)
- func (c *Client) GetAccountDetails(id string) ([]BankDetails, error)
- func (c *Client) GetAccounts() ([]Account, error)
- func (c *Client) GetCounterparties() ([]Counterparty, error)
- func (c *Client) GetCounterparty(id string) (*Counterparty, error)
- func (c *Client) GetJSON(path string) ([]byte, int, error)
- func (c *Client) GetTransactions(ttype, from, to, counterparty string, count int64) ([]TransactionStatus, error)
- func (c *Client) Pay(id, account, cp, cpAccount, currency, reference, schedule string, ...) (*PaymentResponse, error)
- func (c *Client) PostJSON(path string, data interface{}) ([]byte, int, error)
- func (c *Client) SetAPI(key string) error
- func (c *Client) TransactionStatus(id string) (*TransactionStatus, error)
- func (c *Client) Transfer(id, sid, tid, currency, reference string, amount float64) (*TransferResponse, error)
- type Counterparty
- type CounterpartyAccount
- type CounterpartyResponse
- type ErrorResponse
- type EstimatedTime
- type ExternalAccount
- type ExternalCounterparty
- type ExternalCounterpartyResponse
- type IndividualName
- type InternalCounterparty
- type Leg
- type LegCounterparty
- type Merchant
- type PaymentRequest
- type PaymentResponse
- type Receiver
- type TransactionStatus
- type TransferRequest
- type TransferResponse
Constants ¶
const ( // EventCreated is for TransactionCreated hooks. EventCreated = "TransactionCreated" // EventStateChange is for TransactionStateChanged hooks. EventStateChange = "TransactionStateChanged" )
const (
// ErrKeyFormat means the API key string is mangled.
ErrKeyFormat = "API key has the wrong format - not starting with sand_ or prod_"
)
Internal errors
Variables ¶
This section is empty.
Functions ¶
func ValidKey ¶
ValidKey checks that the supplied string conforms roughly to a valid Revolut API key's format.
func ValidTransactionType ¶ added in v0.15.0
ValidTransactionType checks if a type filter is correct.
Types ¶
type Account ¶
type Account struct { // ID is the UUID, and is always available. ID string `json:"id"` // Name is the display name. Not used in counterparty responses. Name string `json:"name,omitempty"` // Balance is not used in counterparty responses. Balance float64 `json:"balance,omitempty"` // Currency is always available. Currency string `json:"currency"` // State is not used in counterparty responses. State string `json:"state,omitempty"` // Public is not used in counterparty responses. Public bool `json:"public,omitempty"` // Created is an ISO date/time. Not used in counterparty responses. Created string `json:"created_at,omitempty"` // Updated is an ISO date/time. Mot used in counterparty responses. Updated string `json:"updated_at,omitempty"` // Type is only used in counterparty responses. Type string `json:"type,omitempty"` }
Account holds one business account, or the response from adding a counterparty.
type Address ¶
type Address struct { // Street1 is line 1 of the address. Street1 string `json:"street_line1"` // Street2 is line 2 of the address. Street2 string `json:"street_line2"` // Region of the beneficiary. Region string `json:"region"` // City of the beneficiary. City string `json:"city"` // Country of the beneficiary. This is a two-letter ISO code. Country string `json:"country"` // Postcode of the beneficiary. Postcode string `json:"postcode"` }
Address is an account-holder's address.
type BankDetails ¶
type BankDetails struct { // IBAN if applicable. IBAN string `json:"iban,omitempty"` // BIC if applicable. BIC string `json:"bic,omitempty"` // AccountNo if applicable. AccountNo string `json:"account_no,omitempty"` // SortCode if applicable. SortCode string `json:"sort_code,omitempty"` // RoutingNo for the bank. RoutingNo string `json:"routing_number,omitempty"` // Beneficiary name. Beneficiary string `json:"beneficiary"` // BeneficiaryAddress is a sub-structure. Address Address `json:"beneficiary_address"` // Country of the bank. This is a two-letter ISO code. Country string `json:"bank_country"` // Pooled or unique status. Pooled bool `json:"pooled"` // UniqueReference of the pooled account. UniqueReference string `json:"unique_reference,omitempty"` //Schemes is one of: chaps, bacs, faster_payments, sepa, swift, ach Schemes []string `json:"schemes"` // EstimatedTime for transfers. EstimatedTime EstimatedTime `json:"estimated_time"` }
BankDetails can be retrieved for an account ID.
type Card ¶
type Card struct { // Number is the masked card number. Number string `json:"card_number"` // First name of the card holder. First string `json:"first_name"` // Last name of the card holder. Last string `json:"last_name"` // Phone number of the card holder. Phone string `json:"phone"` }
Card is used for card payments.
type Client ¶
type Client struct { http.Client //ErrorCode is the last HTTP error code. ErrorCode int // Agent should be customised per app. Agent string // contains filtered or unexported fields }
Client is the core structure for Revolut API access.
func (*Client) AddExternalCounterparty ¶
func (c *Client) AddExternalCounterparty(cp ExternalCounterparty) (*ExternalCounterpartyResponse, error)
AddExternalCounterparty adds a non-Revolut account as a counterparty.
func (*Client) AddRevolutCounterparty ¶
func (c *Client) AddRevolutCounterparty(cp InternalCounterparty) (*CounterpartyResponse, error)
AddRevolutCounterparty adds a Revolut personal or business account as a counterparty.
func (*Client) CancelPayment ¶ added in v0.16.0
CancelPayment if possible.
func (*Client) Delete ¶
Delete sends a delete command to an endpoint. The URL is the data and the HTTP response code is the only result.
func (*Client) DeleteCounterparty ¶
DeleteCounterparty removes a counterparty by UUID.
func (*Client) GetAccount ¶
GetAccount retrieves the basic information for a given account ID.
func (*Client) GetAccountDetails ¶
func (c *Client) GetAccountDetails(id string) ([]BankDetails, error)
GetAccountDetails retrieves BankDetails for one specified account.
func (*Client) GetAccounts ¶
GetAccounts lists the accounts for a given API key.
func (*Client) GetCounterparties ¶
func (c *Client) GetCounterparties() ([]Counterparty, error)
GetCounterparties returns a list of all counterparties for an API key.
func (*Client) GetCounterparty ¶
func (c *Client) GetCounterparty(id string) (*Counterparty, error)
GetCounterparty gets a counterparty by ID.
func (*Client) GetTransactions ¶
func (c *Client) GetTransactions(ttype, from, to, counterparty string, count int64) ([]TransactionStatus, error)
GetTransactions by optional filters. The from and to datescan be in the formats YYYY-MM-DD or RFC3339.
func (*Client) Pay ¶ added in v0.14.0
func (c *Client) Pay(id, account, cp, cpAccount, currency, reference, schedule string, amount float64) (*PaymentResponse, error)
Pay a Revolut account or external account.
func (*Client) PostJSON ¶
PostJSON builds the full endpoint path and posts the provided data, returning the JSON response.
func (*Client) SetAPI ¶
SetAPI sets the API key and type to use (sandbox or production). Sandbox keys start with "sand_" and production keys start with "prod_".
func (*Client) TransactionStatus ¶ added in v0.15.0
func (c *Client) TransactionStatus(id string) (*TransactionStatus, error)
TransactionStatus of transfers or payments.
type Counterparty ¶
type Counterparty struct { // ID is a UUID. ID string `json:"id"` // Name of the counterparty. Name string `json:"name"` // Phone number. Phone string `json:"phone"` // Type is "personal" or "business". Type string `json:"profile_type"` // Country is a two-letter ISO code. Country string `json:"country"` // State of the counterparty is a status string. State string `json:"state"` // CreatedAt is a timestamp for when this was added. CreatedAt time.Time `json:"created_at"` // UpdatedAt is a timestamp for the last change to the counterparty, UpdatedAt time.Time `json:"updated_at"` // Accounts is a list of public accounts for this counterparty. Accounts []CounterpartyAccount `json:"accounts"` }
Counterparty is returned from the /counterparty and /counterparties endpoints.
type CounterpartyAccount ¶
type CounterpartyAccount struct { // ID is the UUID. ID string `json:"id"` // Currency is a three-letter shortname. Currency string `json:"currency"` // Type of account is either "revolut" or "external". Type string `json:"type"` // Account number. Account string `json:"account_no"` // SortCode if used. SortCode string `json:"sort_code"` // Email for the recipient. Email string `json:"email"` // Name of the business or person this account belongs to. Name string `json:"name"` // Country is a two-letter ISO code. Country string `json:"bank_country"` // Charges may be added. Charges string `json:"recipient_charges"` }
CounterpartyAccount is embedded in Counterparty structures.
type CounterpartyResponse ¶
type CounterpartyResponse struct { // ID is the UUID of the counterparty. ID string `json:"id"` // Name of the counterparty. Name string `json:"name"` // Phone number of a personal account. Phone string `json:"phone"` // ProfileType is "business" or "personal". ProfileType string `json:"profile_type"` // Country is a 2-letter code. Country string `json:"bank_country"` // State is either "created" or "deleted". State string `json:"state"` // CreatedAt is the ISO time when the counterparty was created. CreatedAt string `json:"created_at"` // UpdateAt is the ISO time when the counterparty was last updated. UpdatedAt string `json:"updated_at"` // Accounts is a list of all the counterparty's accounts. Accounts []Account `json:"accounts"` }
CounterpartyResponse is returned after adding/removing a Revolut counterparty.
type ErrorResponse ¶ added in v0.13.0
type ErrorResponse struct { // Message is a clarification of what went wrong. Message string `json:"message"` // Code is an internal error code. Code int `json:"code"` }
ErrorResponse from JSON endpoints.
type EstimatedTime ¶
type EstimatedTime struct { // Unit is "days" or "hours". Unit string `json:"unit"` // Max days or hours. Max int `json:"max"` // Min days or hours. Min int `json:"min"` }
EstimatedTime for transfers.
type ExternalAccount ¶
type ExternalAccount struct { // ID of a counterparty's account. ID string `json:"id"` // Currency is a 3-letter ISO code. Currency string `json:"currency"` // Type is "revolut" or "external". Type string `json:"type"` // AccountNo for UK GBP, US USD and SWIFT accounts AccountNo string `json:"account_no"` // IBAN of a foreign account. IBAN string `json:"iban"` // SortCode of a UK GBP account. SortCode string `json:"sort_code"` // RoutingNo of a US USD account RoutingNo string `json:"routing_number"` // BIC of an IBAN/SWIFT account. BIC string `json:"bic"` // RecipientCharges is "no", "expected" or possible "free". TODO: Clarify with devs. RecipientCharges string `json:"recipient_charges"` }
ExternalAccount for counterparties in other banks.
type ExternalCounterparty ¶
type ExternalCounterparty struct { // Company must exist if Individual isn't present. Company string `json:"company_name,omitempty"` // Individual must exist if Company isn't present. Name *IndividualName `json:"individual_name,omitempty"` // BankCountry is a two-letter ISO code. BankCountry string `json:"bank_country"` // Currency is a 3-letter ISO code. Currency string `json:"currency"` // Email is convenient, but optional. Email string `json:"email,omitempty"` // Phone is convenient, but optional. Phone string `json:"phone,omitempty"` // Address is optional, although some bank systems require them to verify recipients. Address Address `json:"address,omitempty"` // AccountNo is required for UK GBP, US USD and SWIFT accounts. AccountNo string `json:"account_no"` // SortCode is required for UK GBP accounts. SortCode string `json:"sort_code,omitempty"` // RoutingNo is required for US USD accounts. RoutingNo string `json:"routing_number,omitempty"` // IBAN is required for IBAN countries. IBAN string `json:"iban,omitempty"` // BIC is required for IBAN/SWIFT accounts. BIC string `json:"bic,omitempty"` }
ExternalCounterparty is used when adding a counterparty with a non-Revolut account.
type ExternalCounterpartyResponse ¶
type ExternalCounterpartyResponse struct { // ID is the UUID of the counterparty. ID string `json:"id"` // Name Name string `json:"name"` // State is either "created" or "deleted". State string `json:"state"` // CreatedAt is the ISO time/date this counterparty was created. CreatedAt string `json:"created_at"` // UpdatedAt is the ISO time/date this counterparty was last modified. UpdatedAt string `json:"updated_at"` // Accounts known for this counterparty. Accounts []ExternalAccount `json:"accounts"` }
ExternalCounterpartyResponse is returned after adding/removing an external counterparty.
type IndividualName ¶
type IndividualName struct { // First name. First string `json:"first_name,omitempty"` // Last name. Last string `json:"last_name,omitempty"` }
IndividualName of an account holder.
type InternalCounterparty ¶
type InternalCounterparty struct { // ProfileType is "business" or "personal". ProfileType string `json:"profile_type"` // Name of the counterparty. Name string `json:"name,omitempty"` // Phone is used with personal accounts. Phone string `json:"phone,omitempty"` // Email is an optional field with the address of the admin for a business account. Email string `json:"email,omitempty"` }
InternalCounterparty is used when adding an existing Revolut account as a counterparty (i.e. contact).
type Leg ¶
type Leg struct { // ID of this leg. ID string `json:"leg_id"` // Amount of the transactiob. Amount float64 `json:"amount"` // Currency is the 3-letter ISO code for the transaction currency. Currency string `json:"currency"` // BillAmount is the amount for cross-currency transactions. BillAmount float64 `json:"bill_amount,omitempty"` // BillCurrency is the billing currency for cross-currency transactions. BillCurrency string `json:"bill_currency,omitempty"` // AccountID of the account this transaction is associated with. AccountID string `json:"account_id"` // Counterparty for this leg. Counterparty LegCounterparty `json:"counterparty"` // Description contains the leg purpose. Description string `json:"description"` // Card information only for card payments. Card Card `json:"card,omitempty"` }
Leg of the transaction process.
type LegCounterparty ¶
type LegCounterparty struct { ID string `json:"id"` // Type is "self", "revolut" or "external". Type string `json:"type"` AccountID string `json:"account_id"` }
LegCounterparty is a quick summary of the counterparty involved in this leg of the transaction.
type Merchant ¶
type Merchant struct { // Name of the merchant. Name string `json:"name"` // City of the merchant. City string `json:"city"` // Category code for the transaction. Category string `json:"category_code"` // Country is the 3-letter ISO bank country code. Country string `json:"country"` }
Merchant info.
type PaymentRequest ¶
type PaymentRequest struct { // RequestID for the payment, provided by the client. RequestID string `json:"request_id"` // AccountID of the account to pay from. AccountID string `json:"account_id"` // Receiver of this payment. Receiver Receiver `json:"receiver"` // Amount to pay. Amount float64 `json:"amount"` // Currency for the transaction. 3-letter ISO code. Currency string `json:"currency"` // Reference is an optional text to show on the transaction. Highly recommended. Reference string `json:"reference,omitempty"` // ScheduleTime to initiate the payment. There's no guarantee this will be fulfilled right away if the current time is used. ScheduleTime string `json:"schedule_for,omitempty"` }
PaymentRequest for payments to counterparties.
type PaymentResponse ¶
type PaymentResponse struct { // ID of the created transaction. ID string `json:"id"` // State is one of "pending", "completed", "declined" or "failed". State string `json:"state"` // Reason is a code for the "declined" or "failed" states. Reason string `json:"reason_code"` // CreatedAt is the ISO time when the payment was requested. CreatedAt string `json:"created_at"` // CompletedAt is the ISO time when the payment finished. Not available for asynchronous or scheduled payments. CompletedAt string `json:"completed_at"` }
PaymentResponse for a request.
type Receiver ¶
type Receiver struct { // CounterpartyID for the receiving party. CounterpartyID string `json:"counterparty_id"` // AccountID is optional. AccountID string `json:"account_id,omitempty"` }
Receiver of a payment.
type TransactionStatus ¶
type TransactionStatus struct { // ID of the transaction. ID string `json:"id"` // Type of transaction. Type string `json:"type"` // RequestID provided by the client. RequestID string `json:"request_id"` // State is one of "pending", "completed", "declined" or "failed". State string `json:"state"` // Reason code for the "declined" and "failed" states. Reason string `json:"reason_code"` // CreatedAt is an ISO date/time. CreatedAt string `json:"created_at"` // UpdatedAt is an ISO date/time. Available when looking up transactions. UpdatedAt string `json:"updated_at,omitempty"` // CompletedAt is an ISO date/time. CompletedAt string `json:"completed_at,omitempty"` // Scheduled time is an ISO date/time the transaction was scheduled to run. ScheduledTime string `json:"scheduled_for"` // Merchant info. Merchant Merchant `json:"merchant"` // Reference for the payment provided by the user. Reference string `json:"reference"` // Legs of the transaction. There will be 2 legs between your Revolut accounts and 1 in other cases. Legs []Leg `json:"legs"` }
TransactionStatus is returned by GetTransaction() and GetTransactions().
type TransferRequest ¶
type TransferRequest struct { // Amount to transfer. Amount float64 `json:"amount"` // ID of the request, provided by the client. ID string `json:"request_id"` // SourceID of the account to transfer from. SourceID string `json:"source_account_id"` // TargetID of the account to transfer to. TargetID string `json:"target_account_id"` // Currency to use. Currency string `json:"currency"` // Reference is an optional text to show on the transaction. Highly recommended. Reference string `json:"reference"` }
TransferRequest for money transfers within a business.
type TransferResponse ¶
type TransferResponse struct { // ID of the created transaction. ID string `json:"id"` // State of the transaction. One of the following: "pending", "completed", "declined" or "failed". State string `json:"state"` // CreatedAT ISO date/time. CreatedAt string `json:"created_at"` // CompletedAt ISO date/time. CompletedAt string `json:"completed_at"` }
TransferResponse to a transfer request.