Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fitur payment siap, fitur CRUD lender siap, router loan complete #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ app.use(express.json())

app.use(routes)

app.listen(3000, () => {
console.log("now running")
})

module.exports = app
Empty file.
127 changes: 127 additions & 0 deletions server/controllers/LoanController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// const {} = require("")
const { XenditInvoice, XenditDisbursement } = require('../helpers/Xendit');

class LoanController {
static async CreateInvoice(req, res, next) {
const { email } = req.body;
const loanID = '123456';
try {
const invoice = await XenditInvoice.createInvoice({
externalID: 'EXTERNAL_ID_KITA',
payerEmail: 'pinjamkuproject@gmail.com',
description: `Invoice for loan ${loanID}`,
amount: 100000,
shouldSendEmail: true
});
res.status(200).json({
externalID: invoice.external_id,
invoiceURL: invoice.invoice_url
});
} catch (error) {
console.log(error);
}
}

// static async CreateLoan(req, res, next) {
// const {} = req.body;
// try {
// } catch (error) {
// next(error);
// }
// }

static async CreateWithdrawal(req, res, next) {
const {} = req.body;

try {
const loan = {
id: '123',
initialLoan: 100000,
lender: {
bankCode: 'BCA',
accountHolderName: 'Test',
accountNumber: '1234567890'
}
};

const withdrawalInterest = loan.initialLoan + loan.initialLoan * 0.05;

const disbursement = await XenditDisbursement.create({
externalID: `disburse-${loan.id}`,
bankCode: loan.lender.bankCode,
accountHolderName: loan.lender.accountHolderName,
accountNumber: loan.lender.accountNumber,
description: `withdrawal for ${loan.id}`,
amount: withdrawalInterest
});
res.status(200).json(disbursement);
} catch (error) {
console.log(error);
}
}

static async CreateDisbursement(req, res, next) {
const {} = req.body;
try {
const loan = {
id: '123',
initialLoan: 100000,
borrower: {
bankCode: 'BCA',
accountHolderName: 'Test',
accountNumber: '1234567890'
}
};

const withdrawalInterest = loan.initialLoan + loan.initialLoan * 0.05;

const disbursement = await XenditDisbursement.create({
externalID: `disburse-${loan.id}`,
bankCode: loan.lender.bankCode,
accountHolderName: loan.lender.accountHolderName,
accountNumber: loan.lender.accountNumber,
description: `withdrawal for ${loan.id}`,
amount: withdrawalInterest
});
res.status(200).json(disbursement);
} catch (error) {
console.log(error);
}
}

static async InvoiceEndpoint(req, res, next) {
const { external_id, status } = req.body;
try {
if (status === 'FAILED') {
res.status(200).json({ status: 'failed' });
} else if (status === 'PAID') {
res.status(200).json({ status: 'paid' });
}
} catch (error) {
console.log(error);
}
}

static async DisbursementEndpoint(req, res, next) {
const { external_id, status } = req.body;
try {
if (status === 'FAILED') {
res.status(200).json({ status: 'failed' });
} else if (status === 'COMPLETED') {
res.status(200).json({ status: 'paid' });
}
} catch (error) {
console.log(error);
}
}

static Test(req, res, next) {
try {
res.status(200).json({ msg: 'ok' });
} catch (error) {
res.status(500);
}
}
}

module.exports = LoanController;
12 changes: 12 additions & 0 deletions server/helpers/Xendit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Xendit = require('xendit-node');
const x = new Xendit({
secretKey: 'xnd_development_S1YRENVA6FA1ELZerCvKR3NaBY1J7Jm2JLLhawkAzF7R5gTg4SvcAZfaXPIKA0n',
});
const { Invoice, Disbursement } = x;
const invoiceSpecificOptions = {};
const disbursementSpecificOptions = {};
const XenditInvoice = new Invoice(invoiceSpecificOptions);
const XenditDisbursement = new Disbursement(disbursementSpecificOptions);


module.exports = {XenditInvoice, XenditDisbursement}
Loading