Skip to content

Commit

Permalink
creating charge with inr
Browse files Browse the repository at this point in the history
  • Loading branch information
HetavShah committed May 26, 2023
1 parent ed2fcca commit 5c7275a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions client/src/actions/orderActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export const payOrder =


const { data } = await axios.post('/api/payments', {
orderId: orderId,
tokenId:token.id
orderId,
token
});


Expand Down
16 changes: 7 additions & 9 deletions payment/src/routes/create-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()};
Expand All @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion payment/src/stripe.ts
Original file line number Diff line number Diff line change
@@ -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"
});

0 comments on commit 5c7275a

Please sign in to comment.