@nkhind/vivawallet-sdk
Version:
Non-Official VivaWallet API SDK
66 lines (65 loc) • 2.4 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Marketplace = void 0;
const functions_1 = require("../utils/functions");
const Vivawallet_class_1 = __importDefault(require("./Vivawallet.class"));
class Marketplace extends Vivawallet_class_1.default {
constructor(datas) {
super(datas);
}
/** Create new Seller Account */
async createAccount(datas) {
if (!this.vivaTotken)
throw new Error('Init not called');
try {
if (this.logs) {
console.log('createAccount', this.endpoints.marketplace.accounts, 'Bearer ' + this.vivaTotken);
}
const r = await (0, functions_1.requests)(this.endpoints.marketplace.accounts.create.url, this.endpoints.marketplace.accounts.create.method, {
Authorization: 'Bearer ' + this.vivaTotken,
}, datas);
if (r.data)
return r.data;
}
catch (e) {
console.log(e);
}
return null;
}
/** Make new VivaWallet Marketplace order, return `orderCode` */
async createMarketplaceOrder(orderData) {
if (!this.vivaTotken)
throw new Error('Init not called');
try {
const r = await (0, functions_1.requests)(this.endpoints.payment.create.url, this.endpoints.payment.create.method, {
Authorization: 'Bearer ' + this.vivaTotken,
}, orderData);
if (r.data && r.data.orderCode)
return r.data.orderCode;
}
catch (e) {
console.log(e);
}
return null;
}
/** Send funds from marketplace to seller account/brank */
async sendFunds(datas) {
if (!this.vivaTotken)
throw new Error('Init not called');
try {
const r = await (0, functions_1.requests)(this.endpoints.marketplace.transfers.send.url, this.endpoints.marketplace.transfers.send.method, {
Authorization: 'Bearer ' + this.vivaTotken,
}, datas);
if (r.data)
return r.data;
}
catch (e) {
console.log(e);
}
return null;
}
}
exports.Marketplace = Marketplace;