const express = require("express"); const mongoose = require("mongoose"); const dotenv = require("dotenv") const app = express(); const cors = require("cors"); const logger = require("morgan"); const port = 5100; const mainRoute = require("./routes/index.js"); const Iyzipay = require("iyzipay"); dotenv.config(); const iyzipay = new Iyzipay({ apiKey: process.env.IYZICO_API_KEY, secretKey: process.env.IYZICO_SECRET_KEY, uri: process.env.MONGO_URL, }); app.post("/api/payment", (req, res) => { const { price, paidPrice, currency, basketId, paymentCard, buyer, shippingAddress, basketItems, } = req.body; const request = { locale: Iyzipay.LOCALE.TR, conversationId: "123456789", price: price, paidPrice: paidPrice, currency: currency, installment: "1", basketId: basketId, paymentChannel: Iyzipay.PAYMENT_CHANNEL.WEB, paymentGroup: Iyzipay.PAYMENT_GROUP.PRODUCT, paymentCard: paymentCard, buyer: buyer, shippingAddress: shippingAddress, billingAddress: billingAddress, basketItems: basketItems, }; iyzipay.payment.create(request, (err, result) => { if (err) { return res.status(500).json(err); } res.status(200).json(result); }); }); const connect = async () => { try { await mongoose.connect(process.env.MONGO_URL); console.log("connect mongodb"); } catch (error) { throw error; } }; //middleewares app.use(logger("dev")); app.use(express.json()); app.use(cors()); app.use("/api", mainRoute); app.listen(port, () => { connect(); console.log(`Sunucu ${port} portunda çalışıyor.`); });