Skip to content

Commit

Permalink
Add Stripe payment integration
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyzen committed Mar 16, 2024
1 parent 5da380c commit 47a8712
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions functions/stripe.js → functions/stripe.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

exports.handler = async (event, context) => {
const { email, amount, currency } = JSON.parse(event.body);
console.log({ email, amount, currency });
exports.handler = async (event: any, context: any) => {
const { amount, currency } = JSON.parse(event.body);

try {
const paymentIntent = await stripe.paymentIntents.create({
amount: parseInt(amount),
currency: currency || 'usd',
currency: currency || 'eur',
payment_method_types: ['card'],
});

Expand All @@ -16,10 +15,9 @@ exports.handler = async (event, context) => {
body: JSON.stringify({ ...paymentIntent }),
};
} catch (error) {
console.log(error);
return {
statusCode: 500,
body: JSON.stringify({ error: error.raw.message }),
body: JSON.stringify({ error }),
};
}
};

0 comments on commit 47a8712

Please sign in to comment.