TypeScript SDK
Package:
@mcards/sdkVersion: 2.0.0Requirements: Node.js >= 16, TypeScript >= 4.7 (optional)
Installation
npm install @mcards/sdkHMAC Authentication
typescript
import { McardsSdk } from '@mcards/sdk';
// HMAC authentication
const client = new McardsSdk({
apiKey: process.env.MCARDS_API_KEY!,
apiSecret: process.env.MCARDS_API_SECRET!,
baseUrl: 'https://api.mcards.com', // optional
});
// All requests are automatically signed with HMAC-SHA256
const { data: profile } = await client.partner.getProfile();
console.log(`Partner: ${profile.name}`);OAuth2 Bearer Token
typescript
// OAuth2 Bearer token authentication
const client = new McardsSdk();
// 1. Exchange credentials for token
const { data: token } = await client.oauth.createToken(
'your-client-id',
'your-client-secret',
'partner:read wallets:read cards:read'
);
// 2. Set the Bearer token
client.setBearerToken(token.access_token);
// 3. Make authenticated requests
const { data: wallets } = await client.wallets.list();Error Handling
typescript
// All methods return ApiResponse<T>
interface ApiResponse<T> {
data: T;
status: number;
headers: Record<string, string>;
error?: string;
ok: boolean;
}
// Check response status
const result = await client.cards.get('card-uuid');
if (!result.ok) {
console.error(`Error ${result.status}: ${result.error}`);
return;
}
console.log(result.data); // typed as CardResource Reference
Partner
client.partnergetProfileGET /partner/profileGet partner profile
getProfile(): Promise<ApiResponse<PartnerProfile>>getApiKeysGET /partner/api_keysList API keys
getApiKeys(): Promise<ApiResponse<{ api_keys: ApiKey[] }>>getRolesGET /partner/rolesList partner roles
getRoles(): Promise<ApiResponse<{ roles: Role[] }>>OAuth
client.oauthcreateTokenPOST /oauth/tokenExchange credentials for token
createToken(clientId: string, clientSecret: string, scope?: string): Promise<ApiResponse<TokenResponse>>revokeTokenPOST /oauth/revokeRevoke an access token
revokeToken(token: string): Promise<ApiResponse<void>>getTokenInfoGET /oauth/token_infoIntrospect current token
getTokenInfo(): Promise<ApiResponse<TokenInfo>>listScopesGET /oauth/scopesList available scopes
listScopes(): Promise<ApiResponse<{ scopes: Scope[]; shorthands: Scope[] }>>getRateLimitGET /oauth/rate_limitGet rate limit status
getRateLimit(): Promise<ApiResponse<RateLimitInfo>>listApplicationsGET /oauth/applicationsList OAuth apps
listApplications(): Promise<ApiResponse<{ applications: OAuthApplication[] }>>createApplicationPOST /oauth/applicationsCreate OAuth app
createApplication(name: string, scopes?: string, sandbox?: boolean): Promise<ApiResponse<OAuthApplicationDetail>>getApplicationGET /oauth/applications/:uuidGet app details
getApplication(uuid: string): Promise<ApiResponse<OAuthApplication>>deleteApplicationDELETE /oauth/applications/:uuidRevoke OAuth app
deleteApplication(uuid: string): Promise<ApiResponse<void>>Wallets
client.walletslistGET /walletsList wallets
list(params?: { page?: number; per_page?: number }): Promise<ApiResponse<{ wallets: Wallet[]; meta: PaginationMeta }>>getGET /wallets/:uuidGet wallet details
get(uuid: string): Promise<ApiResponse<Wallet>>updatePUT /wallets/:uuidUpdate wallet
update(uuid: string, data: { name?: string; description?: string }): Promise<ApiResponse<Wallet>>Cards
client.cardslistGET /cardsList cards
list(params?: { page?: number; per_page?: number; status?: string }): Promise<ApiResponse<{ cards: Card[]; meta: PaginationMeta }>>createPOST /cardsIssue a new card
create(data: { cardholder_uuid?: string; program_uuid?: string }): Promise<ApiResponse<Card>>getGET /cards/:uuidGet card details
get(uuid: string): Promise<ApiResponse<Card>>activatePUT /cards/:uuid/activateActivate a card
activate(uuid: string): Promise<ApiResponse<Card>>deactivatePUT /cards/:uuid/deactivateDeactivate a card
deactivate(uuid: string): Promise<ApiResponse<Card>>getBalanceGET /cards/:uuid/balanceGet card balance
getBalance(uuid: string): Promise<ApiResponse<CardBalance>>Transactions
client.transactionslistGET /transactionsList transactions
list(params?: { page?: number; per_page?: number; start_date?: string; end_date?: string; card_uuid?: string }): Promise<ApiResponse<{ transactions: Transaction[]; meta: PaginationMeta }>>getGET /transactions/:uuidGet transaction details
get(uuid: string): Promise<ApiResponse<Transaction>>Sandbox
client.sandboxgetEnvironmentGET /sandboxGet sandbox info
getEnvironment(): Promise<ApiResponse<SandboxEnvironment>>authorizePOST /sandbox/transactions/authorizeSimulate authorization
authorize(data: { amount: number; currency: string; merchant_name: string }): Promise<ApiResponse<SandboxTransaction>>settlePOST /sandbox/transactions/settleSimulate settlement
settle(data: { transaction_id: string; amount?: number }): Promise<ApiResponse<SandboxTransaction>>refundPOST /sandbox/transactions/refundSimulate refund
refund(data: { transaction_id: string; amount?: number }): Promise<ApiResponse<SandboxTransaction>>declinePOST /sandbox/transactions/declineSimulate decline
decline(data: { amount: number; currency: string; merchant_name: string; reason: string }): Promise<ApiResponse<SandboxTransaction>>