Customize your success page
Learn how to display a confirmation page with your customer’s order information.
You can use the details from a Checkout Session to display an order confirmation page for your customer (e.g., their name or payment amount) after the payment. To use the details from a Checkout Session:
- Modify the
success_url
to pass the Checkout Session ID to the client side. - Look up the Checkout Session using the ID on your success page.
- Use the Checkout Session to customize what’s displayed on your success page.
1 Modify the success URL Server-side
Add the {CHECKOUT_SESSION_ID}
template variable to the success_url
when you create the Checkout Session. Note that this is a literal string and must be added exactly as you see it here. Do not substitute it with a Checkout Session ID—this happens automatically after your customer pays and is redirected to the success page.
session = Stripe::Checkout::Session.create( success_url: "http://yoursite.com/order/success", success_url: "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", # other options..., )session = Stripe::Checkout::Session.create( success_url: "http://yoursite.com/order/success", success_url: "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", # other options..., )
session = stripe.checkout.Session.create( success_url="http://yoursite.com/order/success", success_url="http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", # other options..., )session = stripe.checkout.Session.create( success_url="http://yoursite.com/order/success", success_url="http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", # other options..., )
$session = $stripe->checkout->sessions->create([ 'success_url' => "http://yoursite.com/order/success", 'success_url' => "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", // other options..., ]);$session = $stripe->checkout->sessions->create([ 'success_url' => "http://yoursite.com/order/success", 'success_url' => "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", // other options..., ]);
Map<String, Object> params = new HashMap<>(); params.put( "success_url", "http://yoursite.com/order/success", "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", ); params.put( // other options... ); Session session = Session.create(params);Map<String, Object> params = new HashMap<>(); params.put( "success_url", "http://yoursite.com/order/success", "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", ); params.put( // other options... ); Session session = Session.create(params);
const session = await stripe.checkout.sessions.create({ success_url: "http://yoursite.com/order/success", success_url: "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", // other options..., });const session = await stripe.checkout.sessions.create({ success_url: "http://yoursite.com/order/success", success_url: "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", // other options..., });
params := &stripe.CheckoutSessionParams{ SuccessURL: stripe.String("http://yoursite.com/order/success"), SuccessURL: stripe.String("http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}"), // other options... ); s, _ := session.New(params)params := &stripe.CheckoutSessionParams{ SuccessURL: stripe.String("http://yoursite.com/order/success"), SuccessURL: stripe.String("http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}"), // other options... ); s, _ := session.New(params)
var options = new SessionCreateOptions { SuccessUrl = "http://yoursite.com/order/success", SuccessUrl = "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", // other options... }; var service = new SessionService(); var session = service.Create(options);var options = new SessionCreateOptions { SuccessUrl = "http://yoursite.com/order/success", SuccessUrl = "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}", // other options... }; var service = new SessionService(); var session = service.Create(options);
2 Modify your success page Server-side
Next, look up the Checkout Session using the ID and create a success page to display the order information. This example prints out the customer’s name:
# This example sets up an endpoint using the Sinatra framework. # Watch this video to get started: https://youtu.be/8aA9Enb8NVc. # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' require 'sinatra' get '/order/success' do session = Stripe::Checkout::Session.retrieve(params[:session_id]) customer = Stripe::Customer.retrieve(session.customer) "<html><body><h1>Thanks for your order, #{{customer.name}}!</h1></body></html>" end# This example sets up an endpoint using the Sinatra framework. # Watch this video to get started: https://youtu.be/8aA9Enb8NVc. # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' require 'sinatra' get '/order/success' do session = Stripe::Checkout::Session.retrieve(params[:session_id]) customer = Stripe::Customer.retrieve(session.customer) "<html><body><h1>Thanks for your order, #{{customer.name}}!</h1></body></html>" end
# This example sets up an endpoint using the Flask framework. # Watch this video to get started: https://youtu.be/7Ul1vfmsDck. import os import stripe from flask import Flask, request, render_template_string app = Flask(__name__) # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' @app.route('/order/success', methods=['GET']) def order_success(): session = stripe.checkout.Session.retrieve(request.args.get('session_id')) customer = stripe.Customer.retrieve(session.customer) return render_template_string('<html><body><h1>Thanks for your order, {{customer.name}}!</h1></body></html>') if __name__== '__main__': app.run(port=4242)# This example sets up an endpoint using the Flask framework. # Watch this video to get started: https://youtu.be/7Ul1vfmsDck. import os import stripe from flask import Flask, request, render_template_string app = Flask(__name__) # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' @app.route('/order/success', methods=['GET']) def order_success(): session = stripe.checkout.Session.retrieve(request.args.get('session_id')) customer = stripe.Customer.retrieve(session.customer) return render_template_string('<html><body><h1>Thanks for your order, {{customer.name}}!</h1></body></html>') if __name__== '__main__': app.run(port=4242)
<?php // This example sets up an endpoint using the Slim framework. // Watch this video to get started: https://youtu.be/sGcNPFX1Ph4. use Slim\Http\Request; use Slim\Http\Response; use Stripe\Stripe; require 'vendor/autoload.php'; $app = new \Slim\App; $app->add(function ($request, $response, $next) { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); return $next($request, $response); }); $app->get('/order/success', function (Request $request, Response $response) { $session = \Stripe\Checkout\Session::retrieve($request->get('session_id')); $customer = \Stripe\Customer::retrieve($session->customer); return $response->write("<html><body><h1>Thanks for your order, $customer->name!</h1></body></html>"); }); $app->run();<?php // This example sets up an endpoint using the Slim framework. // Watch this video to get started: https://youtu.be/sGcNPFX1Ph4. use Slim\Http\Request; use Slim\Http\Response; use Stripe\Stripe; require 'vendor/autoload.php'; $app = new \Slim\App; $app->add(function ($request, $response, $next) { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); return $next($request, $response); }); $app->get('/order/success', function (Request $request, Response $response) { $session = \Stripe\Checkout\Session::retrieve($request->get('session_id')); $customer = \Stripe\Customer::retrieve($session->customer); return $response->write("<html><body><h1>Thanks for your order, $customer->name!</h1></body></html>"); }); $app->run();
import static spark.Spark.get; import static spark.Spark.port; import com.stripe.Stripe; import com.stripe.model.checkout.Session; import com.stripe.model.Customer; public class Server { public static void main(String[] args) { port(4242); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; get("/order/success", (request, response) -> { Session session = Session.retrieve(request.queryParams("session_id")); Customer customer = Customer.retrieve(session.getCustomer()) return "<html><body><h1>Thanks for your order, " + customer.getName() + "!</h1></body></html>"; }); } }import static spark.Spark.get; import static spark.Spark.port; import com.stripe.Stripe; import com.stripe.model.checkout.Session; import com.stripe.model.Customer; public class Server { public static void main(String[] args) { port(4242); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; get("/order/success", (request, response) -> { Session session = Session.retrieve(request.queryParams("session_id")); Customer customer = Customer.retrieve(session.getCustomer()) return "<html><body><h1>Thanks for your order, " + customer.getName() + "!</h1></body></html>"; }); } }
// This example sets up an endpoint using the Express framework. // Watch this video to get started: https://youtu.be/rPR2aJ6XnAc. const express = require('express'); const app = express(); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); app.post('/order/success', async (req, res) => { const session = await stripe.checkout.sessions.retrieve(req.query.session_id); const customer = await stripe.customers.retrieve(session.customer); res.send(`<html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>`); }); app.listen(4242, () => console.log(`Listening on port ${4242}!`));// This example sets up an endpoint using the Express framework. // Watch this video to get started: https://youtu.be/rPR2aJ6XnAc. const express = require('express'); const app = express(); // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); app.post('/order/success', async (req, res) => { const session = await stripe.checkout.sessions.retrieve(req.query.session_id); const customer = await stripe.customers.retrieve(session.customer); res.send(`<html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>`); }); app.listen(4242, () => console.log(`Listening on port ${4242}!`));
package main import ( "net/http" "github.com/labstack/echo" "github.com/labstack/echo/middleware" "github.com/stripe/stripe-go/v71" "github.com/stripe/stripe-go/v71/customer" "github.com/stripe/stripe-go/v71/checkout/session" ) // This example sets up an endpoint using the Echo framework. // Watch this video to get started: https://youtu.be/ePmEVBu8w6Y. func main() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover()) e.GET("/order/success", orderSuccess) e.Logger.Fatal(e.Start("localhost:4242")) } func orderSuccess(c echo.Context) (err error) { s, _ := session.Get(c.QueryParam("session_id"), nil) cus, _ := customer.Get(s.Customer.ID, nil) return c.String(http.StatusOK, "<html><body><h1>Thanks for your order, " + cus.Name + "!</h1></body></html>") }package main import ( "net/http" "github.com/labstack/echo" "github.com/labstack/echo/middleware" "github.com/stripe/stripe-go/v71" "github.com/stripe/stripe-go/v71/customer" "github.com/stripe/stripe-go/v71/checkout/session" ) // This example sets up an endpoint using the Echo framework. // Watch this video to get started: https://youtu.be/ePmEVBu8w6Y. func main() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover()) e.GET("/order/success", orderSuccess) e.Logger.Fatal(e.Start("localhost:4242")) } func orderSuccess(c echo.Context) (err error) { s, _ := session.Get(c.QueryParam("session_id"), nil) cus, _ := customer.Get(s.Customer.ID, nil) return c.String(http.StatusOK, "<html><body><h1>Thanks for your order, " + cus.Name + "!</h1></body></html>") }
// This example sets up an endpoint using the ASP.NET MVC framework. // Watch this video to get started: https://youtu.be/2-mMOB8MhmE. using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Stripe; using Stripe.Checkout; namespace server.Controllers { public class SuccessController : Controller { public SuccessController() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; } [HttpGet("/order/success")] public ActionResult OrderSuccess([FromQuery] string session_id) { var sessionService = new SessionService(); Session session = sessionService.Get(session_id); var customerService = new CustomerService(); Customer customer = customerService.Get(session.CustomerId); return Content($"<html><body><h1>Thanks for your order, {customer.Name}!</h1></body></html>"); } } }// This example sets up an endpoint using the ASP.NET MVC framework. // Watch this video to get started: https://youtu.be/2-mMOB8MhmE. using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Stripe; using Stripe.Checkout; namespace server.Controllers { public class SuccessController : Controller { public SuccessController() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; } [HttpGet("/order/success")] public ActionResult OrderSuccess([FromQuery] string session_id) { var sessionService = new SessionService(); Session session = sessionService.Get(session_id); var customerService = new CustomerService(); Customer customer = customerService.Get(session.CustomerId); return Content($"<html><body><h1>Thanks for your order, {customer.Name}!</h1></body></html>"); } } }
3 Test it out
Follow these steps:
- Click your checkout button.
- Fill the customer name in as “Jenny Rosen.”
- Fill out the remaining payment details.
- Click Pay.
You should be redirected to your success page, and see Thanks for your order, Jenny Rosen!