#carasco6170_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1265273044520407072
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi! well you can create the Customer later, like when you submit the form on your frontend, you can create the Customer and Subscription at that point, and then send back the client_secret of the Invoice's PaymentIntent.
Sorry, it's a bit hard to follow without a lot more detail about what code you're using, which guides you're reading, etc.
I am doing sth like this on fronted:
const createPaymentMutation = useMutation({
mutationFn: (payload) => createStrpiePayment(payload),
onSuccess: ({ data }) => {
// setClientSecret(() => data.clientSecret);
},
});
const options = {
clientSecret: clientSecret,
locale: lang,
appearance: {
theme: 'flat',
variables: {
borderRadius: '10px',
fontSizeBase: '12px',
},
rules: {
'.Input': {
borderRadius: '10px',
padding: '8px',
fontSize: '14px',
},
'.Tab': {
padding: '8px',
},
'.Label': {
fontSize: '12px',
},
},
},
};
useEffect(() => {
if (plan.stripe_product_id) {
const payload = {
userId: user._id,
priceId: plan.stripe_product_id,
};
createPaymentMutation.mutate(payload);
}
}, []);
if (!clientSecret) {
return <Loading />;
}
return (
<>
<Elements stripe={stripePromise} options={options}>
<StrpiePaymentViewTest />
</Elements>
</>
);
and i am using: <PaymentElement />
on backend i am createing an customer and creating subscribtion:
const stripeCustomer = await stripe.customers.create({
email: customer.email,
});
const subscription = await stripe.subscriptions.create({
customer: customer.user_stripe_id,
items: [
{
price: createPaymentDTO.priceId,
},
],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
});
where can i find a guid to add and customer later? i am looking on this: https://docs.stripe.com/billing/quickstart
and to confirm payment sth like this:
const stripe = useStripe();
const elements = useElements();
const handleSubmit = async (e) => {
e.preventDefault();
if (!stripe || !elements) {
return;
}
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: `https://${window.location.host}/success-payment`,
},
});
};
o i found it i used this: https://docs.stripe.com/payments/payment-element
you might want to use https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription instead.
in that flow you don't need the clientSecret immediately, so you can wait until after the PaymentElement has completed.