From ed2fcca2e3657f6379d6f79e8b9e72f726331918 Mon Sep 17 00:00:00 2001 From: HetavShah Date: Fri, 26 May 2023 10:55:27 +0530 Subject: [PATCH] stripe payment fix --- client/src/actions/orderActions.js | 5 +++-- client/src/screens/OrderScreen.js | 31 ++++------------------------ payment/src/routes/create-payment.ts | 10 +++++++-- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/client/src/actions/orderActions.js b/client/src/actions/orderActions.js index c7487f4..aee8060 100644 --- a/client/src/actions/orderActions.js +++ b/client/src/actions/orderActions.js @@ -105,7 +105,7 @@ export const getOrderDetails = (id) => async (dispatch, getState) => { }; export const payOrder = - (orderId, paymentResult) => async (dispatch, getState) => { + (orderId, token) => async (dispatch, getState) => { try { @@ -117,7 +117,8 @@ export const payOrder = const { data } = await axios.post('/api/payments', { - orderId + orderId: orderId, + tokenId:token.id }); diff --git a/client/src/screens/OrderScreen.js b/client/src/screens/OrderScreen.js index d85bcfe..c73060a 100644 --- a/client/src/screens/OrderScreen.js +++ b/client/src/screens/OrderScreen.js @@ -52,29 +52,6 @@ const OrderScreen = ({}) => { const userLogin = useSelector((state) => state.userLogin); const { userInfo } = userLogin; - const handleToken = async (token, amount) => { - try { - console.log(amount); - const res = await axios.post('/api/payments', { - orderId: order.id, - }); - const { id } = res.data; - console.log(res.data); - if (id) { - toast('Success ! Check emails for details', { - type: 'success', - }); - } else { - toast('Something went wrong', { - type: 'failure', - }); - } - } catch (err) { - toast('Something went wrong', { - type: 'failure', - }); - } - }; if (!loading) { // Calculate prices @@ -119,9 +96,9 @@ const OrderScreen = ({}) => { dispatch(deliverOrder(order)); }; - const successPaymentHandler = (paymentResult) => { - console.log(paymentResult); - dispatch(payOrder(id, paymentResult)); + const handleToken = (token) => { + console.log(token); + dispatch(payOrder(id, token)); }; if (timeLeft < 0) { @@ -238,7 +215,7 @@ const OrderScreen = ({}) => { {loadingPay && } { - const {orderId}=req.body; + const {orderId,tokenId}=req.body; const order=await Order.findById(orderId); if(!order){throw new NotFoundError()}; @@ -40,6 +44,8 @@ async (req:Request, res:Response)=>{ amount: order.totalPrice*100, currency: 'inr', payment_method_types: ['card'], + confirm:true, + payment_method:tokenId }); if(!paymentIntent.id) throw new Error("Payment Failed"); const payment=Payment.build({