diff --git a/client/src/actions/orderActions.js b/client/src/actions/orderActions.js index aee8060..07065d1 100644 --- a/client/src/actions/orderActions.js +++ b/client/src/actions/orderActions.js @@ -117,8 +117,8 @@ export const payOrder = const { data } = await axios.post('/api/payments', { - orderId: orderId, - tokenId:token.id + orderId, + token }); diff --git a/payment/src/routes/create-payment.ts b/payment/src/routes/create-payment.ts index e2e966b..7daeca1 100644 --- a/payment/src/routes/create-payment.ts +++ b/payment/src/routes/create-payment.ts @@ -22,13 +22,13 @@ requireAuth, .not() .isEmpty() .withMessage("Order Id is required"), - body("tokenId") + body("token") .not() .isEmpty() .withMessage("token is required") ],validateRequest, async (req:Request, res:Response)=>{ - const {orderId,tokenId}=req.body; + const {orderId,token}=req.body; const order=await Order.findById(orderId); if(!order){throw new NotFoundError()}; @@ -40,17 +40,15 @@ async (req:Request, res:Response)=>{ throw new BadRequestError('Can not pay for an cancelled order'); } - const paymentIntent = await stripe.paymentIntents.create({ + const charge = await stripe.charges.create({ amount: order.totalPrice*100, - currency: 'inr', - payment_method_types: ['card'], - confirm:true, - payment_method:tokenId + currency: 'INR', + source:token.id }); - if(!paymentIntent.id) throw new Error("Payment Failed"); + if(!charge.id) throw new Error("Payment Failed"); const payment=Payment.build({ orderId, - stripeId:paymentIntent.id + stripeId:charge.id }) await payment.save(); new PaymentCreatedPublisher(natsWrapper.client).publish({ diff --git a/payment/src/stripe.ts b/payment/src/stripe.ts index f6b8b8b..c8dc1b7 100644 --- a/payment/src/stripe.ts +++ b/payment/src/stripe.ts @@ -1,5 +1,6 @@ import Stripe from 'stripe'; + export const stripe=new Stripe(process.env.STRIPE_KEY!,{ - apiVersion:'2022-11-15', + apiVersion: "2022-11-15" }); \ No newline at end of file