Alur Payment
# feat - Pembelian saham - Function progres ### No Issue
This commit is contained in:
@@ -11,7 +11,7 @@ import { MODEL_Investasi } from "../model/model_investasi";
|
||||
export async function funCreateInvestasi(
|
||||
gamabar: FormData,
|
||||
filePdf: FormData,
|
||||
data: MODEL_Investasi | any
|
||||
data: MODEL_Investasi
|
||||
) {
|
||||
// Function upload gambar
|
||||
const file: any = gamabar.get("file");
|
||||
@@ -32,7 +32,7 @@ export async function funCreateInvestasi(
|
||||
if (!uploadImage)
|
||||
return {
|
||||
status: 400,
|
||||
message: "File Kosong",
|
||||
message: "Gambar Kosong",
|
||||
};
|
||||
|
||||
const upFolder = Buffer.from(await file.arrayBuffer());
|
||||
@@ -67,23 +67,21 @@ export async function funCreateInvestasi(
|
||||
const pdfExt = _.lowerCase(dataPdf.name.split(".").pop());
|
||||
const pdfRandomName = v4(pdfName) + "." + pdfExt;
|
||||
|
||||
const uploadFile = await prisma.prospektusInvestasi.upsert({
|
||||
where: {
|
||||
investasiId: createInvest.id,
|
||||
},
|
||||
update: {
|
||||
url: pdfRandomName,
|
||||
},
|
||||
create: {
|
||||
const uploadFile = await prisma.prospektusInvestasi.create({
|
||||
data: {
|
||||
investasiId: createInvest.id,
|
||||
url: pdfRandomName,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
url: true,
|
||||
},
|
||||
});
|
||||
|
||||
if(!uploadFile) return {status: 400, message: "Gagal Upload"}
|
||||
const upPdfFolder = Buffer.from(await file.arrayBuffer())
|
||||
fs.writeFileSync(`./public/file/${uploadFile.url}`, upPdfFolder)
|
||||
|
||||
if (!uploadFile) return { status: 400, message: "File Kosong" };
|
||||
const upPdfFolder = Buffer.from(await file.arrayBuffer());
|
||||
fs.writeFileSync(`./public/file/${uploadFile.url}`, upPdfFolder);
|
||||
|
||||
revalidatePath(RouterInvestasi.main_porto);
|
||||
|
||||
|
||||
@@ -12,10 +12,12 @@ export default async function funCreateTransaksiInvestasi(
|
||||
data: {
|
||||
namaBank: data.namaBank,
|
||||
nomorRekening: data.nomorRekening,
|
||||
lembarTerbeli: "" + data.lembarTerbeli,
|
||||
totalTransfer: "" + data.totalTransfer,
|
||||
investasiId: invesId,
|
||||
authorId: authorId,
|
||||
gross_amount: "",
|
||||
merchant_name:"",
|
||||
price: "",
|
||||
quantity: ""
|
||||
},
|
||||
});
|
||||
if (!res) return { status: 400, message: "Gagal disimpan" };
|
||||
|
||||
@@ -3,24 +3,31 @@
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAdminInvestasi } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import moment from "moment";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function funGantiStatusInvestasi(id: string, val: string) {
|
||||
const publishCD = new Date
|
||||
const data = await prisma.investasi.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
masterStatusInvestasiId: val,
|
||||
MasterStatusInvestasi: {
|
||||
connect: {
|
||||
id: val,
|
||||
},
|
||||
},
|
||||
countDown: publishCD,
|
||||
},
|
||||
});
|
||||
|
||||
if(!data) return {status: 400}
|
||||
if (!data) return { status: 400 };
|
||||
|
||||
revalidatePath(RouterInvestasi.portofolio)
|
||||
revalidatePath(RouterAdminInvestasi.main_investasi)
|
||||
revalidatePath(RouterInvestasi.portofolio);
|
||||
revalidatePath(RouterAdminInvestasi.main_investasi);
|
||||
|
||||
return {
|
||||
status: 200
|
||||
}
|
||||
status: 200,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ export default async function funGantiStatusTransaksi_Investasi(
|
||||
select: {
|
||||
id: true,
|
||||
namaBank: true,
|
||||
totalTransfer: true,
|
||||
Investasi: true,
|
||||
MasterStatusTransaksiInvestasi: true
|
||||
}
|
||||
|
||||
16
src/app_modules/investasi/fun/fun_total_investor_by_id.ts
Normal file
16
src/app_modules/investasi/fun/fun_total_investor_by_id.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function funTotalInvestorByIdInvestasi(id: string) {
|
||||
// console.log(id)
|
||||
const data = await prisma.transaksiInvestasi.count({
|
||||
where: {
|
||||
investasiId: id,
|
||||
status_code: "200"
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
// belum ke hitungg
|
||||
23
src/app_modules/investasi/fun/fun_update_investasi.ts
Normal file
23
src/app_modules/investasi/fun/fun_update_investasi.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { MODEL_Investasi } from "../model/model_investasi";
|
||||
|
||||
export default async function funUpdateInvestasi(data: MODEL_Investasi) {
|
||||
// console.log(data)
|
||||
const res = await prisma.investasi.update({
|
||||
where: {
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
sisaLembar: "" + data.sisaLembar,
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal update" };
|
||||
return {
|
||||
status: 200,
|
||||
message: "Update berhasil",
|
||||
};
|
||||
}
|
||||
96
src/app_modules/investasi/fun/fun_update_payment.ts
Normal file
96
src/app_modules/investasi/fun/fun_update_payment.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { MODEL_Investasi } from "../model/model_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RouterInvestasi } from "@/app/lib/router_hipmi/router_investasi";
|
||||
|
||||
export interface Model_Midtrans_Success {
|
||||
status_code: string;
|
||||
status_message: string;
|
||||
transaction_id: string;
|
||||
order_id: string;
|
||||
gross_amount: string;
|
||||
payment_type: string;
|
||||
transaction_time: string;
|
||||
transaction_status: string;
|
||||
fraud_status: string;
|
||||
va_numbers: [{ bank: string; va_number: string }];
|
||||
pdf_url: string;
|
||||
finish_redirect_url: string;
|
||||
}
|
||||
|
||||
export default async function funUpdatePaymentInvestasi(
|
||||
data: Model_Midtrans_Success,
|
||||
idPay: any,
|
||||
) {
|
||||
console.log(data)
|
||||
if (data.status_code === "200") {
|
||||
const res = await prisma.transaksiInvestasi.update({
|
||||
where: {
|
||||
id: idPay,
|
||||
},
|
||||
data: {
|
||||
status_code: data.status_code,
|
||||
status_message: data.status_message,
|
||||
order_id: data.order_id,
|
||||
fraud_status: data.fraud_status,
|
||||
payment_type: data.payment_type,
|
||||
transaction_id: data.transaction_id,
|
||||
transaction_status: data.transaction_status,
|
||||
transaction_time: data.transaction_time,
|
||||
pdf_url: data.pdf_url,
|
||||
finish_redirect_url: data.finish_redirect_url,
|
||||
namaBank: data.va_numbers[0].bank,
|
||||
nomorRekening: data.va_numbers[0].va_number,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return { status: 400, message: "Gagal update transaksi" };
|
||||
|
||||
// const jumlah = Number(res.quantity);
|
||||
// const sisa = Number(investasi?.sisaLembar);
|
||||
// const hasil = sisa - jumlah;
|
||||
|
||||
// const updateTransaksi = await prisma.investasi.update({
|
||||
// where: {
|
||||
// id: investasi?.id,
|
||||
// },
|
||||
// data: {
|
||||
// sisaLembar: hasil.toString(),
|
||||
// },
|
||||
// });
|
||||
|
||||
// console.log(updateTransaksi);
|
||||
// if (!updateTransaksi)
|
||||
// return { status: 400, message: "Gagal update investasi" };
|
||||
|
||||
revalidatePath(RouterInvestasi.main_transaksi)
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Process",
|
||||
};
|
||||
} else {
|
||||
if (data.status_code === "201") {
|
||||
const res = await prisma.transaksiInvestasi.update({
|
||||
where: {
|
||||
id: idPay,
|
||||
},
|
||||
data: {
|
||||
status_code: "201",
|
||||
},
|
||||
});
|
||||
return {
|
||||
message: "Success",
|
||||
};
|
||||
} else {
|
||||
if ((!data.status_code as any) === "400")
|
||||
return { status: 400, message: "Update Gagal" };
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil Update",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ export async function getListAllPublish() {
|
||||
},
|
||||
},
|
||||
AND: {
|
||||
active: true
|
||||
}
|
||||
active: true,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -38,7 +38,7 @@ export async function getListAllPublish() {
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
|
||||
countDown: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -19,17 +19,22 @@ export default async function getListAllTransaksiById_Investasi(
|
||||
id: true,
|
||||
namaBank: true,
|
||||
nomorRekening: true,
|
||||
totalTransfer: true,
|
||||
lembarTerbeli: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
authorId: true,
|
||||
quantity: true,
|
||||
price: true,
|
||||
gross_amount: true,
|
||||
merchant_name: true,
|
||||
redirect_url: true,
|
||||
token: true,
|
||||
|
||||
Author: true,
|
||||
masterStatusTransaksiInvestasiId: true,
|
||||
MasterStatusTransaksiInvestasi: true,
|
||||
investasiId: true,
|
||||
Investasi: true,
|
||||
// Author:true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -59,17 +64,21 @@ export default async function getListAllTransaksiById_Investasi(
|
||||
id: true,
|
||||
namaBank: true,
|
||||
nomorRekening: true,
|
||||
totalTransfer: true,
|
||||
lembarTerbeli: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
authorId: true,
|
||||
quantity: true,
|
||||
price: true,
|
||||
gross_amount: true,
|
||||
merchant_name: true,
|
||||
redirect_url: true,
|
||||
token: true,
|
||||
Author: true,
|
||||
masterStatusTransaksiInvestasiId: true,
|
||||
MasterStatusTransaksiInvestasi: true,
|
||||
investasiId: true,
|
||||
Investasi: true,
|
||||
// Author:true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function getListTransaksiBerhasilInvestasi(
|
||||
idAuthor: string
|
||||
) {
|
||||
const data = await prisma.transaksiInvestasi.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc"
|
||||
},
|
||||
where: {
|
||||
authorId: idAuthor,
|
||||
status_code: "200",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
Investasi: true,
|
||||
Author: true,
|
||||
gross_amount: true,
|
||||
quantity: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -30,6 +30,8 @@ export default async function getOneInvestasiById(id: string) {
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
author: true,
|
||||
countDown: true
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function getOneTransaksiBerhasilByIdInvestasi(
|
||||
idTransaksi: string
|
||||
) {
|
||||
const data = await prisma.transaksiInvestasi.findUnique({
|
||||
|
||||
where: {
|
||||
id: idTransaksi,
|
||||
},
|
||||
select: {
|
||||
Investasi: {
|
||||
select: {
|
||||
|
||||
author: true,
|
||||
BeritaInvestasi: true,
|
||||
DokumenInvestasi: true,
|
||||
ProspektusInvestasi: true,
|
||||
MasterPembagianDeviden: true,
|
||||
MasterPencarianInvestor: true,
|
||||
MasterPeriodeDeviden: true,
|
||||
id: true,
|
||||
title: true,
|
||||
countDown: true,
|
||||
imagesId: true,
|
||||
roi: true,
|
||||
targetDana: true,
|
||||
totalLembar: true,
|
||||
sisaLembar: true,
|
||||
hargaLembar: true,
|
||||
},
|
||||
},
|
||||
id: true,
|
||||
gross_amount: true,
|
||||
quantity: true,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -78,6 +78,7 @@ export default async function getPortoByStatusId(id: string, statusId: number) {
|
||||
updatedAt: true,
|
||||
targetDana: true,
|
||||
MasterPencarianInvestor: true,
|
||||
countDown: true,
|
||||
},
|
||||
});
|
||||
return data;
|
||||
|
||||
113
src/app_modules/investasi/fun/get_token_transaksi.js
Normal file
113
src/app_modules/investasi/fun/get_token_transaksi.js
Normal file
@@ -0,0 +1,113 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import MidTrans from "midtrans-client";
|
||||
|
||||
// const midtransClient = require("midtrans-client");
|
||||
|
||||
// const snap = new midtransClient.Snap({
|
||||
// isProduction: false,
|
||||
// serverKey: process.env.Server_KEY,
|
||||
// clientKey: process.env.Client_KEY,
|
||||
// });
|
||||
|
||||
const snap = new MidTrans.Snap({
|
||||
isProduction: false,
|
||||
serverKey: process.env.Server_KEY,
|
||||
clientKey: process.env.Client_KEY,
|
||||
});
|
||||
|
||||
export default async function getTokenTransaksi(data) {
|
||||
const body = await data;
|
||||
// console.log(body);
|
||||
|
||||
const date = new Date();
|
||||
const randomId = date.getTime();
|
||||
|
||||
const params = {
|
||||
transaction_details: {
|
||||
order_id: "hipmi_" + randomId,
|
||||
gross_amount: body.gross_amount,
|
||||
},
|
||||
item_details: [
|
||||
{
|
||||
id: "item_hipmi_" + randomId,
|
||||
name: body.item_name,
|
||||
price: body.price,
|
||||
quantity: body.quantity,
|
||||
merchant_name: body.merchant_name,
|
||||
},
|
||||
],
|
||||
customer_details: {
|
||||
first_name: body.customer_name,
|
||||
phone: body.phone,
|
||||
// email: "test@midtrans.com",
|
||||
},
|
||||
enabled_payments: [
|
||||
"permata_va",
|
||||
"bca_va",
|
||||
"bni_va",
|
||||
"bri_va",
|
||||
"cimb_va",
|
||||
"other_va",
|
||||
"shopeepay",
|
||||
],
|
||||
bca_va: {
|
||||
va_number: "82340374411111",
|
||||
sub_company_code: "00000",
|
||||
free_text: {
|
||||
inquiry: [
|
||||
{
|
||||
en: "text in English",
|
||||
id: "text in Bahasa Indonesia",
|
||||
},
|
||||
],
|
||||
payment: [
|
||||
{
|
||||
en: "text in English",
|
||||
id: "text in Bahasa Indonesia",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const token = await new Promise(async (res) => {
|
||||
try {
|
||||
const transaksi = await snap.createTransaction(params);
|
||||
// console.log(transaksi);
|
||||
res({
|
||||
status: 200,
|
||||
value: transaksi,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error);
|
||||
res({
|
||||
status: 400,
|
||||
value: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (token.status === 400) {
|
||||
return { token: token };
|
||||
}
|
||||
|
||||
const newTransaksi = await prisma.transaksiInvestasi.create({
|
||||
data: {
|
||||
gross_amount: "" + data.gross_amount,
|
||||
merchant_name: data.merchant_name,
|
||||
price: "" + data.price,
|
||||
quantity: "" + data.quantity,
|
||||
token: token.value.token,
|
||||
redirect_url: token.value.redirect_url,
|
||||
authorId: data.authorId,
|
||||
investasiId: data.investasiId,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
token: token,
|
||||
dataTransaksi: newTransaksi,
|
||||
};
|
||||
}
|
||||
@@ -11,8 +11,6 @@ export default async function getTransaksiByIdInvestasi(id: string) {
|
||||
id: true,
|
||||
namaBank: true,
|
||||
nomorRekening: true,
|
||||
lembarTerbeli: true,
|
||||
totalTransfer: true,
|
||||
active: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
Reference in New Issue
Block a user