@moneygraph/sdk
Version:
AI-native SDK for global payouts powered by StratosPay
262 lines (261 loc) • 11 kB
JavaScript
;
/**
* MoneyGraph SDK - Reference Module
*
* Reference data APIs:
* - Countries
* - Currencies with rates
* - Source of funds
* - MCC (Merchant Category Codes)
* - Business registration types
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReferenceModule = void 0;
// Mock reference data for sandbox
const MOCK_SOURCE_OF_FUNDS = [
{ id: '07ffbc0b-6d9a-419a-9ff0-23dff3047ee1', name: 'Funds from other auxiliary sources' },
{ id: '0a685668-1208-4d40-9c30-fdf520296c1c', name: 'Family Savings' },
{ id: '1694d1cb-fcc1-404e-a492-57f150be3b5d', name: 'Sale of Company Share' },
{ id: '1b5dfd0f-3f6a-4e05-a2ab-4b19c400fb4f', name: 'Labour Contract' },
{ id: '1e2b8858-e0e5-43b1-bdad-fc55a7fa7a19', name: 'Dividends' },
{ id: '22bc46b1-6a5a-493b-96cd-61b986ab698d', name: 'Sales of Real Estate' },
{ id: '5554868d-3826-4a39-a7e9-78e869a2c7a7', name: 'Ordinary Business Activities' },
{ id: '67149843-633d-4471-bbbb-b15be843905e', name: 'Sales of Movable Assets' },
{ id: '793cbc60-19db-4044-97eb-cd6b90fd34af', name: 'Inheritance' },
{ id: '92ee4a59-d8df-42d5-bffa-cf679b69b9bc', name: 'Loan from Financial Institutions or Credit Unions' },
{ id: 'a7b454d4-4e7c-4473-95bb-d2ebadf9490e', name: 'Rent' },
{ id: 'bc497c01-1d53-4383-8988-d522a3b561cd', name: 'Civil Contract' },
{ id: 'c579a74d-bccf-41bc-90b0-6f1546197771', name: 'Personal Savings' },
{ id: 'd7f1dea0-948a-4833-a7e1-2ece197df075', name: 'Loan from Third Parties' },
];
const MOCK_MCC = [
{ id: '04bd1dcc-6851-41c4-9712-bb1ce43016bd', name: 'General Services' },
{ id: '0a068c85-b3aa-481b-be28-017002c1f78c', name: 'Eating Places, Restaurants' },
{ id: '0bd4b8f3-7778-45ed-89ce-8e31c35a9a77', name: 'Advertising Services' },
{ id: '168267fd-1ccf-4630-aaea-c2039ee9aa35', name: 'Accounting/Bookkeeping Services' },
{ id: '17a67dc0-d856-476b-a8c7-ee7b63f9b9b9', name: 'Grocery Stores, Supermarkets' },
{ id: '4d6c525b-77ed-42dd-83b1-3a0ee44e18d5', name: 'Electronics Stores' },
{ id: '72c76a77-d67c-42bb-942a-fba942257cd6', name: 'Educational Services' },
{ id: '848e04c2-1df3-43d5-894c-f530994c705b', name: 'Computer Software Stores' },
{ id: '8b05ce55-181f-4236-bc8b-93a4fa5645d4', name: 'Consulting, Public Relations' },
{ id: 'c30e5506-94de-41e2-b948-b970264a6aa5', name: 'Computer Programming' },
{ id: 'd020754b-ab04-4863-bea6-f68c9740bdd5', name: 'Computers, Peripherals, and Software' },
{ id: 'f96e139f-197c-44db-9a10-95028b4576e5', name: 'Computer Network Services' },
];
const MOCK_BUSINESS_TYPES = [
{ id: '0d037237-f0ed-4cd6-af80-2b5b98c644a3', name: 'Single Member LLC', director_required: false },
{ id: '1c8002a5-5915-456b-b113-ee88c8e14ab2', name: 'Governmental Unit', director_required: true },
{ id: '27769002-7f8c-4dd3-8680-b811b8d25ad0', name: 'Sole Proprietorship', director_required: false },
{ id: '314ec76f-5943-4fdc-aabe-2e299dc9bf36', name: 'Public Company', director_required: true },
{ id: '5e5122ee-3dd3-49fc-ada0-52a3fdb5656c', name: 'Private Company', director_required: true },
{ id: '94c0863d-3712-48aa-a85c-4d00c2cd7a90', name: 'Multi Member LLC', director_required: true },
{ id: '95d77e58-ef12-4202-a2d1-7827cf7e9a6c', name: 'Public Corporation', director_required: true },
{ id: 'ac2c5fd0-66f7-4d4e-9ee0-b0159a4d1625', name: 'Private Corporation', director_required: true },
{ id: 'd6ff88d8-8744-4d05-a71b-0ac40a1a36bc', name: 'Limited Liability Partnership', director_required: true },
{ id: 'eda68971-fc10-402d-87c8-230e853fcf16', name: 'Private Partnership', director_required: true },
{ id: 'f1f24733-64ea-4f4f-a920-b90f07d182b0', name: 'Public Partnership', director_required: true },
{ id: 'f4e3fe98-c494-489d-b9a8-9c93d0a22070', name: 'Unincorporated Association', director_required: true },
{ id: 'f62de7f2-5652-4a37-aa75-dc907cd5989c', name: 'Incorporated Non Profit', director_required: true },
];
const MOCK_COUNTRIES = [
{ name: 'Albania', iso2: 'AL' },
{ name: 'Angola', iso2: 'AO' },
{ name: 'Argentina', iso2: 'AR' },
{ name: 'Australia', iso2: 'AU' },
{ name: 'Austria', iso2: 'AT' },
{ name: 'Bangladesh', iso2: 'BD' },
{ name: 'Belgium', iso2: 'BE' },
{ name: 'Brazil', iso2: 'BR' },
{ name: 'Bulgaria', iso2: 'BG' },
{ name: 'Cameroon', iso2: 'CM' },
{ name: 'Canada', iso2: 'CA' },
{ name: 'Chile', iso2: 'CL' },
{ name: 'China', iso2: 'CN' },
{ name: 'Colombia', iso2: 'CO' },
{ name: 'Czech Republic', iso2: 'CZ' },
{ name: 'Denmark', iso2: 'DK' },
{ name: 'Egypt', iso2: 'EG' },
{ name: 'France', iso2: 'FR' },
{ name: 'Germany', iso2: 'DE' },
{ name: 'Ghana', iso2: 'GH' },
{ name: 'Hong Kong', iso2: 'HK' },
{ name: 'India', iso2: 'IN' },
{ name: 'Indonesia', iso2: 'ID' },
{ name: 'Ireland', iso2: 'IE' },
{ name: 'Israel', iso2: 'IL' },
{ name: 'Italy', iso2: 'IT' },
{ name: 'Japan', iso2: 'JP' },
{ name: 'Kenya', iso2: 'KE' },
{ name: 'Malaysia', iso2: 'MY' },
{ name: 'Mexico', iso2: 'MX' },
{ name: 'Morocco', iso2: 'MA' },
{ name: 'Netherlands', iso2: 'NL' },
{ name: 'New Zealand', iso2: 'NZ' },
{ name: 'Nigeria', iso2: 'NG' },
{ name: 'Norway', iso2: 'NO' },
{ name: 'Pakistan', iso2: 'PK' },
{ name: 'Philippines', iso2: 'PH' },
{ name: 'Poland', iso2: 'PL' },
{ name: 'Portugal', iso2: 'PT' },
{ name: 'Saudi Arabia', iso2: 'SA' },
{ name: 'Singapore', iso2: 'SG' },
{ name: 'South Africa', iso2: 'ZA' },
{ name: 'South Korea', iso2: 'KR' },
{ name: 'Spain', iso2: 'ES' },
{ name: 'Sweden', iso2: 'SE' },
{ name: 'Switzerland', iso2: 'CH' },
{ name: 'Tanzania', iso2: 'TZ' },
{ name: 'Thailand', iso2: 'TH' },
{ name: 'Turkey', iso2: 'TR' },
{ name: 'Uganda', iso2: 'UG' },
{ name: 'United Arab Emirates', iso2: 'AE' },
{ name: 'United Kingdom', iso2: 'GB' },
{ name: 'United States', iso2: 'US' },
{ name: 'Vietnam', iso2: 'VN' },
];
class ReferenceModule {
constructor(client) {
this.client = client;
}
/**
* Get list of supported countries
*/
async getCountries(page = 1) {
if (this.client.isSandbox) {
const perPage = 20;
const start = (page - 1) * perPage;
const end = start + perPage;
const data = MOCK_COUNTRIES.slice(start, end);
return {
data,
links: {
first: '?page=1',
last: `?page=${Math.ceil(MOCK_COUNTRIES.length / perPage)}`,
prev: page > 1 ? `?page=${page - 1}` : null,
next: end < MOCK_COUNTRIES.length ? `?page=${page + 1}` : null,
},
meta: {
current_page: page,
from: start + 1,
last_page: Math.ceil(MOCK_COUNTRIES.length / perPage),
path: '/countries',
per_page: perPage,
to: Math.min(end, MOCK_COUNTRIES.length),
total: MOCK_COUNTRIES.length,
links: [],
},
};
}
return this.client.get('/countries', { page });
}
/**
* Get all countries (unpaginated convenience method)
*/
async getAllCountries() {
if (this.client.isSandbox) {
return MOCK_COUNTRIES;
}
const result = await this.client.get('/countries', { page: 'all' });
return result.data;
}
/**
* Get currency details and rates for a country
*/
async getCurrencies(countryIso2) {
if (this.client.isSandbox) {
// Return mock currency data
const currencyMap = {
US: {
id: 'a58cd1d1-ad88-4318-ab6c-200e365bc393',
name: 'US Dollar',
currency: 'USD',
symbol: '$',
settings: {
topup: 'active',
payout: 'active',
delivery_window_required: false,
},
},
GB: {
id: '3e0b7e13-9ad6-40da-9a84-80fe6346f856',
name: 'British Pound',
currency: 'GBP',
symbol: '£',
settings: {
topup: 'active',
payout: 'active',
delivery_window_required: true,
},
},
NG: {
id: 'ng-currency-id',
name: 'Nigerian Naira',
currency: 'NGN',
symbol: '₦',
settings: {
topup: 'active',
payout: 'active',
delivery_window_required: false,
},
},
};
return [currencyMap[countryIso2] || currencyMap.US];
}
return this.client.get(`/currencies/${countryIso2}`);
}
/**
* Get list of source of funds options
*/
async getSourceOfFunds() {
if (this.client.isSandbox) {
return MOCK_SOURCE_OF_FUNDS;
}
const result = await this.client.get('/source_of_funds');
return result.data;
}
/**
* Get list of MCC codes
*/
async getMccCodes() {
if (this.client.isSandbox) {
return MOCK_MCC;
}
const result = await this.client.get('/mcc');
return result.data;
}
/**
* Get list of business registration types
*/
async getBusinessRegistrationTypes() {
if (this.client.isSandbox) {
return MOCK_BUSINESS_TYPES;
}
const result = await this.client.get('/business_registration_type');
return result.data;
}
/**
* Find source of funds by name (case-insensitive partial match)
*/
async findSourceOfFunds(searchTerm) {
const sources = await this.getSourceOfFunds();
const lowerSearch = searchTerm.toLowerCase();
return sources.find(s => s.name.toLowerCase().includes(lowerSearch));
}
/**
* Find MCC by name (case-insensitive partial match)
*/
async findMcc(searchTerm) {
const mccs = await this.getMccCodes();
const lowerSearch = searchTerm.toLowerCase();
return mccs.find(m => m.name.toLowerCase().includes(lowerSearch));
}
/**
* Find business registration type by name
*/
async findBusinessType(searchTerm) {
const types = await this.getBusinessRegistrationTypes();
const lowerSearch = searchTerm.toLowerCase();
return types.find(t => t.name.toLowerCase().includes(lowerSearch));
}
}
exports.ReferenceModule = ReferenceModule;