Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
YehiaFarghaly committed Jan 2, 2024
2 parents 9d388d5 + ea19d1f commit 274cb48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
16 changes: 5 additions & 11 deletions payment/src/api/PaymentAPI.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import Stripe from 'stripe';
import axios from 'axios';

import {
OK_STATUS_CODE,
ERROR_STATUS_CODE,
CLINIC_BASE_URL,
PATIENTS_BASE_URL,
BAD_REQUEST_CODE_400,
SECRET_KEY
BAD_REQUEST_CODE_400
} from '../utils/Constants.js';
import { isValidMongoId } from '../utils/Validation.js';
import PaymentService from '../service/payment-service.js';

const stripe = new Stripe(SECRET_KEY);

export const payment = (app) => {

const service = new PaymentService();

app.post('/payment/card', async (req, res) => {
try{
const total_amount = Number(req.body.paymentAmount);
const paymentIntent = await stripe.paymentIntents.create({
amount: parseInt(total_amount * 100),
currency: "usd",
automatic_payment_methods: {
enabled: true,
},
});
const paymentIntent = service.createPaymentIntent(total_amount);
res.status(OK_STATUS_CODE).send({
clientSecret: paymentIntent.client_secret,
});
Expand Down
21 changes: 21 additions & 0 deletions payment/src/service/payment-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Stripe from 'stripe';
import {
SECRET_KEY
} from '../utils/Constants.js';

const stripe = new Stripe(SECRET_KEY);

class PaymentService{

async createPaymentIntent(total_amount){
await stripe.paymentIntents.create({
amount: parseInt(total_amount * 100),
currency: "usd",
automatic_payment_methods: {
enabled: true,
},
});
}
}

export default PaymentService;

0 comments on commit 274cb48

Please sign in to comment.