Description
Hello, I'm seeking assistance in resolving some issues. Would you mind helping me with the following concerns?
SANDBOX:
QUESTIONS:
- how do i remove ======= ADDITIONAL INFORMATION ====== section
- how to edit ========= SECURITY STATEMENT ==========
- line items Description: 20" POQE CHOPZ 1z (SET) is in place of Name field, while Description field does not exist
- what is the setState for Customer ID :, Fax :, E-Mail : in ==== CUSTOMER BILLING INFORMATION === and do i remove Fax: field
- is the address verification here active: Address Verification : Street Address: Match -- First 5 Digits of Zip: Match
Here is Authorized email template structure
========= SECURITY STATEMENT ==========
It is not recommended that you ship product(s) or otherwise grant services relying solely upon this e-mail receipt.
========= GENERAL INFORMATION =========
Merchant : Tunji Akande (892376)
Date/Time : 25-May-2024 16:47:08 PDT
========= ORDER INFORMATION =========
Invoice : 66526e8435e29ba88ab6
Description : Product Description
Amount : 5.00 (USD)
Payment Method: MasterCard xxxx0015
Transaction Type: Authorization and Capture
============== Line Items ==============
Item: 6648d9dcee746c8f357abead
Description: 20" POQE CHOPZ 1z (SET)
Quantity: 1
Unit Price: $16500.00 (USD)
Item Total: $16500.00 (USD)
============== RESULTS ==============
Response : This transaction has been approved.
Auth Code : GFEV2D
Transaction ID : 80019050046
Address Verification : Street Address: Match -- First 5 Digits of Zip: Match
==== CUSTOMER BILLING INFORMATION ===
Customer ID :
First Name :
Last Name :
Company :
Address :
City :
State/Province :
Zip/Postal Code :
Country :
Phone :
Fax :
E-Mail :
==== CUSTOMER SHIPPING INFORMATION ===
First Name :
Last Name :
Company :
Address :
City :
State/Province :
Zip/Postal Code :
Country :
======= ADDITIONAL INFORMATION ======
Tax :
Duty :
Freight :
Tax Exempt :
PO Number :
//NODE.JS//
//ROUTE
//===================
// AUTHORIZED GATEWAY
//===================
orderRouter.post(
"/:id/authorize-net",
isAuth,
expressAsyncHandler(async (req, res) => {
try {
const { createTransactionRequest } = req.body;
const { transactionRequest } = createTransactionRequest;
const { amount, payment, description } = transactionRequest;
const { creditCard } = payment;
const { cardNumber, expirationDate, cardCode } = creditCard;
const order = await Order.findById(req.params.id).populate("user");
const { shippingAddress, user } = order;
// Extract the customer ID from the user object
const customerId = user.id.toString();
const merchantAuthenticationType =
new APIContracts.MerchantAuthenticationType();
merchantAuthenticationType.setName(process.env.AUTHORIZE_NET_API_KEY);
merchantAuthenticationType.setTransactionKey(
process.env.AUTHORIZE_NET_API_SECRET
);
const creditCardType = new APIContracts.CreditCardType();
creditCardType.setCardNumber(cardNumber);
creditCardType.setExpirationDate(expirationDate);
creditCardType.setCardCode(cardCode);
const paymentType = new APIContracts.PaymentType();
paymentType.setCreditCard(creditCardType);
const orderDetails = new APIContracts.OrderType();
const invoiceNumber = req.params.id.slice(0, 20);
orderDetails.setInvoiceNumber(invoiceNumber);
orderDetails.setDescription(description || "Product Description");
const billTo = new APIContracts.CustomerAddressType();
billTo.setCustomerID(customerId);
billTo.setFirstName(shippingAddress.firstName);
billTo.setLastName(shippingAddress.lastName);
billTo.setCompany(shippingAddress.company);
billTo.setAddress(shippingAddress.address);
billTo.setCity(shippingAddress.city);
billTo.setState(shippingAddress.cState);
billTo.setZip(shippingAddress.zipCode);
billTo.setCountry(shippingAddress.country);
billTo.setPhoneNumber(shippingAddress.phone);
const shipTo = new APIContracts.CustomerAddressType();
shipTo.setFirstName(shippingAddress.firstName);
shipTo.setLastName(shippingAddress.lastName);
shipTo.setCompany(shippingAddress.company);
shipTo.setAddress(shippingAddress.address);
shipTo.setCity(shippingAddress.city);
shipTo.setState(shippingAddress.cState);
shipTo.setZip(shippingAddress.zipCode);
shipTo.setCountry(shippingAddress.country);
const transactionRequestType = new APIContracts.TransactionRequestType();
transactionRequestType.setTransactionType(
APIContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION
);
transactionRequestType.setPayment(paymentType);
transactionRequestType.setAmount(amount);
transactionRequestType.setOrder(orderDetails);
transactionRequestType.setBillTo(billTo);
transactionRequestType.setShipTo(shipTo);
// Set orderItems as line items
if (order.orderItems) {
const apiLineItems = new APIContracts.ArrayOfLineItem();
const lineItemArray = [];
order.orderItems.forEach((orderItem) => {
const apiLineItem = new APIContracts.LineItemType();
apiLineItem.setItemId(orderItem._id.toString());
apiLineItem.setName(orderItem.name);
apiLineItem.setDescription(orderItem.description);
apiLineItem.setQuantity(orderItem.quantity);
apiLineItem.setUnitPrice(orderItem.price);
lineItemArray.push(apiLineItem);
});
apiLineItems.setLineItem(lineItemArray);
transactionRequestType.setLineItems(apiLineItems);
}
const createRequest = new APIContracts.CreateTransactionRequest();
createRequest.setMerchantAuthentication(merchantAuthenticationType);
createRequest.setTransactionRequest(transactionRequestType);
const ctrl = new APIControllers.CreateTransactionController(
createRequest.getJSON()
);
ctrl.execute(async function () {
const apiResponse = ctrl.getResponse();
const response = new APIContracts.CreateTransactionResponse(
apiResponse
);
if (response != null) {
if (
response.getMessages().getResultCode() ===
APIContracts.MessageTypeEnum.OK
) {
const transactionResponse = response.getTransactionResponse();
if (
transactionResponse != null &&
transactionResponse.getMessages() != null
) {
order.isPaid = true;
order.paidAt = Date.now();
order.paymentResult = {
id: transactionResponse.getTransId(),
status:
transactionResponse.getResponseCode() === "1"
? "approved"
: "declined",
authCode: transactionResponse.getAuthCode(),
avsResultCode: transactionResponse.getAvsResultCode(),
cvvResultCode: transactionResponse.getCvvResultCode(),
accountNumber: transactionResponse.getAccountNumber(),
accountType: transactionResponse.getAccountType(),
};
// order.paymentMethod = req.body.paymentMethod;
// order.currencySign = req.body.currencySign;
// for (const index in order.orderItems) {
// const item = order.orderItems[index];
// const product = await Product.findById(item.product);
// if (item.quantity > product.countInStock) {
// throw new Error(
// `Insufficient stock for product: ${product.name}`
// );
// }
// const currentDate = new Date();
// const formattedDate = `${currentDate.getFullYear()}-${(
// currentDate.getMonth() + 1
// )
// .toString()
// .padStart(2, "0")}-${currentDate
// .getDate()
// .toString()
// .padStart(2, "0")}`;
// const existingSoldEntryIndex = product.sold.findIndex(
// (entry) =>
// entry.date.toISOString().slice(0, 10) === formattedDate
// );
// if (existingSoldEntryIndex !== -1) {
// product.sold[existingSoldEntryIndex].value += item.quantity;
// } else {
// product.sold.push({
// value: item.quantity,
// date: new Date(formattedDate),
// });
// }
// product.countInStock -= item.quantity;
// product.numSales += item.quantity;
// await product.save();
// }
// const updatedOrder = await order.save();
res.status(200).json({
message: "Transaction successful",
// response: updatedOrder,
});
} else {
const errors = transactionResponse
? transactionResponse.getErrors()
: null;
res.status(400).json({
message: "Failed transaction",
errors: errors
? errors.getError()
: "No error details available",
});
}
} else {
const transactionResponse = response.getTransactionResponse();
const errors = transactionResponse
? transactionResponse.getErrors()
: null;
res.status(400).json({
message: "Failed transaction",
errors: errors
? errors.getError()
: response.getMessages().getMessage(),
});
}
} else {
res.status(500).json({ message: "Null response" });
}
});
} catch (error) {
console.error("Transaction processing error:", error);
res.status(500).json({ message: "Transaction processing failed" });
}
})
);