Skip to content

Commit

Permalink
Merge pull request Project-Based-Learning-IT#39 from Project-Based-Le…
Browse files Browse the repository at this point in the history
…arning-IT/Mayank

payment is done
  • Loading branch information
Mayank8085 committed Apr 1, 2021
2 parents 1886744 + c29ecfb commit 0d577fc
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 20 deletions.
24 changes: 20 additions & 4 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.15",
"url": "^0.11.0"
"stripe": "^8.141.0",
"url": "^0.11.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"nyc": "^15.1.0",
Expand Down
43 changes: 43 additions & 0 deletions backend/routes/patients.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const router = require('express').Router();
const Patient = require('../models/patient.model');
const Appointment = require('../models/appointment.model');
const jwt = require('jsonwebtoken');
const stripe =require("stripe")("sk_test_51IabQNSCj4BydkZ38AsoDragCM19yaMzGyBVng5KUZnCNrxCJuj308HmdAvoRcUEe2PEdoORMosOaRz1Wl8UX0Gt00FCuSwYpz")
const uuid = require('uuid/v4');

// To get all the patients
// ** ONLY FOR TESTING **
Expand Down Expand Up @@ -179,4 +181,45 @@ router.route('/upcoming-appointments').post(async (req, res) => {
}
})

router.route("/payment").post(async (req,res)=>{
const {finalBalnce, token}=req.body;
console.log(product);
const idempotencyKey = uuid();

return stripe.customers
.create({
email: token.email,
source: token.id
})
.then(customer => {
stripe.charges
.create(
{
amount: finalBalnce * 100,
currency: 'usd',
customer: customer.id,
receipt_email: token.email,
description: `Booked Appointement Successfully`,
shipping: {
name: token.card.name,
address: {
line1: token.card.address_line1,
line2: token.card.address_line2,
city: token.card.address_city,
country: token.card.address_country,
postal_code: token.card.address_zip
}
}
},
{
idempotencyKey
}
)
.then(result => res.status(200).json(result))
.catch(err => console.log(err));
})
.catch(console.log("FAILED"));
})


module.exports = router;
2 changes: 1 addition & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mongoose = require('mongoose');
const patientsRouter = require('./routes/patients');
const doctorsRotuer = require('./routes/doctors');
require('dotenv').config();

app.use(express.json());
app.use(cors(
{
Expand Down
5 changes: 5 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-scrollbars-custom": "^4.0.25",
"react-stripe-checkout": "^2.6.3",
"reactstrap": "^8.9.0",
"web-vitals": "^1.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Doctor/BookingSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const BookingSlots = (props) => {
</thead>
<tbody>
{Slots.map((slot) => (
<tr>
<tr key={slot._id}>
<th scope="row">{slot.time}</th>
{slot.isBooked ? (
<td>Booked</td>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Doctor/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Search = () => {
onClick={() => suggestionSelected(item)}
key={item}
>
{item}
{item}
</li>
))}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Patient/AppointmentStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ const AppointmentStatus = () => {
);
};

export default AppointmentStatus;
export default AppointmentStatus;
42 changes: 36 additions & 6 deletions frontend/src/Patient/Payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link, useHistory } from "react-router-dom";

import Navbar from "../Basic/Navbar";
import Leftside from "../Dashbaord/LeftsidePatient";
import StripeCheckoutButton from "react-stripe-checkout";

function getEndDateTime(dateTime) {
const hrs = (parseInt(dateTime.split('T')[1].split(':')[0]) + 1).toString().padStart(2, '0')
Expand All @@ -13,6 +14,7 @@ function getEndDateTime(dateTime) {
}

const Payment = (props) => {
const [finalBalnce, setFinalBalnce] = useState(0)
const history = useHistory();

function createEvent(id, dateTime, doctorEmail) {
Expand Down Expand Up @@ -78,15 +80,32 @@ const Payment = (props) => {

if (data.doctorEmail) {
createEvent(data._id, data.date + 'T' + data.slotTime, data.doctorEmail)

}

history.push("/patient");
// history.push("/patient");
};
useEffect(() => {
setFinalBalnce(1.18*doctor.feesPerSession)
}, [])


const makePayment=async(token)=>{

const {result}= await Axios.post( `${process.env.REACT_APP_SERVER_URL}/patients/payment`,{
token, finalBalnce
})

console.log(result);



}

return (
<div className="bg-dark" style={{ height: "100vh" }}>
<Navbar />
<div>
<div >
<div className="row m-5" style={{ maxWidth: "100%" }}>
<div
className="col-3 col-md-3 p-4 bg-white "
Expand All @@ -95,14 +114,14 @@ const Payment = (props) => {
<Leftside />
</div>
<div
className="col-9 col-md-9 p-4"
className="col-9 col-md-9 p-4 "
style={{
border: "15px solid yellow ",
height: "80vh",
backgroundColor: "#6c757d",
}}
>
<div className="container">
<div className="container text-white">
<div className="row">
<div className="well col-xs-10 col-sm-10 col-md-6 col-xs-offset-1 col-sm-offset-1 col-md-offset-3">
<div className="row">
Expand Down Expand Up @@ -130,7 +149,7 @@ const Payment = (props) => {
<div className="text-center">
<h1>Receipt</h1>
</div>
<table className="table table-hover">
<table className="table table-hover text-white">
<thead>
<tr>
<th>Doctor Name</th>
Expand Down Expand Up @@ -173,6 +192,7 @@ const Payment = (props) => {
</p>
<p>
<strong>{0.18 * doctor.feesPerSession}</strong>

</p>
</td>
</tr>
Expand All @@ -186,12 +206,20 @@ const Payment = (props) => {
</td>
<td className="text-center text-danger">
<h4>
<strong>{1.18 * doctor.feesPerSession}</strong>

<strong>{finalBalnce}</strong>
</h4>
</td>
</tr>
</tbody>
</table>
<StripeCheckoutButton
stripeKey="pk_test_51IabQNSCj4BydkZ3VIEbtfIJoWfSESvGSia3mSOfCYPWiyGxNxyr42IRvpmi8f8WbnhzCYBIZMyshg540TErXG3500fbHzRzLc"
token={makePayment}
amount={finalBalnce}
name="Placed Appointment"
shippingAddress
billingAddress>
<button
type="button"
className="btn btn-success btn-lg btn-block"
Expand All @@ -200,6 +228,8 @@ const Payment = (props) => {
Pay Now&nbsp;&nbsp;&nbsp;
<span className="glyphicon glyphicon-chevron-right" />
</button>
</StripeCheckoutButton>

</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Patient/PerviousAppointments.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const PatientAppointments = () => {
</thead>
<tbody>
{Appointments.map((Appointment) => (
<tr>
<tr key={Appointment._id}>
<th scope="row">{Appointment.date}</th>
<th scope="row">{Appointment.slotTime}</th>
<th scope="row">{Appointment.doctorName}</th>
Expand All @@ -72,4 +72,4 @@ const PatientAppointments = () => {
);
};

export default PatientAppointments;
export default PatientAppointments;
3 changes: 0 additions & 3 deletions package-lock.json

This file was deleted.

0 comments on commit 0d577fc

Please sign in to comment.