lootpay
Version:
To install dependencies:
244 lines (243 loc) • 8.25 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
// Utils
import { makev1LootpayRequest } from "../utils/request";
export default class LootPayClient {
constructor(apiKey) {
this.apiKey = apiKey;
}
/**
* Send a crypto payment
* @param amount - The amount to send in USD
* @param address - The address to send the payment to
* @param network - The crypto network to send the payment to
*/
sendCryptoPayment(_a) {
return __awaiter(this, arguments, void 0, function* ({ amount, address, network, }) {
try {
const { err, data } = yield makev1LootpayRequest({
url: `crypto/${network}/send`,
method: "POST",
body: {
recipientAddress: address,
amount,
},
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Get the prices of all supported cryptocurrencies
*/
getCryptoPrices() {
return __awaiter(this, void 0, void 0, function* () {
try {
const { err, data } = yield makev1LootpayRequest({
url: `crypto/prices/get`,
method: "GET",
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Get your applications balance
*/
getBalance() {
return __awaiter(this, void 0, void 0, function* () {
try {
const { err, data } = yield makev1LootpayRequest({
url: `balance/get`,
method: "GET",
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Get the balance history
* @param limit - The number of transactions to return
* @param offset - The number of transactions to skip
*/
getBalanceHistory(_a) {
return __awaiter(this, arguments, void 0, function* ({ limit, offset, }) {
const query = new URLSearchParams();
if (limit)
query.append('limit', limit.toString());
if (offset)
query.append('offset', offset.toString());
const queryString = query.toString();
try {
const { err, data } = yield makev1LootpayRequest({
url: `balance/history${queryString ? `?${queryString}` : ''}`,
method: "GET",
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Get all transactions
* @param limit - The number of transactions to return
* @param offset - The number of transactions to skip
* @param type - The type of transactions to return
*/
getTransactionHistory(_a) {
return __awaiter(this, arguments, void 0, function* ({ limit, offset, type, }) {
const query = new URLSearchParams();
if (limit)
query.append('limit', limit.toString());
if (offset)
query.append('offset', offset.toString());
if (type)
query.append('type', type);
const queryString = query.toString();
try {
const { err, data } = yield makev1LootpayRequest({
url: `transactions/list${queryString ? `?${queryString}` : ''}`,
method: "GET",
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Get a transaction by ID
* @param transactionID - The ID of the transaction to get
*/
getTransaction(transactionID) {
return __awaiter(this, void 0, void 0, function* () {
try {
const { err, data } = yield makev1LootpayRequest({
url: `transactions/get?transactionID=${transactionID}`,
method: 'GET',
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Get all available redemption methods
*/
getMethods() {
return __awaiter(this, void 0, void 0, function* () {
try {
const { err, data } = yield makev1LootpayRequest({
url: `methods/list`,
method: "GET",
apiKey: this.apiKey,
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
/**
* Send a loot link
* @param amount - The amount to send in USD
* @param email - The email to send the loot link to
* @param username - The username of the user you're sending the loot link to
*/
sendLootLink(_a) {
return __awaiter(this, arguments, void 0, function* ({ amount, email, username, }) {
try {
const { err, data } = yield makev1LootpayRequest({
url: `looklink/send`,
method: "POST",
apiKey: this.apiKey,
body: {
amount,
email,
username,
},
});
if (err)
return { err };
return {
err: undefined,
data: data,
};
}
catch (error) {
console.error(error);
return { err: 'Request failed' };
}
});
}
}