paypal-integrations-intacct
Version:
Integration between paypal and intacct using hapi.
107 lines • 3.91 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const hapi_intacct_1 = require("hapi-intacct");
const joi = require("joi");
class HapiIntacctInvoicing {
setServer(server) {
this.server = server;
}
query(query, fields) {
return __awaiter(this, void 0, void 0, function* () {
let url = `/intacct/invoice?query=${encodeURIComponent(query)}`;
if (fields) {
url += `&fields=${fields.join(",")}`;
}
const res = yield this.server.inject({
allowInternals: true,
method: "GET",
url,
});
if (res.statusCode !== 200) {
throw new Error(res.result.message);
}
return res.result;
});
}
get(id) {
return __awaiter(this, void 0, void 0, function* () {
const get = yield this.server.inject({
allowInternals: true,
method: "GET",
url: `/intacct/invoice/${id}`,
});
if (get.statusCode !== 200) {
throw new Error(get.result.message);
}
return get.result;
});
}
update(id, payload) {
return __awaiter(this, void 0, void 0, function* () {
const update = yield this.server.inject({
allowInternals: true,
method: "PUT",
payload,
url: `/intacct/invoice/${id}`,
});
if (update.statusCode !== 200) {
throw new Error(update.result.message);
}
return update.result;
});
}
createPayment(payload) {
return __awaiter(this, void 0, void 0, function* () {
const validate = joi.validate(payload, hapi_intacct_1.intacctPaymentSchema);
if (validate.error) {
throw new Error(validate.error.message);
}
const create = yield this.server.inject({
allowInternals: true,
method: "POST",
payload,
url: `/intacct/payment`,
});
if (create.statusCode !== 200) {
throw new Error(create.result.message);
}
return create.result;
});
}
listAccounts() {
return __awaiter(this, void 0, void 0, function* () {
const list = yield this.server.inject({
allowInternals: true,
method: "GET",
url: `/intacct/checkingaccount`,
});
if (list.statusCode !== 200) {
throw new Error(list.result.message);
}
return list.result;
});
}
inspect() {
return __awaiter(this, void 0, void 0, function* () {
const inspect = yield this.server.inject({
allowInternals: true,
method: "OPTIONS",
url: `/intacct/invoice`,
});
if (inspect.statusCode !== 200) {
throw new Error(inspect.result.message);
}
return inspect.result;
});
}
}
exports.HapiIntacctInvoicing = HapiIntacctInvoicing;
//# sourceMappingURL=intacct.js.map