kotanipay-sdk
Version:
Official Kotani Pay SDK for Node.js and Browser
61 lines • 2.28 kB
JavaScript
import { ValidationUtil } from '../../utils/validation.util';
export class MobileMoneyService {
constructor(httpClient) {
this.httpClient = httpClient;
}
validateCreateCustomerRequest(request) {
const requiredFields = [
'phone_number', 'country_code'
];
ValidationUtil.validateRequiredFields(request, requiredFields);
ValidationUtil.validatePhone(request.phone_number);
this.validateCountryCode(request.country_code);
if (request.network) {
this.validateNetwork(request.network);
}
}
validateCountryCode(countryCode) {
const validCountryCodes = [
'GHA', 'KEN', 'ZAC', 'CIV', 'ZMB', 'CMR', 'COD',
'SEN', 'TZM', 'MWI', 'UGA', 'ETH', 'GRW'
];
if (!validCountryCodes.includes(countryCode)) {
throw new Error(`Invalid country code. Must be one of: ${validCountryCodes.join(', ')}`);
}
}
validateNetwork(network) {
const validNetworks = [
'MPESA', 'MTN', 'AIRTEL', 'VODAFONE', 'TIGO', 'ORANGE',
'NOT_SUPPORTED', 'ZAMTEL', 'CHECKOUT', 'BKTRX', 'CRDTRX',
'MOOV', 'TMONEY', 'FREE', 'EXPRESSO', 'HALOPESA', 'VODACOM'
];
if (!validNetworks.includes(network)) {
throw new Error(`Invalid network. Must be one of: ${validNetworks.join(', ')}`);
}
}
async createCustomer(request) {
this.validateCreateCustomerRequest(request);
const response = await this.httpClient.post('/api/v3/customer/mobile-money', request);
return response.data;
}
/**
* Get all mobile money customers
* Requires API key authentication
*/
async getAllCustomers() {
const response = await this.httpClient.get('/api/v3/customer/mobile-money');
return response.data;
}
/**
* Get mobile money customer by ID
* Requires API key authentication
*/
async getCustomerById(customerId) {
if (!customerId) {
throw new Error('Customer ID is required');
}
const response = await this.httpClient.get(`/api/v3/customer/mobile-money/${customerId}`);
return response.data;
}
}
//# sourceMappingURL=mobile-money.service.js.map