#kenny_code
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/1361720035659350016
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- kenny_code, 4 hours ago, 74 messages
const session = await stripe.checkout.sessions.create({
ui_mode: "custom",
line_items: [
{
price: formData.price,
quantity: formData.quantity,
},
],
mode: formData.mode,
return_url: `${BASE_URL}${href("/:orgSlug?")}?session_id={CHECKOUT_SESSION_ID}`,
automatic_tax: { enabled: false },
customer: orgExt.customerId,
saved_payment_method_options: {
allow_redisplay_filters: ['always', 'limited'],
},
});
that's the full session object
it renders like this even though I have an active payment method
That's Checkout not Payment Element
So that uses a different flow from customer session
I'm afraid that I don't understand
The doc you linked is for the payment element
You are not using the payment element
Not based on the code you shared
You are using Checkout Sessions
the checkout sessions with the payment element
function CheckoutForm({
amountTotal,
amountSubtotal,
}: {
amountTotal: number;
amountSubtotal: number;
}) {
const checkout = useCheckout();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [viewMode, setViewMode] = useState<string | null>(null);
const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<
string | undefined
>();
console.log('checkout.savedPaymentMethods', checkout.savedPaymentMethods)
const displayAmount = new Intl.NumberFormat("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(amountTotal / 100);
async function handleSubmit(event: FormEvent) {
event.preventDefault();
setIsLoading(true);
const res = await checkout.confirm();
if (res.type === "error") {
setError(res.error.message);
}
};
return (
<form onSubmit={handleSubmit} className="m-auto">
<PaymentElement options={{ layout: "tabs" }} />
<button type="submit" disabled={isLoading}>submit</button>
</form>
);
}
...
return (
<CheckoutProvider
stripe={stripePromise}
options={{
fetchClientSecret: async () => clientSecret,
elementsOptions: {
fonts: [
{ cssSrc: "https://fonts.googleapis.com/css?family=Inter" },
],
appearance: {
theme: "night",
variables: {
fontFamily: "Inter",
colorPrimary: "white",
colorBackground: "#09090B",
colorText: "white",
},
},
},
}}
>
<CheckoutForm amountTotal={amountTotal} amountSubtotal={amountSubtotal} />
</CheckoutProvider>
);
I don't think Elements with Checkout Sessions supports Customer Sessions and redisplaying saved payment methods
AFAIK it's only regular Payment Element integrations that support it
Confirming with a colleague though
gotcha so if that were the case would I need to do the advanced integration with payment intents & customer sessions?
I believe so
Still waiting for confirmation from my colleague if there's a way around this with Elements + Checkout Sessions
appreciate it
Ok: https://docs.stripe.com/payments/online-payments#compare-features
3 We’re actively working on supporting this feature and expect to launch in 2025.```
So it's actively being worked on
But not possible yet
gotcha, not possible for the payment element entirely?
Not possible with Checkout Sessions + Payment Element
If only doing Payment Intent + Payment Element it is possible
does that method allow me to charge based on a subscription price
I guess I don't understand how payment intent works. Would I just be showing them a button and then issuing the payment when they click it directly?
idk how to put my thoughts into words
basically what's the difference between payment intents and a checkout session
Hi hi! I’m going to be taking over for my colleague here. Can you please summarize where things are at for me, and what issue(s) is/are blocking you?
Yeah for sure. I am trying to get payment methods for my checkout session payment element but I learned that it's not supported yet so I am looking into alternatives.
from this link I notice this line of code:
const intent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
// In the latest version of the API, specifying the `automatic_payment_methods` parameter
// is optional because Stripe enables its functionality by default.
automatic_payment_methods: {enabled: true},
customer: {{CUSTOMER_ID}},
});
but this is manually specifying an amount. I need to be able to put a price in not an amount it also needs to be a subscription
Can we take a step back and can you explain to me what you're trying to accomplish exactly?
Or rather, what is the "why" behind what you're trying to do?
I have a flow where my customers have payment methods. When they want to subscribe or top up I need them to be able to select which payment method they would like to use (if available) or to enter new card details pretty much to continue with the payment
kind of like how amazon works with payments
Can you share the request ID from your dashboard for the Checkout Session? Or the Checkout Session ID?
I can but I don't know why that would help considering that @brittle granite confirmed that this isn't supported by checkout sessions yet
cs_test_a1NMZXHiTwTHEO3UbTgJnl4Qjg6HcDWrjhQJT3wcZmfTo7600bkrTaE0ST
Cool, so you're good then?
no because he said it was possible with payment intents
which is why I asked this
I think this is what you're looking for? https://docs.stripe.com/payments/existing-customers?platform=web&ui=elements#display-additional-saved-payment-methods
this doesn't answer my question about the price though
like price id
const intent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
// In the latest version of the API, specifying the `automatic_payment_methods` parameter
// is optional because Stripe enables its functionality by default.
automatic_payment_methods: {enabled: true},
customer: {{CUSTOMER_ID}},
});
as you can see it's manually selecitng the amount
i have 0 idea how i could possibly translate this into setting up a subscription for my price let's say price_1RCs4uCWRQ9TqHkCexlKFdcp
When they want to subscribe or top up
Tell me more about what this means in terms of your application, and also why an existing Customer would want to 'subscribe' (since I presume they arlready were subscribed)?
because we have multiple subscription packages that are not mutually exclusive to one another
The only part of this that actually requires a Stripe frontend component is the "enter new card details" part; the rest could all be done with your own UI.
Tell me more about "top up"s.
right, and I tried to make my own UI for this as well but checkout.savedPaymentMethods outputs null
You wouldn't use Checkout Sessions if you did it yourself. You can list a Customers' payment methods like this server-side https://docs.stripe.com/api/payment_methods/customer_list and then render that client-side.
You need to think about this like the two distinct steps it is:
- Pick the costs-money activity (top-up, new subscription item, whatever);
- Select the payment method you want to use (or add a new one)
From that perspective, it's a lot easier to execute on. How are they/the app selecting the 'costs-money' actions?
Okay I see what you mean but without a checkout session how would I charge a user and set up a new subscription?
First please tell me more about what 'top ups' mean for you.
one time payments. But those are easy and I can just use standard payments intents. I'm more interested in figuring out the more complex subscriptions.
Ok, so a top-up from Stripe's perspective is just a regular 'charge', rather than a Subscription needing creating, and whatever's getting 'topped up' is managed wholly outside of Stripe, ya?
Yes that’s correct
But my users can select multiple add on subscriptions which is why I need payment methods to be saved so they don’t have to re-input every time
Right, ok.
Have you seen this? https://docs.stripe.com/billing/subscriptions/usage-based