#phillip_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/1333724376448634920
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
This is part of my handleSubmit function.
Would I need to do something like (if paymentMethod === 'payPal') await stripe.confirmPayPalPayment?
const { error, setupIntent } = await stripe.value!.confirmSetup({
// @ts-ignore
elements: elements.value,
// @ts-ignore
redirect: 'if_required'
})
// @ts-ignore
const paymentMethod = setupIntent?.payment_method || null
if (error) throw createError(error)
await updateCustomer(customer.value, address.value);
await stripeAttachPaymentMethod(paymentMethod, customer.value);
if (!useStripe().basicProduct.value.price?.id || !useStripe().adBudgetProduct.value.price?.id) {
throw createError('Stripe products have not been initialized')
}
const promotionCode = useState<Stripe.PromotionCode>('stripePromotionCode')
const [basicSubscription] = await Promise.all([
// basic subscription
createSubscription(
customer.value,
useStripe().basicProduct.value.price!,
paymentMethod,
promotionCode.value?.coupon?.id
),
// ad budget subscription
createSubscription(
customer.value,
useStripe().adBudgetProduct.value.price!,
paymentMethod,
undefined,
false
)
])
Hi @wheat python , there is no request ID because I haven't implemented the code yet
I'd like to understand better how I can implement PayPal to my existing payment method flow
as you can see here https://docs.stripe.com/payments/paypal/accept-a-payment?web-or-mobile=web&payments-ui-type=direct-api#confirm-paypal-payment you need to pass the return_url param to indicate where Stripe should redirect your customer to after they complete the payment.
Yes โ but where would I need to add stripe.confirmPayPalPayment in my existing flow?
- question: Do I have to determine what payment method the user chose and do something like this?
Something like (if paymentMethod === 'paypal') {
stripe.confirmPayPalPayment(...)
} else if (paymentMethod === 'card') {
// same flow as before
}
Or would I need to do that here somewhere?
const { error, setupIntent } = await stripe.value!.confirmSetup({
// @ts-ignore
elements: elements.value,
// @ts-ignore
redirect: 'if_required'
})
- question: How to retrieve the
payment_intent_client_secret?
I don't have a Payment Intent object or at least I don't know what is meant by that.
Can I use the client_secret from the setupIntent instead?
const { client_secret: clientSecretFromSetupIntent } = await $fetch<Stripe.SetupIntent>('/api/create-stripe-setup-intent', {
method: 'post',
body: {
customerId: customer.value?.id
}
})
actually you don't need to
if you're already using the PaymentElement and using stripe.confirmPayment or stripe.confirmSetup this should be enough regardless of the type of the payment method
Okay, that would be great! But I was getting the error that the redirect_url is missing and I don't know where to pass it.
I just found out confirmSetup has confirmParams which includes return_url โ is this what is being used by PayPal?
So can I simply pass it there?
const { error, setupIntent } = await stripe.value!.confirmSetup({
// @ts-ignore
elements: elements.value,
// @ts-ignore
redirect: 'if_required',
confirmParams: {
return_url: 'https://someurl-in-my-app.com'
}
})
yes that's one way of doing it
another way is just to add the return_url when creating the SetupIntent in the backend
Thanks a lot @wheat python , I'll try it out ๐