@zebec-fintech/silver-card-sdk
Version:
An sdk for purchasing silver card in zebec
241 lines (240 loc) • 9.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.allCountriesWithCode = exports.Recipient = exports.Money = exports.Receipt = exports.Deposit = exports.Quote = exports.OrderCardRequest = void 0;
const errors_1 = require("./errors");
const utils_1 = require("./utils");
class OrderCardRequest {
amount;
recipient;
receipt;
constructor(amount, recipient, receipt) {
this.amount = amount;
this.receipt = receipt;
this.recipient = recipient;
}
}
exports.OrderCardRequest = OrderCardRequest;
class Quote {
id; // Unique identifier for the quote
token; // Token symbol or name (e.g., BTC, ETH)
targetCurrency; // Target currency (e.g., "USD")
amountRequested; // Amount of USD the user wants to purchase
pricePerUnitCurrency; // Price of 1 USD in terms of the token
totalPrice; // Total token amount needed for the USD purchase
platformFee; // Any additional platform fee
expiresIn; // Validity period for the quote in seconds or ISO date
timestamp; // Timestamp when the quote was generated
status; // Quote status
constructor(id, token, targetCurrency, amountRequested, pricePerUnitCurrency, totalPrice, platformFee, expiresIn, timestamp, status) {
this.id = id;
this.token = token;
this.targetCurrency = targetCurrency;
this.amountRequested = amountRequested;
this.pricePerUnitCurrency = pricePerUnitCurrency;
this.totalPrice = totalPrice;
this.platformFee = platformFee;
this.expiresIn = expiresIn;
this.timestamp = timestamp;
this.status = status;
}
}
exports.Quote = Quote;
class Deposit {
tokenName;
tokenAmount;
signature;
buyerAddress;
txHash;
blockHash;
chainId;
purchaseCounter;
constructor(tokenName, tokenAmount, signature, buyerAddress, txHash, blockHash, chainId, purchaseCounter) {
this.tokenName = tokenName;
this.tokenAmount = tokenAmount;
this.signature = signature;
this.txHash = txHash;
this.blockHash = blockHash;
this.chainId = chainId;
this.buyerAddress = buyerAddress;
this.purchaseCounter = purchaseCounter;
}
}
exports.Deposit = Deposit;
class Receipt {
quote;
deposit;
constructor(quote, deposit) {
this.quote = quote;
this.deposit = deposit;
}
}
exports.Receipt = Receipt;
class Money {
amount;
currencyCode;
constructor(amount, currencyCode) {
this.amount = amount;
this.currencyCode = currencyCode;
}
// Example static method to create a Money instance from an amount and optional currency code
static create(amount, currencyCode) {
return new Money(Number(amount), currencyCode);
}
static USD(amount) {
return this.create((0, utils_1.formatAmount)(amount), "USD");
}
}
exports.Money = Money;
class Recipient {
participantId;
firstName;
lastName;
emailAddress;
address1;
address2;
city;
state;
postalCode;
countryCode;
language = "en-US";
mobilePhone;
constructor(participantId, firstName, lastName, emailAddress, mobilePhone, language, city, state, postalCode, countryCode, address1, address2) {
this.participantId = participantId;
this.firstName = firstName;
this.lastName = lastName;
this.address1 = address1;
this.address2 = address2;
this.city = city;
this.state = state;
this.postalCode = postalCode;
this.countryCode = countryCode;
this.emailAddress = emailAddress;
this.language = language;
this.mobilePhone = mobilePhone;
}
static create(participantId, firstName, lastName, emailAddress, mobilePhone, language, city, state, postalCode, countryCode, address1, address2) {
if (!(0, utils_1.hasLen)(participantId, 1, 20)) {
throw new errors_1.ValidationError("Participants must be of 1 to 20 characters.");
}
if (!(0, utils_1.isAlphaNumeric)(participantId)) {
throw new errors_1.ValidationError("Participants must only contains alpha numeric characters");
}
if (!(0, utils_1.hasLen)(firstName, 1, 50)) {
throw new errors_1.ValidationError("Firstname must be within 1 to 50 characters.");
}
if (!(0, utils_1.hasLen)(lastName, 1, 50)) {
throw new errors_1.ValidationError("Lastname must be within 1 to 50 characters.");
}
if (!(0, utils_1.hasLen)(emailAddress, 1, 80)) {
throw new errors_1.ValidationError("Email must be within 1 to 80 characters.");
}
if (!(0, utils_1.isEmailValid)(emailAddress)) {
throw new errors_1.ValidationError("Email address must be a valid email.");
}
if (!(0, utils_1.hasLen)(language, 2, 5)) {
throw new errors_1.ValidationError("Language code must be within 2 to 5 characters.");
}
if (!(0, utils_1.hasLen)(mobilePhone, 1, 20)) {
throw new errors_1.ValidationError("Mobile phone number must be within 1 to 20 characters.");
}
if (!(0, utils_1.hasLen)(city, 1, 50)) {
throw new errors_1.ValidationError("City must be within 1 to 50 characters.");
}
if (!(0, utils_1.hasLen)(state, 1, 50)) {
throw new errors_1.ValidationError("State must be within 1 to 50 characters.");
}
if (!exports.allCountriesWithCode.find((country) => country.code === countryCode)) {
throw new errors_1.ValidationError("CountryCode must be a valid supported ISO 3166-1 alpha-3 code");
}
if (!(0, utils_1.hasLen)(postalCode, 1, 20)) {
throw new errors_1.ValidationError("Postal code must be within 1 to 20 characters.");
}
if (!(0, utils_1.hasLen)(address1, 1, 50)) {
throw new errors_1.ValidationError("Address line 1 must be within 1 to 50 characters.");
}
if (address2 && !(0, utils_1.hasLen)(address2, 1, 50)) {
throw new errors_1.ValidationError("Address line 2 must be within 1 to 50 characters.");
}
return new Recipient(participantId, firstName, lastName, emailAddress, mobilePhone, language, city, state, postalCode, countryCode, address1, address2 ?? "N/A");
}
}
exports.Recipient = Recipient;
exports.allCountriesWithCode = [
{ name: "Algeria", code: "DZA" },
{ name: "Angola", code: "AGO" },
{ name: "Argentina", code: "ARG" },
{ name: "Australia", code: "AUS" },
{ name: "Austria", code: "AUT" },
{ name: "Belgium", code: "BEL" },
{ name: "Bolivia (Plurinational State of)", code: "BOL" },
{ name: "Brazil", code: "BRA" },
{ name: "Cameroon", code: "CMR" },
{ name: "Canada", code: "CAN" },
{ name: "Chile", code: "CHL" },
{ name: "Costa Rica", code: "CRI" },
{ name: "Cyprus", code: "CYP" },
{ name: "Czechia", code: "CZE" },
{ name: "Denmark", code: "DNK" },
{ name: "Ecuador", code: "ECU" },
{ name: "Egypt", code: "EGY" },
{ name: "El Salvador", code: "SLV" },
{ name: "Estonia", code: "EST" },
{ name: "Finland", code: "FIN" },
{ name: "France", code: "FRA" },
{ name: "Georgia", code: "GEO" },
{ name: "Germany", code: "DEU" },
{ name: "Ghana", code: "GHA" },
{ name: "Greece", code: "GRC" },
{ name: "Guatemala", code: "GTM" },
{ name: "Honduras", code: "HND" },
{ name: "Hungary", code: "HUN" },
{ name: "Iceland", code: "ISL" },
{ name: "Ireland", code: "IRL" },
{ name: "Italy", code: "ITA" },
{ name: "Jamaica", code: "JAM" },
{ name: "Japan", code: "JPN" },
{ name: "Jordan", code: "JOR" },
{ name: "Kenya", code: "KEN" },
{ name: "Korea, Republic of Korea", code: "KOR" },
{ name: "Kuwait", code: "KWT" },
{ name: "Lithuania", code: "LTU" },
{ name: "Luxembourg", code: "LUX" },
{ name: "Malawi", code: "MWI" },
{ name: "Malaysia", code: "MYS" },
{ name: "Malta", code: "MLT" },
{ name: "Mexico", code: "MEX" },
{ name: "Morocco", code: "MAR" },
{ name: "Mozambique", code: "MOZ" },
{ name: "Nepal", code: "NPL" },
{ name: "Netherlands", code: "NLD" },
{ name: "New Zealand", code: "NZL" },
{ name: "Nigeria", code: "NGA" },
{ name: "Norway", code: "NOR" },
{ name: "Oman", code: "OMN" },
{ name: "Pakistan", code: "PAK" },
{ name: "Papua New Guinea", code: "PNG" },
{ name: "Paraguay", code: "PRY" },
{ name: "Peru", code: "PER" },
{ name: "Philippines", code: "PHL" },
{ name: "Poland", code: "POL" },
{ name: "Portugal", code: "PRT" },
{ name: "Puerto Rico", code: "PRI" },
{ name: "Qatar", code: "QAT" },
{ name: "Romania", code: "ROU" },
{ name: "Saudi Arabia", code: "SAU" },
{ name: "Singapore", code: "SGP" },
{ name: "Slovakia", code: "SVK" },
{ name: "Slovenia", code: "SVN" },
{ name: "Spain", code: "ESP" },
{ name: "Sweden", code: "SWE" },
{ name: "Taiwan", code: "TWN" },
{ name: "Thailand", code: "THA" },
{ name: "Trinidad and Tobago", code: "TTO" },
{ name: "Tunisia", code: "TUN" },
{ name: "Turkey", code: "TUR" },
{ name: "United Kingdom", code: "GBR" },
{ name: "United States", code: "USA" },
{ name: "Uruguay", code: "URY" },
{ name: "Vanuatu", code: "VUT" },
{ name: "Zambia", code: "ZMB" },
];