kirapay-sdk
Version:
Official TypeScript/JavaScript SDK for KiraPay API
145 lines (141 loc) • 3.94 kB
text/typescript
interface ApiResponse<T = any> {
message: string;
data: T;
code: number;
}
interface ApiError {
statusCode: number;
message: string;
timestamp?: string;
path?: string;
}
interface TokenOut {
symbol: string;
address: string;
decimals: number;
chain: string;
}
interface User {
_id: string;
username: string;
address?: string;
isVerified?: boolean;
}
interface CreateLinkRequest {
currency: 'USDC';
receiver: string;
price: number;
name: string;
redirectUrl?: string;
}
interface CreateLinkResponse {
url: string;
}
interface PaymentLink {
_id: string;
code: string;
price: number;
tokenOut: TokenOut;
receiver: string;
user: string | User;
key: string;
name: string;
redirectUrl?: string;
createdAt: string;
updatedAt: string;
url?: string;
}
interface GetLinksRequest {
page?: number;
limit?: number;
}
interface GetLinksResponse {
links: PaymentLink[];
total: number;
page: number;
totalPages: number;
}
type TransactionStatus = 'PENDING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
type TransactionType = 'Contract' | 'Transfer' | 'Refund';
interface TransactionPayload {
eventNonce: string;
attestation: string;
cctpVersion: number;
sender: string;
recipient: string;
mintRecipient: string;
messageSender: string;
amount: string;
maxFee: number;
feeExecuted: number;
sourceDomain: number;
destinationDomain: number;
status: string;
}
interface Transaction {
_id: string;
price: number;
hash: string;
status: string;
type: TransactionType;
user: User;
link: string;
source: string;
createdAt: string;
updatedAt: string;
__v: number;
payload: TransactionPayload;
}
interface GetTransactionsRequest {
status?: TransactionStatus;
transaction_hash?: string;
from_date?: string;
to_date?: string;
page?: number;
limit?: number;
}
interface GetTransactionsResponse {
transactions: Transaction[];
total: number;
page: number;
totalPages: number;
}
interface KiraPayConfig {
apiKey: string;
baseUrl?: string;
}
interface HttpClient {
get<T>(url: string, params?: any): Promise<T>;
post<T>(url: string, data?: any): Promise<T>;
put<T>(url: string, data?: any): Promise<T>;
delete<T>(url: string): Promise<T>;
}
declare class KiraPay {
private httpClient;
private config;
constructor(config: KiraPayConfig, httpClient?: HttpClient);
createPaymentLink(request: CreateLinkRequest): Promise<CreateLinkResponse>;
getPaymentLinks(request?: GetLinksRequest): Promise<GetLinksResponse>;
getPaymentLinkByCode(code: string): Promise<PaymentLink>;
getWalletTransactions(request?: GetTransactionsRequest): Promise<GetTransactionsResponse>;
getConfig(): KiraPayConfig;
setApiKey(apiKey: string): void;
setBaseUrl(baseUrl: string): void;
}
declare class DefaultHttpClient implements HttpClient {
private baseUrl;
private apiKey;
constructor(baseUrl: string, apiKey: string);
private request;
get<T>(url: string, params?: any): Promise<T>;
post<T>(url: string, data?: any): Promise<T>;
put<T>(url: string, data?: any): Promise<T>;
delete<T>(url: string): Promise<T>;
}
declare class KiraPayError extends Error {
statusCode: number;
timestamp?: string | undefined;
path?: string | undefined;
constructor(error: ApiError);
}
export { type ApiError, type ApiResponse, type CreateLinkRequest, type CreateLinkResponse, DefaultHttpClient, type GetLinksRequest, type GetLinksResponse, type GetTransactionsRequest, type GetTransactionsResponse, type HttpClient, KiraPay, type KiraPayConfig, KiraPayError, type PaymentLink, type TokenOut, type Transaction, type TransactionPayload, type TransactionStatus, type TransactionType, type User, KiraPay as default };