반응형
https://stripe.com/docs/checkout/quickstart
This link is simple api code with nodejs ↑
in there
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: '{{PRICE_ID}}',
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}/success.html`,
cancel_url: `${YOUR_DOMAIN}/cancel.html`,
});
res.redirect(303, session.url);
});
price: '{{PRICE_ID}}' is can select my product with price of my product list at Stripe.
When you search Product (just make one test product and operate search code)
const products = await stripe.products.search({
query: 'active:\'true\' AND metadata[\'order_id\']:\'6735\'',
});
you can get json data.
but you have to know that "stripe.products.search" this is not contain this price.
So if you want to get price each products use this.
const products = await stripe.products.search({
query: 'metadata[\'store_index\']:\'' + req.body.storeindex + '\'',
});
const prices = []
for (let i = 0; i < (products.data).length; i++){
const price = await stripe.prices.search({
query: 'product:\'' + products.data[i].id + '\'',
})
products.data[i].id = products.data[i].id + ","+ price.data[0].id
}
res.json(products)
for use this code, you need to add metadata at your product.
"stripe.prices.search" this contain product id. so we can find price using product id which we get this at
"stripe.products.search"
Using all json's data you can apply this to many code.
반응형
'IT기술(코딩) > nodejs' 카테고리의 다른 글
nodejs에서 fetch 사용방법 fetch is not a function $.ajax 사용불가 (0) | 2024.01.04 |
---|---|
multer 사용시에 [Violation] handler took 발생 현상 원인 및 조치 자바스크립트 2. (0) | 2023.09.23 |
자바스크립트 express multer 다중파일 여러파일 이미지 업로드 할때 한개만 업로듣 되는현상 (0) | 2023.09.23 |
multer 사용시에 [Violation] handler took 발생 현상 원인 및 조치 자바스크립트 1. (0) | 2023.08.30 |
multer 응용 및 내부 기능 한계점 극복 formdata사용 (0) | 2023.07.17 |