Sebelumnya saya menggunakan Node.js 12 dan saya bisa menggunakan xendit-node dengan lancar.
Tapi sekarang saya harus menggunakan Node.js 10 dan xendit-node tidak bisa lagi di gunakan dengan pesan error :
2021-03-24T16:54:23.277Z ? invoice-create: Provided module can't be loaded.
2021-03-24T16:54:23.278Z ? invoice-create: Did you list all required modules in the package.json dependencies?
2021-03-24T16:54:23.278Z ? invoice-create: Detailed stack trace: Error: Cannot find module 'xendit-node'
{
"dependencies": {
"xendit-node": "^1.10.0"
}
}
const Xendit = require("xendit-node");
const xendit = new Xendit({
secretKey: "xnd_production_T91prSZWogti1oXvhGhHicH",
// secretKey: 'xnd_development_EJSQs9rwP7k66WDo1Pe',
});
module.exports = xendit;
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const xendit = require("../config/xendit");
const {
Invoice,
} = xendit;
const invoice = new Invoice({});
exports.create = functions.https.onCall((data, context) => {
const timestamp = Date.now();
const auth = context.auth.token;
// missing check
if (data.type == undefined) return {code: "missing-type"};
if (data.order == undefined) return {code: "missing-order"};
// functions.logger.log("missing check", "success");
// typeof check
if (typeof data.type != "string") return {code: "typeof-type"};
if (typeof data.order != "string") return {code: "typeof-order"};
// functions.logger.log("typeof check", "success");
if (data.type == "order") {
return admin.firestore().collection("order").doc(data.order).get().then((doc) => {
if (!doc.exists) {
return {code: "order-not-found"};
}
const order = doc.data();
if (order["buyer"]["uid"] != auth.uid) {
return {code: "user-not-buyer"};
}
return admin.firestore().collection("users").doc(order["buyer"]["uid"]).get().then((doc) => {
if (!doc.exists) {
return {code: "buyer-not-found"};
}
const buyer = doc.data();
return invoice.createInvoice({
externalID: data.order,
amount: order["deal"]["price"],
payerEmail: buyer["email"],
description: "ORDER : #" + order["id"] + " : " + order["product"]["name"],
shouldSendEmail: true,
}).then((invoice) => {
invoice["order"] = data.order;
invoice["user"] = auth.uid;
invoice["seller"] = order["seller"]["uid"];
invoice["registered"] = timestamp;
return admin.firestore().collection("invoices").add(invoice)
.then((doc) => {
return admin.firestore().collection("order").doc(data.order).update({
"invoice": doc.id,
"status": "deal",
"updated": timestamp,
}).then(() => {
functions.logger.info("INVOICE CREATED", invoice["amount"]);
return {code: "success", invoice: doc.id};
}).catch((error) => {
return {code: "error", error: error};
});
}).catch((error) => {
return {code: "error", error: error};
});
}).catch((error) => {
functions.logger.error(error);
return {code: "error", error: error};
});
}).catch((error) => {
functions.logger.error(error);
return {code: "error", error: error};
});
}).catch((error) => {
functions.logger.error(error);
return {code: "error", error: error};
});
}
});