#Daniel M.-react
1 messages · Page 1 of 1 (latest)
I need to store the client secret as the payment ID in the data base
since the client secret is created at the root level of my app, wrapping my routes, i dont want to drop down the client secret as a prop through 20 components
are you talking about the client_secret of the PaymentIntent
yes
const options = {
clientSecret,
appearance
};
return (
<>
{clientSecret && (
<Elements options={options} stripe={stripePromise}>
{children}
</Elements>
)}
</>
);
that one
ok why do you need it in the children components?
so, I´m creating a pdf file as a product which is stored on our database. I need to link that file stored on the database with a payment, which is represented by the client secret because its unique isnt it?
and that backend request to store it on the database happens way down in the children components
and way down there I´d need the client secret again, BEFORE the redirect, where the client secret is send in the url after payment
i could also safe it in the redux store, but I don´t know if that´s so clever
are you create a Payment Intent? instead of storing the client_secret maybe it's better to store the id of the Payment Intent
how do i get the id?
sure that works as well, never heard that that there was a payment id haha
always thought "client secret" was stripes fance name for payment id
const stripe = require("stripe")(
"sk_test_51KyzygLkVu8CqnKeeX0TbSexsPog29cBPLUekig88CVaR4wn947OOYA4VM7TxMOAZqP4zH94t6utEQIz3fPBiisq00FKsowi5x"
);
exports.createNewIntent = async (req, res) => {
const intent = await paymentIntent;
res.send(intent);
};
const paymentIntent = stripe.paymentIntents.create({
amount: process.env.AUDIT_PRICE,
currency: "eur",
automatic_payment_methods: {
enabled: true,
},
});
how would i get a payment id from here?
just let me ask you a few questions to better understand your use case and provide you with the best solution that fits your needs
sure
const mongoose = require('mongoose');
const OrderSchema = mongoose.Schema({
timestamp: {
type: String,
required: true,
},
paymentId: {
type: String,
required: true,
},
paymentStatus: {
type: String,
required: true,
},
filename: {
type: String,
require: true,
},
fileHash: {
type: String,
required: true,
},
method: {
type: String,
required: true,
},
});
i need to fill in all these fields when clicking on the pay now button
<form
className="payment-form"
id="payment-form"
onSubmit={(e) => handleSubmit(e)}>
<PaymentElement id="payment-element" />
<button
className="checkout-button"
disabled={isLoading || !stripe || !elements}
id="submit">
<span id="button-text">
{isLoading ? <div className="spinner" id="spinner"></div> : 'Pay now'}
</span>
</button>
{/* Show any error or success messages */}
{message && <div id="payment-message">{message}</div>}
</form>
```so in that handleSubmit(e) event, i need to put a backend request via axios, where I send all that data which you can see in the schema definition of the mongodb
axios
.post(process.env.REACT_APP_SERVER_API + '/payment/cash',
formData, ... <------ STRIPE PAYMENT ID HERE)
.then((res) => {
console.log(res);
setOrderHash(res.data);
})
.catch((err) => console.log('something went wrong'));
});