Setup: Stripe API #60#97
Conversation
sundayezeilo
left a comment
There was a problem hiding this comment.
Great work to this stage 👍
Just check out a few comments I left and take a look.
Happy coding!
| setUserIds({ stripeId, userId: user.id }); | ||
| return stripeId; | ||
| } catch (err) { | ||
| console.log(err); |
|
|
||
| SetPaymentProfileExist(true); | ||
| } catch (err) { | ||
| console.log(err); |
| const asyncHandler = require("express-async-handler"); | ||
|
|
||
| exports.createPaymentIntent = asyncHandler(async (req, res) => { | ||
| if (req.method === "POST") { |
There was a problem hiding this comment.
Once you create your routes, you don't need this kind of check.
| exports.createPaymentIntent = asyncHandler(async (req, res) => { | ||
| if (req.method === "POST") { | ||
| try { | ||
| const { amount } = req.body; |
| const { userId } = req.params; | ||
| if (!userId || !id) { | ||
| return res | ||
| .status(404) |
There was a problem hiding this comment.
A missing field in the request should be a bad request status 400
| const { customerId } = req.params; | ||
|
|
||
| if (!customerId) { | ||
| return res.status(404).json({ err: "customerId is undefined" }); |
There was a problem hiding this comment.
This should be a bad request and return 400
| const customer = await stripe.customers.retrieve(customerId); | ||
| res.status(200).json({ customer, paymentMethods }); | ||
| } catch (err) { | ||
| res.status(400).json({ err: err.message }); |
| .attach(id, { | ||
| customer: customer.id, | ||
| }) | ||
| .catch((err) => res.status(404).json({ err: err.message })); |
| } else { | ||
| res.setHeader("Allow", "POST"); | ||
| res.status(405).end("Method Not Allowed"); |
There was a problem hiding this comment.
These lines are irrelevant, as long as your routes are properly created.
| const { paymentMethodId, userStripeId } = req.body; | ||
| if (!paymentMethodId || !userStripeId) { | ||
| return res | ||
| .status(404) |
|
|
||
| export const PaymentProfilesProvider: FunctionComponent = ({ children }): JSX.Element => { | ||
| const [paymentProfiles, setPaymentProfiles] = useState<IPaymentProfiles | undefined>(undefined); | ||
| const [loggedInuserDetails, setLoggedInuserDetails] = useState<IPaymentProfiles['loggedInuserDetails']>(undefined); |
There was a problem hiding this comment.
What is the purpose of the loggedInuserDetails state? Our AuthContext already has a state which holds the logged in user's information
There was a problem hiding this comment.
I used it for resetting the data stored in the context because when I log in with a different user on the same computer , the data of the previous user will be there, so I have to reset the data
There was a problem hiding this comment.
If we need the loggeInUserDetails you can get it from the AuthContext, it is not advisable to store the same data within another context as this may cause confusion.
| const { loggedInUser } = useAuth(); | ||
| const { updatePaymentProfiles, paymentProfiles, updateLoggedInUser } = usePaymentProfiles(); | ||
| const [paymentProfileExist, SetPaymentProfileExist] = useState<boolean>(false); | ||
| const [userIds, setUserIds] = useState<any>(false); |
There was a problem hiding this comment.
Please avoid using 'any' as a type
Ditto throughout!
There was a problem hiding this comment.
I will make changes but please how can I declare the data type of a promise containing an object with lots of Properties?
There was a problem hiding this comment.
You can define an interface and use it 👍🏽
Ref: https://www.tutorialsteacher.com/typescript/typescript-interface
| </Grid> | ||
| <Grid item container md={10} className={classes.gridContainer}> | ||
| <Typography variant="h6" className={classes.containerInfo}> | ||
| {paymentProfiles && 'Saved Payment Profiles:'} |
There was a problem hiding this comment.
| {paymentProfiles && 'Saved Payment Profiles:'} | |
| {paymentProfiles ? "Saved Payment Profiles:" : "You don't have any Payment Profile"} |
| paymentProfiles.map((paymentMethod: any) => ( | ||
| <Grid item xs={12} sm={12} md={6} key={paymentMethod.id}> | ||
| <Card className={classes.payCard}> | ||
| <div className={classes.cardHeader}> |
There was a problem hiding this comment.
Please use MUI Box components instead of HTML divs. A lot of the CSS properties can be passed as props to the Box component
Eg: <Box display="flex" alignItems="center".....>
Ditto throughout!
| import * as Yup from 'yup'; | ||
| import { iframeStyles } from './CardElementStyles/CardElementStyles'; | ||
|
|
||
| interface IState { |
There was a problem hiding this comment.
| interface IState { | |
| interface BillingInfo{ |
Co-authored-by: Rajiv Titus <75184965+rajivtitus@users.noreply.github.com>
rajivtitus
left a comment
There was a problem hiding this comment.
@uche-okoroafor Good work with this! Just some minor comment to address :)
|
@uche-okoroafor There are a couple of pending comments, once they are addressed please tag me in so that we can get this approved :) |
What this PR does (required):
Setup: Stripe API :
Screenshots / Videos (required):
Any information needed to test this feature (required):
Any issues with the current functionality (optional):