-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (74 loc) · 2.34 KB
/
index.js
File metadata and controls
82 lines (74 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require("dotenv").config();
var express=require('express');
const cors = require('cors');
const stripe=require('stripe')(process.env.STRIPE_SECRIT)
const port=3000||process.env.PORT;
var app=express();
app.set('view engine','ejs');
app.get('/',(req,res)=>{
res.render('index')
});
app.use(cors());
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(
bodyparse.urlencoded({
extended:false
})
);
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [{
price_data: {
currency: 'usd',
product_data: {
name: 'T-shirt',
},
unit_amount: 2000,
},
quantity: 1,
}],
mode: 'payment',
ui_mode: 'embedded',
return_url: 'https://example.com/checkout/return?session_id={CHECKOUT_SESSION_ID}'
});
res.send({clientSecret: session.client_secret});
});
// app.post('/create-checkout-session', async (req, res) => {
// try {
// // const price = req.body.price;
// const session = await stripe.checkout.sessions.create({
// line_items: [{
// price_data: {
// currency: 'usd',
// product_data: {
// name: 'عسل سدر طبيعي',
// },
// unit_amount: 10 * 50 // تحويل السعر إلى سنتات
// },
// quantity: 1
// }],
// mode: 'payment',
// ui_mode: 'embedded',
// success_url: 'https://ghidhaalruwh.netlify.app/complate',
// cancel_url: 'https://ghidhaalruwh.netlify.app/cancel'
// });
// res.redirect(session.url); // توجيه المستخدم إلى صفحة الدفع في Stripe
// } catch (error) {
// console.error('Error:', error);
// res.status(500).send('Error occurred');
// }
// });
app.get('/complate',async(req,res)=>{
try{
await paypal.capturpayment(req.query.token)
res.send('secessful')
}catch(error){
res.send('error : '+error)
}
})
app.get('/cancel',(rez,res)=>{
res.redirect('/')
})
app.listen(port,(req,res)=>{console.log(`that is server ${port}`);});