#ubi
1 messages · Page 1 of 1 (latest)
Hi there
I can not use the Checkout/Payment Link/[Anything self-hosted] btw. I tried that and my CTO asked me to remove it
If you want to confirm on your server then you want to follow our guide here: https://stripe.com/docs/payments/finalize-payments-on-the-server
I have that so far, but when you click in that Submit I need to collect the info and send it to my backend
Okay so what is happening right now?
Is there an error?
Are you fetching your backend when that button is clicked?
Well, first, should I remove the payment intent client secret?
the link you shared isn't using that, which I rather not do it because technically the Price can change over time
You can either pick to do full-payment or payment plan (subscription)
Yeah you wouldn't pass the client secret to your frontend if you want to confirm from your server
right right, I was a bit lost because the amount thingy changes over time ...
somebody/docs else recommended me to create the payment intent as soon as possible but it is adding more problems than the one that solve
I also would like to avoid creating ghost payment intent due to the user clicking awway and coming back as well
anyway, let me fix that first
Sounds good, try changing to the above and let me know after that
return (
<Elements
stripe={stripePromise}
options={{
mode: 'payment',
amount: 1099,
paymentMethodTypes: ['card'],
currency: 'usd',
setupFutureUsage: 'off_session',
appearance: {},
paymentMethodCreation: 'manual',
// passing the client secret obtained from the server
// clientSecret: data.client_secret,
}}
>
{props.children}
</Elements>
);
Did that so far!
with
<PaymentElement />
<AddressElement options={{ mode: 'billing' }} onChange={onAddressChange} />
So the only thing to note is that if you are supporting both one-time and Sub payments here then you will want to re-render your Elements component if they swap between those two options
step two
const handleSubmit = async (event: any) => {
event.preventDefault();
if (!stripe || !elements) {
return;
}
const { error: submitError } = await elements.submit();
if (submitError) {
handleError(submitError);
return;
}
// https://stripe.com/docs/radar/radar-session
const { error, paymentMethod } = await stripe.createPaymentMethod({
elements,
});
if (error) {
handleError(error);
return;
}
console.log(paymentMethod);
const res = await fetch('http://localhost:44000/api/stripe/create-confirm-intent', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
paymentMethodId: paymentMethod.id,
address: address,
}),
});
const data = await res.json();
handleServerResponse(data);
};
So that the correct Payment Method types show
I am moving into the backend portion now!
Just to clarify, I am not using your subscription stuff, I am doing it in my side
So I have to implement that, being said, yes, I can swap stuff based on whatever state
alright, I think I am getting it now, so now in the backend I need to create and confirm the payment intent
is that correct?
Yep correct
looking at the example code in the backend
app.post('/create-confirm-intent', async (req, res) => {
try {
const intent = await stripe.paymentIntents.create({
confirm: true,
amount: 1099,
currency: 'usd',
automatic_payment_methods: {enabled: true},
payment_method: req.body.paymentMethodId, // the PaymentMethod ID sent by your client
return_url: 'https://example.com/order/123/complete',
use_stripe_sdk: true,
mandate_data: {
customer_acceptance: {
type: "online",
online: {
ip_address: req.ip,
user_agent: req.get("user-agent"),
},
},
},
});
res.json({
client_secret: intent.client_secret,
status: intent.status
});
} catch (err) {
res.json({
error: err
})
}
});
ahhh never mind! the trick is the confirm: true
LOL
ignore me!
👍
Why should I expose that client_secret in the response btw?
Like someone reloading the page and paying again?
right, or whatever double-click happen by mistake
Well you want to disable your buy button on click
So that you don't have any issue there in terms of double click
If you want to prevent duplicate payments from same customer in terms of reloading the page then there are several ways to go about it but my advice would be to use a session/cookie
Right, just using an extreme example
what do you mean by session/cookie?
like save an ID for the session that you were type of thing?
Not following
I am familiar with the cookie but I am not sure what do you want me to do with it honestly
Well you would check on that customers actions
And you can check within Stripe if they have already purchased
The other thing you can do is use something like email to check if they have already purchased
There are a variety of ways to go about preventing duplicates and all depends on how you want to handle
I like the email idea, do you have a link about it?
Not really. You would basically want to collect the customer's email and then associate it to a Stripe object (like a Customer potentially or you could use the billing details of a PaymentMethod) and then check whether that object is associated with any past payments based on the email
How could I attach taxes information to the payment intent?
Should I use https://stripe.com/docs/radar/radar-session or pass the following manually myself
mandate_data: %{
customer_acceptance: %{
type: "online",
online: %{
ip_address: ,
user_agent: "..."
}
}
}
Is this related to the tax question or is it a new question?
about radar session
passing the radar session to my backend, I am doing it already
but the example code isnt working for off-session btw
nevermind ... it suppose to be in the backend
const { error, paymentMethod } = await stripe.createPaymentMethod({
elements,
params: {
radar_options: {
session: '{{RADAR_SESSION_ID}}',
},
},
});
that wouldn't work in the client, but I am not sure how I should do it then, I am calling that function in my FrontEnd before sending the payment info