Skip to content

Commit 220694a

Browse files
committed
22. Back to the Client | 13. Showing a Stripe Payment Form
1 parent 22c01b5 commit 220694a

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

22_Back_to_the_Client.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ If chome will block page for security reasons, type: **thisisunsafe**
6464

6565
<br/>
6666

67+
### 10. Programmatic Navigation to Wildcard Routess
68+
69+
<br/>
70+
71+
### 11. The Expiration Timer
72+
73+
<br/>
74+
75+
### 12. Displaying the Expiration
76+
77+
<br/>
78+
79+
### 13. Showing a Stripe Payment Form
80+
81+
$ cd client
82+
$ npm install react-stripe-checkout
83+
84+
<br/>
85+
6786
---
6887

6988
<br/>

22_Back_to_the_Client/app/client/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

22_Back_to_the_Client/app/client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"bootstrap": "^4.4.1",
1616
"next": "^9.3.6",
1717
"react": "^16.13.1",
18-
"react-dom": "^16.13.1"
18+
"react-dom": "^16.13.1",
19+
"react-stripe-checkout": "^2.6.3"
1920
}
2021
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useEffect, useState } from 'react';
2+
3+
const OrderShow = ({ order }) => {
4+
const [timeLeft, setTimeLeft] = useState(0);
5+
6+
useEffect(() => {
7+
const findTimeLeft = () => {
8+
const msLeft = new Date(order.expiresAt) - new Date();
9+
setTimeLeft(Math.round(msLeft / 1000));
10+
};
11+
12+
findTimeLeft();
13+
const timerId = setInterval(findTimeLeft, 1000);
14+
return () => {
15+
clearInterval(timerId);
16+
};
17+
}, [order]);
18+
19+
if (timeLeft < 0) {
20+
return <div>Order Expired</div>;
21+
}
22+
23+
return <div>TIme left to pay: {timeLeft} seconds</div>;
24+
};
25+
26+
OrderShow.getInitialProps = async (context, client) => {
27+
const { orderId } = context.query;
28+
const { data } = await client.get(`/api/orders/${orderId}`);
29+
30+
return { order: data };
31+
};
32+
33+
export default OrderShow;

22_Back_to_the_Client/app/client/pages/tickets/[ticketId].js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Router from 'next/router';
12
import useRequest from '../../hooks/use-request';
23

34
const TicketShow = ({ ticket }) => {
@@ -7,7 +8,8 @@ const TicketShow = ({ ticket }) => {
78
body: {
89
ticketId: ticket.id,
910
},
10-
onSuccess: (order) => console.log(order),
11+
onSuccess: (order) =>
12+
Router.push('/orders/[orderId]', `/orders/${order.id}`),
1113
});
1214

1315
return (

0 commit comments

Comments
 (0)