From a4701596c1878e12e7c61b53a8226fa1eabaf2fb Mon Sep 17 00:00:00 2001 From: Dimitar Nizamov Date: Fri, 30 Dec 2022 16:33:16 +0100 Subject: [PATCH] Stripe elements components for getting the users payment details (#1269) * 1267 - add elements and init the payment element * 1267 - add Appearance to the Elements object to match the MUI Theme * 1267 - add a seperate component for the stripe form * 1267 - remove the call fro mthe PaymentElement component * 1267 - rename PaymentElement * 1267 - style payment element to be more in line with the current inputs * 1267 - comment out the PaymentElement init * 1267 - remove personal public key * 1267 - remove e2e dependency files * 1267 - remove personal pk from the env folder --- .env.local.example | 4 ++ README.md | 1 - package.json | 2 + .../stripe/PaymentDetailsStripeForm.tsx | 66 +++++++++++++++++++ src/components/modal/DetailsModal.tsx | 1 - .../one-time-donation/OneTimeDonationPage.tsx | 18 ++++- src/pages/campaigns/donation/[slug].tsx | 2 +- src/service/apiEndpoints.ts | 1 + src/service/donation.ts | 13 ++++ yarn.lock | 22 +++++++ 10 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 src/components/donations/stripe/PaymentDetailsStripeForm.tsx diff --git a/.env.local.example b/.env.local.example index 632decde9..8ec1a117f 100644 --- a/.env.local.example +++ b/.env.local.example @@ -30,6 +30,10 @@ NEXTAUTH_SECRET=super-dev-secret GOOGLE_ID= GOOGLE_SECRET= +## Stripe ## +############## +STRIPE_PUBLIC_KEY= + ## Paypal ## ############## # using 'sb' as sandbox. no need to put real sandbox key if you don't plan to test requests with backend webhooks diff --git a/README.md b/README.md index 33abfb218..02b7ef04a 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,6 @@ Watch releases of this repository to be notified about future updates: ![Peek 2022-12-23 11-19](https://user-images.githubusercontent.com/893608/209308853-ddb8dfe8-1c42-4c18-be9c-4d55f8599d73.gif) - ## Contributors ✨ diff --git a/package.json b/package.json index a2e8921db..5d07672ea 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "@paypal/react-paypal-js": "^7.8.1", "@react-pdf/renderer": "^3.0.1", "@sentry/nextjs": "7.21.1", + "@stripe/react-stripe-js": "^1.16.1", + "@stripe/stripe-js": "^1.46.0", "@tanstack/react-query": "^4.16.1", "@tryghost/content-api": "^1.11.4", "axios": "0.21.4", diff --git a/src/components/donations/stripe/PaymentDetailsStripeForm.tsx b/src/components/donations/stripe/PaymentDetailsStripeForm.tsx new file mode 100644 index 000000000..ce9310288 --- /dev/null +++ b/src/components/donations/stripe/PaymentDetailsStripeForm.tsx @@ -0,0 +1,66 @@ +import getConfig from 'next/config' +import { Appearance, loadStripe } from '@stripe/stripe-js' +import { Elements, PaymentElement } from '@stripe/react-stripe-js' + +import theme from 'common/theme' +import { Box, BoxProps } from '@mui/material' +const { + publicRuntimeConfig: { STRIPE_PUBLIC_KEY }, +} = getConfig() + +const appearance: Appearance = { + theme: 'stripe', + variables: { + colorPrimary: theme.palette.primary.main, + colorBackground: theme.palette.background.paper, + colorText: theme.palette.text.primary, + colorDanger: theme.palette.error.main, + fontFamily: "Montserrat, 'Helvetica Neue', Helvetica, Arial, sans-serif", + fontSizeSm: theme.typography.pxToRem(12), + fontSizeBase: theme.typography.pxToRem(16), + fontSizeLg: theme.typography.pxToRem(18), + fontSizeXl: theme.typography.pxToRem(20), + spacingUnit: theme.spacing(0), + borderRadius: theme.borders.round, + focusBoxShadow: 'none', + focusOutline: `2px solid ${theme.palette.primary.main}`, + }, + rules: { + '.Input': { + boxShadow: 'none', + border: `1px solid ${theme.palette.grey[300]}`, + }, + '.Input:focus': { + border: 'none', + boxShadow: 'none', + }, + }, +} + +const stripePromise = loadStripe(STRIPE_PUBLIC_KEY) + +export type PaymentDetailsStripeFormProps = { + clientSecret: string + containerProps?: BoxProps +} +export default function PaymentDetailsStripeForm({ + clientSecret, + containerProps, +}: PaymentDetailsStripeFormProps) { + // const mutation = useCreatePaymentIntent({ amount: 100, currency: Currencies.BGN }) + // useEffect(() => { + // mutation.mutate() + // }, []) + return ( + + + + + + ) +} diff --git a/src/components/modal/DetailsModal.tsx b/src/components/modal/DetailsModal.tsx index 3fb3b7252..987538dbb 100644 --- a/src/components/modal/DetailsModal.tsx +++ b/src/components/modal/DetailsModal.tsx @@ -90,7 +90,6 @@ function DetailsModal() { ))} - {/* */}