Skip to content

Commit

Permalink
stripe integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Anushkajoshii committed Jul 24, 2024
1 parent 0048004 commit 0cc0d51
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .env example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//used for frontend

REACT_APP_STRIPE_PUBLISHABLE_KEY= stripe publishable key
REACT_APP_BACKEND_URL= backend local host url
3 changes: 3 additions & 0 deletions server/.env example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//used by server.js for backend

STRIPE_SECRET_KEY= stripe secret key
9 changes: 7 additions & 2 deletions src/Pages/pay/pay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import axios from 'axios';
import CheckoutForm from './CheckoutForm';
import './pay.scss';


// Initialize Stripe with your publishable key
const stripePromise = loadStripe("pk_test_51OZeOJSHKQ5UtevikLLJG3vvyhNe2XwePgVfDVvW1aalKTW1yhPJyiEg50tZJ9xldsoauRrhEfAjpdzritmEGAQ100wKhUGSSq");
const stripePromise = loadStripe(process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY);
// or use this statement, paste publisable key here
// const stripePromise = loadStripe("paste key here");

const Pay = () => {
const [clientSecret, setClientSecret] = useState("");
Expand All @@ -15,7 +18,9 @@ const Pay = () => {
useEffect(() => {
const makeRequest = async () => {
try {
const backendUrl = 'http://localhost:8801';
const backendUrl = process.env.REACT_APP_BACKEND_URL;
//or use this statement, paste backend url
// const backendUrl = 'paste backend url';
const response = await axios.post(`${backendUrl}/create-payment-intent`, { amount });
setClientSecret(response.data.clientSecret);
} catch (err) {
Expand Down

0 comments on commit 0cc0d51

Please sign in to comment.