Skip to content

Commit

Permalink
reorg index
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcholmsky committed Jan 4, 2024
1 parent f13d56c commit 3f71a12
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 42 deletions.
65 changes: 32 additions & 33 deletions api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,41 @@ app.use(express.static("public"));

let braceletDetails

app.post("/create-payment-intent", async (req, res) => {
console.log(req)
console.log(req.body)
console.log(req.body?.braceletDetails)
braceletDetails = req.body?.braceletDetails?.braceletDetails
console.log("intent BD", braceletDetails)
// Single-sided product id
const productId = process.env.PRODUCT_ID;

try {
const productPrice = await calculateOrderAmount(productId);

const paymentIntent = await stripe.paymentIntents.create({
amount: productPrice,
currency: "cad",
automatic_payment_methods: {
enabled: true,
}
});

res.send({
clientSecret: paymentIntent.client_secret,
productPrice: productPrice/100,
});

} catch (error) {
res.status(500).json({ error: error.message });
}
});

app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
console.log("webhook called")
let event = request.body;
console.log("prev BD", braceletDetails)
console.log("event: ", event)
console.log("event BD: ", request.body.braceletDetails)

braceletDetails = request.body?.braceletDetails?.braceletDetails
console.log("post BD", braceletDetails)

console.log("webhook BD", braceletDetails)

if (endpointSecret) {
console.log("endpoint secret found")
Expand Down Expand Up @@ -67,33 +93,6 @@ app.post('/webhook', express.raw({type: 'application/json'}), (request, response
response.json({received: true});
});

app.post("/create-payment-intent", async (req, res) => {
braceletDetails = req.body?.braceletDetails?.braceletDetails
console.log("intent BD", braceletDetails)
// Single-sided product id
const productId = process.env.PRODUCT_ID;

try {
const productPrice = await calculateOrderAmount(productId);

const paymentIntent = await stripe.paymentIntents.create({
amount: productPrice,
currency: "cad",
automatic_payment_methods: {
enabled: true,
}
});

res.send({
clientSecret: paymentIntent.client_secret,
productPrice: productPrice/100,
});

} catch (error) {
res.status(500).json({ error: error.message });
}
});

async function updateGoogleSheet(productPrice, braceletDetails, paymentIntent) {
// Append order data to Google Spreadsheet
let orderData
Expand Down
11 changes: 2 additions & 9 deletions client/src/components/checkout-page/PaymentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@ const PaymentDetails = () => {

useEffect(() => {
console.log("Starting PD useEffect");

const isDoubleSided =
braceletDetails.braceletDetails['centerpiece']['front-side']['type'] &&
braceletDetails.braceletDetails['centerpiece']['back-side']['type']
? true
: false;

console.log("isDoubleSided:", isDoubleSided);

console.log("payment details in useEffect", braceletDetails)

// Create PaymentIntent with the dynamically determined productId
fetch("https://traitlets-be.onrender.com/create-payment-intent", {
method: "POST",
Expand Down

0 comments on commit 3f71a12

Please sign in to comment.