Nodejs의 Stripe 결제 게이트웨이 통합

안녕하세요 여러분, 오늘 우리는 노드에서 스트라이프 지불 게이트웨이를 구현할 것입니다. 우리는 간단한 주문을 만들고 카드로 지불합니다. Stripe 체크아웃은 아름다운 UI와 다양한 결제 옵션을 제공합니다. 더 나은 이해를 위해 데모 비디오를 시청하고 내 채널을 지원하십시오 ????.

그럼 코딩을 시작해 볼까요?

데모 비디오

Project Github Link

Node.js 앱 만들기

$ mkdir node-stripe-payment-gateway
$ cd node-stripe-payment-gateway
$ npm init –yes
$ npm install express stripe
Express : Express는 최소한의 유연한 Node.js 웹 애플리케이션 프레임워크입니다.
스트라이프 : 스트라이프 노드 라이브러리는 스트라이프 API에 대한 편리한 액세스를 제공합니다.

package.json은 다음과 같습니다.

{
“name”: “node-stripe-payment-gateway”,
“version”: “1.0.0”,
“description”: “Implementing stripe payment gateway in node.js”,
“main”: “index.js”,
“scripts”: {
“start”: “node index.js”
},
“author”: “jahangeer”,
“license”: “ISC”,
“dependencies”: {
“express”: “^4.17.1”,
“stripe”: “^8.156.0”
}
}
결제 경로 구성
루트 폴더에서 index.js 파일을 생성합니다.

const express = require(“express”);
const app = express();
const path = require(“path”);
const stripe = require(“stripe”)(“Add your secret key”);
const YOUR_DOMAIN = “:8080”;
// static files
app.use(express.static(path.join(__dirname, “views”)));
// middleware
app.use(express.json());
// routes
app.post(“/payment”, async (req, res) => {
const { product } = req.body;
const session = await stripe.checkout.sessions.create({ payment_method_types: [“card”], line_items: [ { price_data: { currency: “inr”, product_data: { name: product.name, images: [product.image], }, unit_amount: product.amount * 100, }, quantity: product.quantity, }, ], mode: “payment”, success_url: `${YOUR_DOMAIN}/success.html`, cancel_url: `${YOUR_DOMAIN}/cancel.html`,
}); res.json({ id: session.id });
});
// listening…
const port = process.env.PORT || 8080;
app.listen(port, () => console.log(`Listening on port ${port}…`));
스타일.css
/views/style.css

.container {
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
background: #f5f5f5;
}
.product {
width: 250px;
padding: 10px;
height: auto;
background-color: white;
border-radius: 5px;
border: 2px solid black;
}
.product_img {
width: 100%;
height: 250px;
object-fit: contain;
border-bottom: 1px solid black;
}
.description {
display: flex;
justify-content: space-between;
}
#btn {
width: 100%;
padding: 10px;
}
결제 UI
/views/checkout.html Buy Products rel=”stylesheet” href=”style.css”>
src= “/v3/” >
class=”container” > class=”product”> src=”-apple.com/4668/as-images.apple.com/is/iphone-12-purple-select-2021?wid=470&hei=556&fmt=jpeg&qlt=95&.v= ” alt=”iphone 12″ class=”product_img” /> class=”description”> iPhone ₹ 100.00