@cardql/core
Version:
CardQL core SDK for payment processing - cross-platform shared logic, auth and data access
250 lines (218 loc) • 7.11 kB
text/typescript
import { CardQLClient } from "./client";
import type {
Account,
App,
Customer,
Merchant,
Payment,
Ledger,
CreateAccountInput,
UpdateAccountInput,
CreateAppInput,
UpdateAppInput,
CreateCustomerInput,
UpdateCustomerInput,
CreateMerchantInput,
UpdateMerchantInput,
CreatePaymentInput,
UpdatePaymentInput,
CreateLedgerInput,
UpdateLedgerInput,
} from "./types";
import * as queries from "./queries";
export class CardQLApi {
constructor(private client: CardQLClient) {}
// Account methods
async getAccounts(): Promise<Account[]> {
const result = await this.client.requestWithRetry<{ accounts: Account[] }>(
queries.GET_ACCOUNTS
);
return result.accounts;
}
async getAccount(accountID: string): Promise<Account | null> {
const result = await this.client.requestWithRetry<{
account: Account | null;
}>(queries.GET_ACCOUNT, { accountID });
return result.account;
}
async createAccount(input: CreateAccountInput): Promise<Account> {
const result = await this.client.requestWithRetry<{
createAccount: Account;
}>(queries.CREATE_ACCOUNT, input);
return result.createAccount;
}
async updateAccount(input: UpdateAccountInput): Promise<Account> {
const result = await this.client.requestWithRetry<{
updateAccount: Account;
}>(queries.UPDATE_ACCOUNT, input);
return result.updateAccount;
}
async deleteAccount(id: string): Promise<string> {
const result = await this.client.requestWithRetry<{
deleteAccount: string;
}>(queries.DELETE_ACCOUNT, { id });
return result.deleteAccount;
}
// App methods
async getApps(): Promise<App[]> {
const result = await this.client.requestWithRetry<{ apps: App[] }>(
queries.GET_APPS
);
return result.apps;
}
async getApp(id: string): Promise<App | null> {
const result = await this.client.requestWithRetry<{ app: App | null }>(
queries.GET_APP,
{ id }
);
return result.app;
}
async createApp(input: CreateAppInput): Promise<App> {
const result = await this.client.requestWithRetry<{ createApp: App }>(
queries.CREATE_APP,
input
);
return result.createApp;
}
async updateApp(input: UpdateAppInput): Promise<App> {
const result = await this.client.requestWithRetry<{ updateApp: App }>(
queries.UPDATE_APP,
input
);
return result.updateApp;
}
async deleteApp(id: string): Promise<string> {
const result = await this.client.requestWithRetry<{ deleteApp: string }>(
queries.DELETE_APP,
{ id }
);
return result.deleteApp;
}
// Customer methods
async getCustomers(): Promise<Customer[]> {
const result = await this.client.requestWithRetry<{
customers: Customer[];
}>(queries.GET_CUSTOMERS);
return result.customers;
}
async getCustomer(id: string): Promise<Customer | null> {
const result = await this.client.requestWithRetry<{
customer: Customer | null;
}>(queries.GET_CUSTOMER, { id });
return result.customer;
}
async createCustomer(input: CreateCustomerInput): Promise<Customer> {
const result = await this.client.requestWithRetry<{
createCustomer: Customer;
}>(queries.CREATE_CUSTOMER, input);
return result.createCustomer;
}
async updateCustomer(input: UpdateCustomerInput): Promise<Customer> {
const result = await this.client.requestWithRetry<{
updateCustomer: Customer;
}>(queries.UPDATE_CUSTOMER, input);
return result.updateCustomer;
}
async deleteCustomer(id: string): Promise<string> {
const result = await this.client.requestWithRetry<{
deleteCustomer: string;
}>(queries.DELETE_CUSTOMER, { id });
return result.deleteCustomer;
}
// Merchant methods
async getMerchants(): Promise<Merchant[]> {
const result = await this.client.requestWithRetry<{
merchants: Merchant[];
}>(queries.GET_MERCHANTS);
return result.merchants;
}
async getMerchant(id: string): Promise<Merchant | null> {
const result = await this.client.requestWithRetry<{
merchant: Merchant | null;
}>(queries.GET_MERCHANT, { id });
return result.merchant;
}
async createMerchant(input: CreateMerchantInput): Promise<Merchant> {
const result = await this.client.requestWithRetry<{
createMerchant: Merchant;
}>(queries.CREATE_MERCHANT, input);
return result.createMerchant;
}
async updateMerchant(input: UpdateMerchantInput): Promise<Merchant> {
const result = await this.client.requestWithRetry<{
updateMerchant: Merchant;
}>(queries.UPDATE_MERCHANT, input);
return result.updateMerchant;
}
async deleteMerchant(id: string): Promise<string> {
const result = await this.client.requestWithRetry<{
deleteMerchant: string;
}>(queries.DELETE_MERCHANT, { id });
return result.deleteMerchant;
}
// Payment methods
async getPayments(): Promise<Payment[]> {
const result = await this.client.requestWithRetry<{ payments: Payment[] }>(
queries.GET_PAYMENTS
);
return result.payments;
}
async getPayment(id: string): Promise<Payment | null> {
const result = await this.client.requestWithRetry<{
payment: Payment | null;
}>(queries.GET_PAYMENT, { id });
return result.payment;
}
async createPayment(input: CreatePaymentInput): Promise<Payment> {
const result = await this.client.requestWithRetry<{
createPayment: Payment;
}>(queries.CREATE_PAYMENT, input);
return result.createPayment;
}
async updatePayment(input: UpdatePaymentInput): Promise<Payment> {
const result = await this.client.requestWithRetry<{
updatePayment: Payment;
}>(queries.UPDATE_PAYMENT, input);
return result.updatePayment;
}
async deletePayment(id: string): Promise<string> {
const result = await this.client.requestWithRetry<{
deletePayment: string;
}>(queries.DELETE_PAYMENT, { id });
return result.deletePayment;
}
// Ledger methods
async getLedgers(): Promise<Ledger[]> {
const result = await this.client.requestWithRetry<{ ledgers: Ledger[] }>(
queries.GET_LEDGERS
);
return result.ledgers;
}
async getLedger(id: string): Promise<Ledger | null> {
const result = await this.client.requestWithRetry<{
ledger: Ledger | null;
}>(queries.GET_LEDGER, { id });
return result.ledger;
}
async createLedger(input: CreateLedgerInput): Promise<Ledger> {
const result = await this.client.requestWithRetry<{ createLedger: Ledger }>(
queries.CREATE_LEDGER,
input
);
return result.createLedger;
}
async updateLedger(input: UpdateLedgerInput): Promise<Ledger> {
const result = await this.client.requestWithRetry<{ updateLedger: Ledger }>(
queries.UPDATE_LEDGER,
input
);
return result.updateLedger;
}
async deleteLedger(id: string): Promise<string> {
const result = await this.client.requestWithRetry<{ deleteLedger: string }>(
queries.DELETE_LEDGER,
{ id }
);
return result.deleteLedger;
}
}