#dante-3ds
1 messages · Page 1 of 1 (latest)
@untold cargo hi! I think it would depend on how exactly you've integrated things. Do you have an example of a PaymentIntent pi_xxx where the payment didn't go through? And ideally the exact frontend code you're using?
hi @little yew on my bckend this is whezre I create my paymentIntent and my subscription :
const paymentIntent = await stripe.paymentIntents.create({
customer: customer.id,
payment_method,
amount: product.productPrice,
currency: 'eur',
// payment_method_types: ['card'],
metadata: {
name,
email,
product: product.productName,
},
automatic_payment_methods: {
enabled: true,
},
})
// const { status, client_secret } = paymentIntent
const paymentIntentStatus = paymentIntent.status
const paymentIntentClientSecret = paymentIntent.client_secret
console.log('paymentIntent', paymentIntent)
const discount =
model.nguidCodeDiscountRate === '0'
? []
: `rate${model.nguidCodeDiscountRate}`
try {
console.log('inside the productIsSubscription and the try statement')
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: stripePriceElement }],
coupon: discount,
expand: ['latest_invoice.payment_intent'],
trial_period_days: trialDays,
})
console.log('subscription', subscription)
console.log('subscription.latest_invoice.payment_intent', subscription.latest_invoice.payment_intent)
const { status, client_secret } = subscription
const subscriptionStatus = subscription.status;
const subscriptionClientSecret= subscription.client_secret;
on my client i have the following:
const handleSubscription = async (event) => {
event.preventDefault();
if (!stripe || !elements) {
return;
}
if (error) {
// @ts-ignore
elements.getElement('card').focus();
return;
}
if (cardComplete) {
setProcessing(true);
}
const payload = await stripe.createPaymentMethod({
type: 'card',
// @ts-ignore
card: elements.getElement(CardElement),
billing_details: billingDetails,
});
if (payload.error) {
// @ts-ignore
setError(payload.error.message);
} else {
const res = await axios.post(
`${process.env.REACT_APP_BACKEND}/users/payment`,
{
// @ts-ignore
payment_method: payload.paymentMethod.id,
name: billingDetails.name,
email: billingDetails.email,
product: product,
model: model,
},
token
);
if (res.data.error == 'subscription_payment_intent_requires_action') {
setError(res.data.error);
setSuccess(false);
}
const { client_secret, status, intent_secret, intent_status } = res.data;
if (intent_status == "requires_confirmation") {
stripe.confirmCardPayment(intent_secret).then((result) => {
if (result.error) {
setError(result.error);
setSuccess(false);
}
});
}
if (status == "requires_action") {
stripe.confirmCardPayment(client_secret).then((result) => {
if (result.error) {
// @ts-ignore
setError(result.error);
setSuccess(false);
}
});
}
if (status || intent_status == 'succeeded') {
setSuccess(true);
}
if (status == "payment failed"){
setSuccess(false);
setStripeError(`${status}`);
}
}
setProcessing(false);
};
hmm your backend code doesn't make sense to me really
why do you create a PaymentIntent and a Subscription? You'd generally just create a Subscription, and then you use the PaymentIntent returned by it (subscription.latest_invoice.payment_intent)
I was afraid of that. at the beginning we combined things and ended up mixing stuff.
if you're using a trial period though there won't be a PaymentIntent, at least
I would like to to create :
- a subscription
- for some customers subscriptions though would have a coupon attached to them 10 eur reduction
- for some customers subscription will have a trial period of 1year
any chance you can use Checkout instead of manually creating Subscriptions + Elements?
just because it's a lot easier to implement
I'm actually opting for that now, I'm rebuilding the whole thing using Checkout, but
is this the right documentation : https://stripe.com/docs/billing/quickstart
yep!
thanks, let me try to to implement that. do you think this is possible with the checkout?
- a subscription
- for some customers subscriptions though would have a coupon attached to them 10 eur reduction
- for some customers subscription will have a trial period of 1year after the will have a subscription with 10eur deducted
yes :
- yep
- https://stripe.com/docs/billing/subscriptions/coupons#using-coupons-in-checkout to set the coupon in your backend logic when creating the Session , or you can even use promo codes https://stripe.com/docs/billing/subscriptions/coupons/codes#adding-promotion-codes-to-checkout
- https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-trial_end