revolut-sdk
Version:
SDK for Revolut API
92 lines (91 loc) • 2.62 kB
TypeScript
import { AxiosError } from 'axios';
import { Option } from 'fp-ts/lib/Option';
import { TaskEither } from 'fp-ts/lib/TaskEither';
import { ISOCountryCode, ISODate, ThreeLettersISOCurrencyCode, UUID } from '../common';
import API from './api';
export declare type State = 'pending' | 'completed' | 'declined' | 'failed';
export interface TransferData {
request_id: string;
source_account_id: UUID;
target_account_id: UUID;
amount: number;
currency: ThreeLettersISOCurrencyCode;
description: string;
}
export interface Transfer {
id: UUID;
state: State;
created_at: ISODate;
}
export interface PaymentData {
request_id: string;
account_id: UUID;
receiver: {
counterparty_id: UUID;
account_id?: UUID;
};
amount: number;
currency: ThreeLettersISOCurrencyCode;
description: string;
schedule_for?: ISODate;
}
export interface Payment {
id: UUID;
state: State;
reason: string;
created_at: ISODate;
}
export interface Leg {
leg_id: UUID;
amount: number;
currency: ThreeLettersISOCurrencyCode;
bill_amount?: number;
bill_currency?: ThreeLettersISOCurrencyCode;
account_id: UUID;
counterparty: {
id: UUID;
account_id: UUID;
type: 'self' | 'revolut' | 'external';
};
description: string;
explanation: string;
card: {
card_number: string;
first_name: string;
last_name: string;
phone: string;
};
}
export interface Transaction {
id: UUID;
type: string;
request_id: string;
state: State;
reason?: 'declined' | 'failed';
created_at: ISODate;
updated_at: ISODate;
completed_at?: ISODate;
schedule_for?: ISODate;
merchant?: {
name: string;
city: string;
category_code: string;
country: ISOCountryCode;
};
legs: Leg[];
}
export interface TransactionsParams {
from?: ISODate;
to?: ISODate;
counterparty?: UUID;
count?: number;
type?: string;
}
export default class Payments extends API {
transfer: (transferData: TransferData) => TaskEither<AxiosError, Option<Transfer>>;
pay: (paymentData: PaymentData) => TaskEither<AxiosError, Option<Payment>>;
transactionById: (transactionId: string) => TaskEither<AxiosError, Option<Transaction>>;
transactionByRequestId: (requestId: string) => TaskEither<AxiosError, Option<Transaction>>;
cancel: (transactonId: string) => TaskEither<AxiosError, Option<any>>;
transactions: (params?: TransactionsParams | undefined) => TaskEither<AxiosError, Option<Transaction[]>>;
}