this is the function in the “use client” file
const handleOrderTransaction = (index: number) => {
const transaction = transactions[index]
if (!form.Name || !form.PhoneNumber) {
return toast.error("חובה למלא את פרטי המזמין!")
}
if (ship && !form.city || !form.customerName || !form.homeNumber || !form.street) {
return toast.error("חובה למלא פרטי משלוח!")
}
if (ship && !form.customerName || !form.shipDate) {
return toast.error("חובה למלא את פרטי המקבל!")
}
if (!ship && !form.storeId) {
return toast.error("חובה לבחור נקודת איסוף!")
}
if (transaction && transaction.type === OrderTransactionPayment.NOT_PAY && !transaction.payDate) {
return toast.error("חובה להוסיף תאריך לתשלום!")
}
let formOrder = {
...form,
storeId: ship ? "" : form.storeId,
customerBusinessName: form.customerBusiness ? form.customerBusinessName : ""
}
if(transactions.every(i => i.paid)) {
return router.push(`/orders/${form?.id}`)
}
if (!transaction) {
return toast.promise(createOrderZeroAmount(productsSend, formOrder, discounts, totalAmount), {
loading: "מעביר להזמנה...",
success: (data) => {
onGetOrders()
router.push(`/orders/${data?.id}`)
return "תשלום בוצע בהצלחה!"
},
error: (err) => err.message
})
}
toast.promise(newOrderWithTransaction(productsSend, formOrder, discounts, totalAmount, transaction , ship , form.id), {
loading: "מחייב תשלום...",
success: (data) => {
setTransactions(prev => prev.map((tran, i) => i === index ?
({
...tran,
paid: transaction.type === OrderTransactionPayment.CHECKOUT ? true : data.paid!,
card4Digits: data.card4Digits!,
receiptCopy: data.receiptCopy ? data.receiptCopy : "",
receiptOriginal: data.receiptOriginal ? data.receiptOriginal : "",
})
: tran))
setForm(prev => ({...prev, id: data.orderId}))
onGetOrders()
return "תשלום בוצע בהצלחה!"
},
error: (err) => err.message
})
}
and this in the file fetch-orders.ts with “use-server”
export const newOrderWithTransaction = async (products: OrderProductNew[], customer: OrderCustomer , discounts : OrderProductNew[] , amount : number , transaction : OrderTransactionType , ship : boolean , orderId ?: number) => {
try {
const session: Session | null = await getServerSession(authOptions)
if (!session?.user) {
throw new Error("אין לך הרשאה לבצע פעולה זו!");
}
const client = {
name: customer.Name,
email: customer.Email || process.env.DEFAULT_MAIL!,
address: `${customer.street} ${customer.homeNumber}`,
city: customer.city,
phone: customer.PhoneNumber,
}
const incomeProduct = products.map(item => ({
description : item.Name,
quantity : item.Quantity,
price : item.Amount,
currency : "ILS",
currencyRate : 1,
itemId : item.productId?.toString(),
vatType : 1
})) as IncomeDocumentType[];
const discountAmount = discounts.reduce((previousValue , currentValue) => previousValue + currentValue.Amount,0)
let income = [...incomeProduct]
if(ship) {
const allShips = await getAllShip()
const findShip = allShips.find(i => i.city === customer.city)
if(findShip) {
income.push({
description : "עלות משלוח",
quantity : 1,
price : parseFloat(findShip.amount),
currency : "ILS",
currencyRate : 1,
vatType : 1
})
}
}
if(orderId) {
return newOrderTransaction(orderId , transaction , client , income , amount , discountAmount)
}
const couponCode = discounts.find(i => i.type === "coupon")?.Code
const pointsUsage = discounts.find(i => i.type === "points")?.Amount
const giftCode = discounts.find((i) => i.type === "giftCart");
const data = {
...customer,
status : transaction.amount === amount ? OrderStatus.PAID : OrderStatus.PENDING,
Email: customer.Email.toLowerCase(),
couponCode : couponCode!!,
pointsUsage : pointsUsage!!,
giftCode: giftCode!!?.Code,
giftUsage : giftCode!!?.Amount,
homeNumber : customer?.homeNumber?.toString(),
homeFloor : customer?.homeFloor?.toString(),
amount
} as any
const order = await db.order.create({
data
})
await Promise.all(
products.map(async (product) => {
await db.orderProduct.create({
data: {
productId : product?.productId!,
Name : product.Name,
Amount : product.Amount,
Quantity : product.Quantity,
Image : product.Image!,
orderId: order.id
},
include: {
product: true
}
})
})
)
return newOrderTransaction(order.id , transaction , client , income , amount , discountAmount)
} catch (err) {
throw err
}
}
export const newOrderTransaction = async (orderId : number , transaction : OrderTransactionType , client : InvoiceCustomer , income : IncomeDocumentType[] , amount : number , discount : number) => {
try {
const trans = {
CardNumber : transaction.cardNumber , CVV : transaction.cvv , ExpDate_MMYY : transaction.expiryDate?.replace("/" , "") , TransactionSum : transaction.amount , NumberOfPayments : transaction.numberOfPayments
}
let data = {
type : transaction.type,
amount : transaction.amount,
orderId,
payDate : transaction.payDate,
bankAcountNumber : transaction.bankAcountNumber,
bankBranch : transaction.bankBranch,
bankName : transaction.bankName,
referenceId: parseInt(transaction.referenceId!),
chequeNumNumber: transaction.referenceId,
accountPayNumber : transaction.accountPayNumber
} as any
if(transaction.type === OrderTransactionPayment.CREDIT_CARD) {
const resp = await fetch(`${process.env.NEXTAUTH_URL!}/api/create-order-transaction`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(trans),
})
let response = await resp.json()
if (response.HasError) {
throw new Error(response.ReturnMessage)
}
data = {
...data,
cardName : response.CardName,
card4Digits : parseInt(response.Card4Digits),
expiryDate : response.ExpDate_MMYY,
referenceId : response.ReferenceNumber.toString(),
token : response.Token,
numberOfPayments : transaction.numberOfPayments,
paid : true
} as any
}
const newTransaction = await db.orderTransaction.create({
data
})
if(transaction.type === OrderTransactionPayment.CHECKOUT) {
return newTransaction
}
let receipt : any
if(transaction.type === OrderTransactionPayment.NOT_PAY || transaction.type === OrderTransactionPayment.DELIVERY_PAY) {
if(transaction.payDate) {
await newNotification({ transactionId : newTransaction.id , createdAt : transaction.payDate , type : NotificationType.TRANSACTION})
}
receipt = await createInvoice(newTransaction.id , client , income)
} else {
if(transaction.amount === amount ) {
await createInvoiceReceipt(newTransaction.orderId , client , income , [client.email] , discount)
}
receipt = await createReceipt(newTransaction , client)
}
return db.orderTransaction.update({
where : {id : newTransaction.id},
data : {
receiptNumber : receipt.receiptNumber,
receiptOriginal : receipt.receiptOriginal,
receiptCopy : receipt.receiptCopy,
paid : transaction.type !== OrderTransactionPayment.NOT_PAY
}
})
} catch (err) {
throw err
}
}
why i in the development in local its work fine but after deploy to amplify aws i get this error
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error