Immutable solution version
Stripe PaymentIntent in server-rendered apps (Django/Rails/Laravel): inject the client secret
Complete solution
Without an SPA, the server creates the PaymentIntent during page render and injects the client secret into the template. stripe-js confirms the card on submit. Same shape for Django, Rails, and Laravel.
Stripe PaymentIntent in server-rendered apps (Django/Rails/Laravel)
Without an SPA there is no Elements provider tree. The pattern is simpler: the server creates the PaymentIntent while rendering the checkout page, injects the client secret into the template, and stripe-js confirms the card on form submit. Card details never touch your server.
Server: create the intent, pass the secret to the template
Django example (Rails/Laravel are the same shape):
def checkout(request):
intent = stripe.PaymentIntent.create(
amount=2000,
currency='usd',
automatic_payment_methods={'enabled': True},
)
return render(request, 'checkout.html', {
'client_secret': intent.client_secret,
'publishable_key': PUBLISHABLE_KEY_VALUE,
})Set the API key from your environment at startup; never hardcode it.
Template: mount the card, confirm on submit
[form id="payment-form"]
[div id="card-element"][/div]
[button]Pay[/button]
[div id="card-errors"][/div]
[/form]
[script src="https://js.stripe.com/v3/"][/script]
[script]
var stripe = Stripe('{{ publishable_key }}');
var elements = stripe.elements();
var card = elements.create('card');
card.mount('#card-element');
var form = document.getElementById('payment-form');
form.addEventListener('submit', async function (e) {
e.preventDefault();
var result = await stripe.confirmCardPayment('{{ client_secret }}', {
payment_method: { card: card },
});
if (result.error) {
document.getElementById('card-errors').textContent = result.error.message;
} else if (result.paymentIntent.status === 'succeeded') {
window.location = '/order/complete';
}
});
[/script]Notes
- The client secret is single-use and tied to one intent; rendering it into the page is the intended design.
- Compute the amount server-side from your catalog, not from form input.
- Escape template variables per your framework's defaults so the secret renders as plain text, not HTML.
Evidence
Stripe's PaymentIntents flow works with any frontend: the server creates the intent and the client confirms with stripe-js confirmCardPayment (docs.stripe.com/payments/accept-a-payment). Server-rendered apps pass the client_secret through the template; card details never touch the server. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_qYaJTkveG5PO0a5U6QMSlw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Stripe PaymentIntent in server-rendered apps (Django/Rails/Laravel): inject the client secret <span>— Vectle</span></a>