--- title: Add custom fields subtitle: Add additional fields to a prebuilt payment page with Checkout. route: /payments/checkout/custom-fields --- # Add custom fields Add additional fields to a prebuilt payment page with Checkout. You can add custom fields on the payment form to collect additional information from your customers. The information is available after the payment is complete and is useful for fulfilling the purchase. Custom fields have the following limitations: - Up to three fields allowed. - Not available in `setup` mode. - Support for up to 255 characters on text fields. - Support for up to 255 digits on numeric fields. - Support for up to 200 options on dropdown fields. Don’t use custom fields to collect personal, protected, or sensitive data, or information restricted by law. ## Create a Checkout Session Create a Checkout Session while specifying an array of [custom fields](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields). Each field must have a unique `key` that your integration uses to reconcile the field. Also provide a label for the field that you display to your customer. Labels for custom fields aren’t translated, but you can use the [locale](https://stripe.com/api/checkout/sessions/create#create_checkout_session-locale) parameter to set the language of your Checkout Session to match the same language as your labels. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ --data-urlencode success_url="https://example.com/success" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --success-url="https://example.com/success" \ --cancel-url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "success_url": "https://example.com/success", "cancel_url": "https://example.com/cancel", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ![A checkout page with custom fields](https://b.stripecdn.com/docs-statics-srv/assets/required.ba6d59544fa4519cf4eb2a1764e016cf.png) ## Retrieve custom fields When your customer completes the Checkout Session, we send a [checkout.session.completed](https://stripe.com/api/events/types#event_types-checkout.session.completed) *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) with the completed fields. Example `checkout.session.completed` payload: ```json { "id": "evt_1Ep24XHssDVaQm2PpwS19Yt0", "object": "event", "api_version": "2022-11-15", "created": 1664928000, "data": { "object": { "id": "cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k", "object": "checkout.session","custom_fields": [{ "key": "engraving", "label": { "type": "custom", "custom": "Personalized engraving" }, "optional": false, "type": "text", "text": { "value": "Jane", } }], "mode": "payment", } }, "livemode": false, "pending_webhooks": 1, "request": { "id": null, "idempotency_key": null }, "type": "checkout.session.completed" } ``` ## Use a custom field ### Mark a field as optional By default, customers must complete all fields before completing payment. To mark a field as optional, pass in `optional=true`. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ --data-urlencode success_url="https://example.com/success" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --success-url="https://example.com/success" \ --cancel-url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "optional": True, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "success_url": "https://example.com/success", "cancel_url": "https://example.com/cancel", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "optional": True, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', 'optional' => true, ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setOptional(true) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setOptional(true) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', optional: true, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Optional: stripe.Bool(true), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Optional: stripe.Bool(true), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Optional = true, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Optional = true, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ![](https://b.stripecdn.com/docs-statics-srv/assets/optional.bf0c1564296ff02264bd5e8c066a6034.png) ### Add a dropdown field A dropdown field presents your customers with a list of options to select from. To create a dropdown field, specify `type=dropdown` and a list of options, each with a `label` and a `value`. The `label` displays to the customer while your integration uses the `value` to reconcile which option the customer selected. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ --data-urlencode success_url="https://example.com/success" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=sample \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Free sample" \ -d "custom_fields[0][optional]"=true \ -d "custom_fields[0][type]"=dropdown \ -d "custom_fields[0][dropdown][options][0][label]"="Balm sample" \ -d "custom_fields[0][dropdown][options][0][value]"=balm \ -d "custom_fields[0][dropdown][options][1][label]"="BB cream sample" \ -d "custom_fields[0][dropdown][options][1][value]"=cream ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --success-url="https://example.com/success" \ --cancel-url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=sample \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Free sample" \ -d "custom_fields[0][optional]"=true \ -d "custom_fields[0][type]"=dropdown \ -d "custom_fields[0][dropdown][options][0][label]"="Balm sample" \ -d "custom_fields[0][dropdown][options][0][value]"=balm \ -d "custom_fields[0][dropdown][options][1][label]"="BB cream sample" \ -d "custom_fields[0][dropdown][options][1][value]"=cream ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'sample', label: { type: 'custom', custom: 'Free sample', }, optional: true, type: 'dropdown', dropdown: { options: [ { label: 'Balm sample', value: 'balm', }, { label: 'BB cream sample', value: 'cream', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'sample', label: { type: 'custom', custom: 'Free sample', }, optional: true, type: 'dropdown', dropdown: { options: [ { label: 'Balm sample', value: 'balm', }, { label: 'BB cream sample', value: 'cream', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "sample", "label": {"type": "custom", "custom": "Free sample"}, "optional": True, "type": "dropdown", "dropdown": { "options": [ {"label": "Balm sample", "value": "balm"}, {"label": "BB cream sample", "value": "cream"}, ], }, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "success_url": "https://example.com/success", "cancel_url": "https://example.com/cancel", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "sample", "label": {"type": "custom", "custom": "Free sample"}, "optional": True, "type": "dropdown", "dropdown": { "options": [ {"label": "Balm sample", "value": "balm"}, {"label": "BB cream sample", "value": "cream"}, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'sample', 'label' => [ 'type' => 'custom', 'custom' => 'Free sample', ], 'optional' => true, 'type' => 'dropdown', 'dropdown' => [ 'options' => [ [ 'label' => 'Balm sample', 'value' => 'balm', ], [ 'label' => 'BB cream sample', 'value' => 'cream', ], ], ], ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("sample") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Free sample") .build() ) .setOptional(true) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("Balm sample") .setValue("balm") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("BB cream sample") .setValue("cream") .build() ) .build() ) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("sample") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Free sample") .build() ) .setOptional(true) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("Balm sample") .setValue("balm") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("BB cream sample") .setValue("cream") .build() ) .build() ) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'sample', label: { type: 'custom', custom: 'Free sample', }, optional: true, type: 'dropdown', dropdown: { options: [ { label: 'Balm sample', value: 'balm', }, { label: 'BB cream sample', value: 'cream', }, ], }, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("sample"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Free sample"), }, Optional: stripe.Bool(true), Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCustomFieldDropdownParams{ Options: []*stripe.CheckoutSessionCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Label: stripe.String("Balm sample"), Value: stripe.String("balm"), }, &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Label: stripe.String("BB cream sample"), Value: stripe.String("cream"), }, }, }, }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("sample"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Free sample"), }, Optional: stripe.Bool(true), Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCreateCustomFieldDropdownParams{ Options: []*stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Label: stripe.String("Balm sample"), Value: stripe.String("balm"), }, &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Label: stripe.String("BB cream sample"), Value: stripe.String("cream"), }, }, }, }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "sample", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Free sample", }, Optional = true, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "Balm sample", Value = "balm", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "BB cream sample", Value = "cream", }, }, }, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "sample", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Free sample", }, Optional = true, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "Balm sample", Value = "balm", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "BB cream sample", Value = "cream", }, }, }, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ![A checkout page with a dropdown field](https://b.stripecdn.com/docs-statics-srv/assets/dropdown.4501d199ebe009030c2be6935cfdf2dd.png) ### Add a numbers only field A numbers-only field provides your customers a text field that only accepts numerical values, up to 255 digits. To create a numbers-only field, specify `type=numeric`. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ --data-urlencode success_url="https://example.com/success" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=invoice \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Invoice number" \ -d "custom_fields[0][type]"=numeric ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --success-url="https://example.com/success" \ --cancel-url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=invoice \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Invoice number" \ -d "custom_fields[0][type]"=numeric ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'invoice', label: { type: 'custom', custom: 'Invoice number', }, type: 'numeric', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'invoice', label: { type: 'custom', custom: 'Invoice number', }, type: 'numeric', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "invoice", "label": {"type": "custom", "custom": "Invoice number"}, "type": "numeric", }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "success_url": "https://example.com/success", "cancel_url": "https://example.com/cancel", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "invoice", "label": {"type": "custom", "custom": "Invoice number"}, "type": "numeric", }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'invoice', 'label' => [ 'type' => 'custom', 'custom' => 'Invoice number', ], 'type' => 'numeric', ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("invoice") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Invoice number") .build() ) .setType(SessionCreateParams.CustomField.Type.NUMERIC) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("invoice") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Invoice number") .build() ) .setType(SessionCreateParams.CustomField.Type.NUMERIC) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'invoice', label: { type: 'custom', custom: 'Invoice number', }, type: 'numeric', }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("invoice"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Invoice number"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeNumeric), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("invoice"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Invoice number"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeNumeric), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "invoice", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Invoice number", }, Type = "numeric", }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "invoice", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Invoice number", }, Type = "numeric", }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ### Retrieve custom fields for a subscription You can retrieve the custom fields associated with a subscription by querying for the Checkout Session that created it using the [subscription](https://stripe.com/api/checkout/sessions/list#list_checkout_sessions-subscription) parameter. Code snippet calling get /v1/checkout/sessions in curl (resource-based pattern). ```curl curl -G https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d subscription="{{SUBSCRIPTION_ID}}" ``` Code snippet calling get /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions list \ --subscription="{{SUBSCRIPTION_ID}}" ``` Code snippet calling get /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' sessions = Stripe::Checkout::Session.list({subscription: '{{SUBSCRIPTION_ID}}'}) ``` Code snippet calling get /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") sessions = client.v1.checkout.sessions.list({subscription: '{{SUBSCRIPTION_ID}}'}) ``` Code snippet calling get /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" sessions = stripe.checkout.Session.list(subscription="{{SUBSCRIPTION_ID}}") ``` Code snippet calling get /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") sessions = client.checkout.sessions.list({"subscription": "{{SUBSCRIPTION_ID}}"}) ``` Code snippet calling get /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $sessions = $stripe->checkout->sessions->all([ 'subscription' => '{{SUBSCRIPTION_ID}}', ]); ``` Code snippet calling get /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionListParams params = SessionListParams.builder().setSubscription("{{SUBSCRIPTION_ID}}").build(); SessionCollection sessions = Session.list(params); ``` Code snippet calling get /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionListParams params = SessionListParams.builder().setSubscription("{{SUBSCRIPTION_ID}}").build(); StripeCollection stripeCollection = client.checkout().sessions().list(params); ``` Code snippet calling get /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const sessions = await stripe.checkout.sessions.list({ subscription: '{{SUBSCRIPTION_ID}}', }); ``` Code snippet calling get /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionListParams{ Subscription: stripe.String("{{SUBSCRIPTION_ID}}"), }; result := session.List(params); ``` Code snippet calling get /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionListParams{ Subscription: stripe.String("{{SUBSCRIPTION_ID}}"), }; result := sc.V1CheckoutSessions.List(context.TODO(), params); ``` Code snippet calling get /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionListOptions { Subscription = "{{SUBSCRIPTION_ID}}", }; var service = new Stripe.Checkout.SessionService(); StripeList sessions = service.List(options); ``` Code snippet calling get /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionListOptions { Subscription = "{{SUBSCRIPTION_ID}}", }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; StripeList sessions = service.List(options); ``` ### Add character length validations You can optionally specify a minimum and maximum character length [requirement](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-numeric-maximum_length) for `text` and `numeric` field types. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ --data-urlencode success_url="https://example.com/success" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][minimum_length]"=10 \ -d "custom_fields[0][text][maximum_length]"=20 \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --success-url="https://example.com/success" \ --cancel-url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][minimum_length]"=10 \ -d "custom_fields[0][text][maximum_length]"=20 \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { minimum_length: 10, maximum_length: 20, }, optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { minimum_length: 10, maximum_length: 20, }, optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"minimum_length": 10, "maximum_length": 20}, "optional": True, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "success_url": "https://example.com/success", "cancel_url": "https://example.com/cancel", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"minimum_length": 10, "maximum_length": 20}, "optional": True, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', 'text' => [ 'minimum_length' => 10, 'maximum_length' => 20, ], 'optional' => true, ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder() .setMinimumLength(10L) .setMaximumLength(20L) .build() ) .setOptional(true) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder() .setMinimumLength(10L) .setMaximumLength(20L) .build() ) .setOptional(true) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { minimum_length: 10, maximum_length: 20, }, optional: true, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCustomFieldTextParams{ MinimumLength: stripe.Int64(10), MaximumLength: stripe.Int64(20), }, Optional: stripe.Bool(true), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCreateCustomFieldTextParams{ MinimumLength: stripe.Int64(10), MaximumLength: stripe.Int64(20), }, Optional: stripe.Bool(true), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { MinimumLength = 10, MaximumLength = 20, }, Optional = true, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { MinimumLength = 10, MaximumLength = 20, }, Optional = true, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ![A field with character limits](https://b.stripecdn.com/docs-statics-srv/assets/between-validation.20431cd8e0c03a028843945d1f1ea314.png) ### Add default values You can optionally provide a default value for the [text](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-text-default_value), [numeric](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-numeric-default_value), and [dropdown](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-dropdown-default_value) field types. Default values are prefilled on the payment page. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ --data-urlencode success_url="https://example.com/success" \ --data-urlencode cancel_url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][default_value]"=Stella \ -d "custom_fields[1][key]"=size \ -d "custom_fields[1][label][type]"=custom \ -d "custom_fields[1][label][custom]"=Size \ -d "custom_fields[1][type]"=dropdown \ -d "custom_fields[1][dropdown][default_value]"=small \ -d "custom_fields[1][dropdown][options][0][value]"=small \ -d "custom_fields[1][dropdown][options][0][label]"=Small \ -d "custom_fields[1][dropdown][options][1][value]"=large \ -d "custom_fields[1][dropdown][options][1][label]"=Large ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --success-url="https://example.com/success" \ --cancel-url="https://example.com/cancel" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][default_value]"=Stella \ -d "custom_fields[1][key]"=size \ -d "custom_fields[1][label][type]"=custom \ -d "custom_fields[1][label][custom]"=Size \ -d "custom_fields[1][type]"=dropdown \ -d "custom_fields[1][dropdown][default_value]"=small \ -d "custom_fields[1][dropdown][options][0][value]"=small \ -d "custom_fields[1][dropdown][options][0][label]"=Small \ -d "custom_fields[1][dropdown][options][1][value]"=large \ -d "custom_fields[1][dropdown][options][1][label]"=Large ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: {default_value: 'Stella'}, }, { key: 'size', label: { type: 'custom', custom: 'Size', }, type: 'dropdown', dropdown: { default_value: 'small', options: [ { value: 'small', label: 'Small', }, { value: 'large', label: 'Large', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: {default_value: 'Stella'}, }, { key: 'size', label: { type: 'custom', custom: 'Size', }, type: 'dropdown', dropdown: { default_value: 'small', options: [ { value: 'small', label: 'Small', }, { value: 'large', label: 'Large', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", success_url="https://example.com/success", cancel_url="https://example.com/cancel", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"default_value": "Stella"}, }, { "key": "size", "label": {"type": "custom", "custom": "Size"}, "type": "dropdown", "dropdown": { "default_value": "small", "options": [ {"value": "small", "label": "Small"}, {"value": "large", "label": "Large"}, ], }, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "success_url": "https://example.com/success", "cancel_url": "https://example.com/cancel", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"default_value": "Stella"}, }, { "key": "size", "label": {"type": "custom", "custom": "Size"}, "type": "dropdown", "dropdown": { "default_value": "small", "options": [ {"value": "small", "label": "Small"}, {"value": "large", "label": "Large"}, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', 'text' => ['default_value' => 'Stella'], ], [ 'key' => 'size', 'label' => [ 'type' => 'custom', 'custom' => 'Size', ], 'type' => 'dropdown', 'dropdown' => [ 'default_value' => 'small', 'options' => [ [ 'value' => 'small', 'label' => 'Small', ], [ 'value' => 'large', 'label' => 'Large', ], ], ], ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder().setDefaultValue("Stella").build() ) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("size") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Size") .build() ) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .setDefaultValue("small") .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("small") .setLabel("Small") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("large") .setLabel("Large") .build() ) .build() ) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setSuccessUrl("https://example.com/success") .setCancelUrl("https://example.com/cancel") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder().setDefaultValue("Stella").build() ) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("size") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Size") .build() ) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .setDefaultValue("small") .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("small") .setLabel("Small") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("large") .setLabel("Large") .build() ) .build() ) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { default_value: 'Stella', }, }, { key: 'size', label: { type: 'custom', custom: 'Size', }, type: 'dropdown', dropdown: { default_value: 'small', options: [ { value: 'small', label: 'Small', }, { value: 'large', label: 'Large', }, ], }, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCustomFieldTextParams{ DefaultValue: stripe.String("Stella"), }, }, &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("size"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Size"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCustomFieldDropdownParams{ DefaultValue: stripe.String("small"), Options: []*stripe.CheckoutSessionCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Value: stripe.String("small"), Label: stripe.String("Small"), }, &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Value: stripe.String("large"), Label: stripe.String("Large"), }, }, }, }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCreateCustomFieldTextParams{ DefaultValue: stripe.String("Stella"), }, }, &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("size"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Size"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCreateCustomFieldDropdownParams{ DefaultValue: stripe.String("small"), Options: []*stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Value: stripe.String("small"), Label: stripe.String("Small"), }, &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Value: stripe.String("large"), Label: stripe.String("Large"), }, }, }, }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { DefaultValue = "Stella", }, }, new Stripe.Checkout.SessionCustomFieldOptions { Key = "size", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Size", }, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { DefaultValue = "small", Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "small", Label = "Small", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "large", Label = "Large", }, }, }, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { DefaultValue = "Stella", }, }, new Stripe.Checkout.SessionCustomFieldOptions { Key = "size", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Size", }, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { DefaultValue = "small", Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "small", Label = "Small", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "large", Label = "Large", }, }, }, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` You can add custom fields on the payment form to collect additional information from your customers. The information is available after the payment is complete and is useful for fulfilling the purchase. Custom fields have the following limitations: - Up to three fields allowed. - Not available in `setup` mode. - Support for up to 255 characters on text fields. - Support for up to 255 digits on numeric fields. - Support for up to 200 options on dropdown fields. Don’t use custom fields to collect personal, protected, or sensitive data, or information restricted by law. ## Create a Checkout Session Create a Checkout Session while specifying an array of [custom fields](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields). Each field must have a unique `key` that your integration uses to reconcile the field. Also provide a label for the field that you display to your customer. Labels for custom fields aren’t translated, but you can use the [locale](https://stripe.com/api/checkout/sessions/create#create_checkout_session-locale) parameter to set the language of your Checkout Session to match the same language as your labels. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ -d ui_mode=embedded \ --data-urlencode return_url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --ui-mode=embedded \ --return-url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", ui_mode="embedded", return_url="https://example.com/return", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "ui_mode": "embedded", "return_url": "https://example.com/return", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'ui_mode' => 'embedded', 'return_url' => 'https://example.com/return', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ## Retrieve custom fields When your customer completes the Checkout Session, we send a [checkout.session.completed](https://stripe.com/api/events/types#event_types-checkout.session.completed) *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) with the completed fields. Example `checkout.session.completed` payload: ```json { "id": "evt_1Ep24XHssDVaQm2PpwS19Yt0", "object": "event", "api_version": "2022-11-15", "created": 1664928000, "data": { "object": { "id": "cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k", "object": "checkout.session","custom_fields": [{ "key": "engraving", "label": { "type": "custom", "custom": "Personalized engraving" }, "optional": false, "type": "text", "text": { "value": "Jane", } }], "mode": "payment", } }, "livemode": false, "pending_webhooks": 1, "request": { "id": null, "idempotency_key": null }, "type": "checkout.session.completed" } ``` ## Use a custom field ### Mark a field as optional By default, customers must complete all fields before completing payment. To mark a field as optional, pass in `optional=true`. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ -d ui_mode=embedded \ --data-urlencode return_url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --ui-mode=embedded \ --return-url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", ui_mode="embedded", return_url="https://example.com/return", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "optional": True, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "ui_mode": "embedded", "return_url": "https://example.com/return", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "optional": True, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'ui_mode' => 'embedded', 'return_url' => 'https://example.com/return', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', 'optional' => true, ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setOptional(true) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setOptional(true) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', optional: true, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Optional: stripe.Bool(true), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Optional: stripe.Bool(true), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Optional = true, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Optional = true, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ### Add a dropdown field A dropdown field presents your customers with a list of options to select from. To create a dropdown field, specify `type=dropdown` and a list of options, each with a `label` and a `value`. The `label` displays to the customer while your integration uses the `value` to reconcile which option the customer selected. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ -d ui_mode=embedded \ --data-urlencode return_url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=sample \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Free sample" \ -d "custom_fields[0][optional]"=true \ -d "custom_fields[0][type]"=dropdown \ -d "custom_fields[0][dropdown][options][0][label]"="Balm sample" \ -d "custom_fields[0][dropdown][options][0][value]"=balm \ -d "custom_fields[0][dropdown][options][1][label]"="BB cream sample" \ -d "custom_fields[0][dropdown][options][1][value]"=cream ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --ui-mode=embedded \ --return-url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=sample \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Free sample" \ -d "custom_fields[0][optional]"=true \ -d "custom_fields[0][type]"=dropdown \ -d "custom_fields[0][dropdown][options][0][label]"="Balm sample" \ -d "custom_fields[0][dropdown][options][0][value]"=balm \ -d "custom_fields[0][dropdown][options][1][label]"="BB cream sample" \ -d "custom_fields[0][dropdown][options][1][value]"=cream ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'sample', label: { type: 'custom', custom: 'Free sample', }, optional: true, type: 'dropdown', dropdown: { options: [ { label: 'Balm sample', value: 'balm', }, { label: 'BB cream sample', value: 'cream', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'sample', label: { type: 'custom', custom: 'Free sample', }, optional: true, type: 'dropdown', dropdown: { options: [ { label: 'Balm sample', value: 'balm', }, { label: 'BB cream sample', value: 'cream', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", ui_mode="embedded", return_url="https://example.com/return", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "sample", "label": {"type": "custom", "custom": "Free sample"}, "optional": True, "type": "dropdown", "dropdown": { "options": [ {"label": "Balm sample", "value": "balm"}, {"label": "BB cream sample", "value": "cream"}, ], }, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "ui_mode": "embedded", "return_url": "https://example.com/return", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "sample", "label": {"type": "custom", "custom": "Free sample"}, "optional": True, "type": "dropdown", "dropdown": { "options": [ {"label": "Balm sample", "value": "balm"}, {"label": "BB cream sample", "value": "cream"}, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'ui_mode' => 'embedded', 'return_url' => 'https://example.com/return', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'sample', 'label' => [ 'type' => 'custom', 'custom' => 'Free sample', ], 'optional' => true, 'type' => 'dropdown', 'dropdown' => [ 'options' => [ [ 'label' => 'Balm sample', 'value' => 'balm', ], [ 'label' => 'BB cream sample', 'value' => 'cream', ], ], ], ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("sample") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Free sample") .build() ) .setOptional(true) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("Balm sample") .setValue("balm") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("BB cream sample") .setValue("cream") .build() ) .build() ) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("sample") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Free sample") .build() ) .setOptional(true) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("Balm sample") .setValue("balm") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setLabel("BB cream sample") .setValue("cream") .build() ) .build() ) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'sample', label: { type: 'custom', custom: 'Free sample', }, optional: true, type: 'dropdown', dropdown: { options: [ { label: 'Balm sample', value: 'balm', }, { label: 'BB cream sample', value: 'cream', }, ], }, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("sample"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Free sample"), }, Optional: stripe.Bool(true), Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCustomFieldDropdownParams{ Options: []*stripe.CheckoutSessionCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Label: stripe.String("Balm sample"), Value: stripe.String("balm"), }, &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Label: stripe.String("BB cream sample"), Value: stripe.String("cream"), }, }, }, }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("sample"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Free sample"), }, Optional: stripe.Bool(true), Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCreateCustomFieldDropdownParams{ Options: []*stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Label: stripe.String("Balm sample"), Value: stripe.String("balm"), }, &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Label: stripe.String("BB cream sample"), Value: stripe.String("cream"), }, }, }, }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "sample", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Free sample", }, Optional = true, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "Balm sample", Value = "balm", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "BB cream sample", Value = "cream", }, }, }, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "sample", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Free sample", }, Optional = true, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "Balm sample", Value = "balm", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Label = "BB cream sample", Value = "cream", }, }, }, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ### Add a numbers only field A numbers-only field provides your customers a text field that only accepts numerical values, up to 255 digits. To create a numbers-only field, specify `type=numeric`. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ -d ui_mode=embedded \ --data-urlencode return_url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=invoice \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Invoice number" \ -d "custom_fields[0][type]"=numeric ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --ui-mode=embedded \ --return-url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=invoice \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Invoice number" \ -d "custom_fields[0][type]"=numeric ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'invoice', label: { type: 'custom', custom: 'Invoice number', }, type: 'numeric', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'invoice', label: { type: 'custom', custom: 'Invoice number', }, type: 'numeric', }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", ui_mode="embedded", return_url="https://example.com/return", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "invoice", "label": {"type": "custom", "custom": "Invoice number"}, "type": "numeric", }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "ui_mode": "embedded", "return_url": "https://example.com/return", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "invoice", "label": {"type": "custom", "custom": "Invoice number"}, "type": "numeric", }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'ui_mode' => 'embedded', 'return_url' => 'https://example.com/return', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'invoice', 'label' => [ 'type' => 'custom', 'custom' => 'Invoice number', ], 'type' => 'numeric', ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("invoice") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Invoice number") .build() ) .setType(SessionCreateParams.CustomField.Type.NUMERIC) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("invoice") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Invoice number") .build() ) .setType(SessionCreateParams.CustomField.Type.NUMERIC) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'invoice', label: { type: 'custom', custom: 'Invoice number', }, type: 'numeric', }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("invoice"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Invoice number"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeNumeric), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("invoice"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Invoice number"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeNumeric), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "invoice", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Invoice number", }, Type = "numeric", }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "invoice", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Invoice number", }, Type = "numeric", }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ### Retrieve custom fields for a subscription You can retrieve the custom fields associated with a subscription by querying for the Checkout Session that created it using the [subscription](https://stripe.com/api/checkout/sessions/list#list_checkout_sessions-subscription) parameter. Code snippet calling get /v1/checkout/sessions in curl (resource-based pattern). ```curl curl -G https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d subscription="{{SUBSCRIPTION_ID}}" ``` Code snippet calling get /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions list \ --subscription="{{SUBSCRIPTION_ID}}" ``` Code snippet calling get /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' sessions = Stripe::Checkout::Session.list({subscription: '{{SUBSCRIPTION_ID}}'}) ``` Code snippet calling get /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") sessions = client.v1.checkout.sessions.list({subscription: '{{SUBSCRIPTION_ID}}'}) ``` Code snippet calling get /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" sessions = stripe.checkout.Session.list(subscription="{{SUBSCRIPTION_ID}}") ``` Code snippet calling get /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") sessions = client.checkout.sessions.list({"subscription": "{{SUBSCRIPTION_ID}}"}) ``` Code snippet calling get /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $sessions = $stripe->checkout->sessions->all([ 'subscription' => '{{SUBSCRIPTION_ID}}', ]); ``` Code snippet calling get /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionListParams params = SessionListParams.builder().setSubscription("{{SUBSCRIPTION_ID}}").build(); SessionCollection sessions = Session.list(params); ``` Code snippet calling get /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionListParams params = SessionListParams.builder().setSubscription("{{SUBSCRIPTION_ID}}").build(); StripeCollection stripeCollection = client.checkout().sessions().list(params); ``` Code snippet calling get /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const sessions = await stripe.checkout.sessions.list({ subscription: '{{SUBSCRIPTION_ID}}', }); ``` Code snippet calling get /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionListParams{ Subscription: stripe.String("{{SUBSCRIPTION_ID}}"), }; result := session.List(params); ``` Code snippet calling get /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionListParams{ Subscription: stripe.String("{{SUBSCRIPTION_ID}}"), }; result := sc.V1CheckoutSessions.List(context.TODO(), params); ``` Code snippet calling get /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionListOptions { Subscription = "{{SUBSCRIPTION_ID}}", }; var service = new Stripe.Checkout.SessionService(); StripeList sessions = service.List(options); ``` Code snippet calling get /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionListOptions { Subscription = "{{SUBSCRIPTION_ID}}", }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; StripeList sessions = service.List(options); ``` ### Add character length validations You can optionally specify a minimum and maximum character length [requirement](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-numeric-maximum_length) for `text` and `numeric` field types. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ -d ui_mode=embedded \ --data-urlencode return_url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][minimum_length]"=10 \ -d "custom_fields[0][text][maximum_length]"=20 \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --ui-mode=embedded \ --return-url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][minimum_length]"=10 \ -d "custom_fields[0][text][maximum_length]"=20 \ -d "custom_fields[0][optional]"=true ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { minimum_length: 10, maximum_length: 20, }, optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { minimum_length: 10, maximum_length: 20, }, optional: true, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", ui_mode="embedded", return_url="https://example.com/return", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"minimum_length": 10, "maximum_length": 20}, "optional": True, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "ui_mode": "embedded", "return_url": "https://example.com/return", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"minimum_length": 10, "maximum_length": 20}, "optional": True, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'ui_mode' => 'embedded', 'return_url' => 'https://example.com/return', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', 'text' => [ 'minimum_length' => 10, 'maximum_length' => 20, ], 'optional' => true, ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder() .setMinimumLength(10L) .setMaximumLength(20L) .build() ) .setOptional(true) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder() .setMinimumLength(10L) .setMaximumLength(20L) .build() ) .setOptional(true) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { minimum_length: 10, maximum_length: 20, }, optional: true, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCustomFieldTextParams{ MinimumLength: stripe.Int64(10), MaximumLength: stripe.Int64(20), }, Optional: stripe.Bool(true), }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCreateCustomFieldTextParams{ MinimumLength: stripe.Int64(10), MaximumLength: stripe.Int64(20), }, Optional: stripe.Bool(true), }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { MinimumLength = 10, MaximumLength = 20, }, Optional = true, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { MinimumLength = 10, MaximumLength = 20, }, Optional = true, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` ### Add default values You can optionally provide a default value for the [text](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-text-default_value), [numeric](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-numeric-default_value), and [dropdown](https://stripe.com/api/checkout/sessions/create#create_checkout_session-custom_fields-dropdown-default_value) field types. Default values are prefilled on the payment page. Code snippet calling post /v1/checkout/sessions in curl (resource-based pattern). ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \ -d mode=payment \ -d ui_mode=embedded \ --data-urlencode return_url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][default_value]"=Stella \ -d "custom_fields[1][key]"=size \ -d "custom_fields[1][label][type]"=custom \ -d "custom_fields[1][label][custom]"=Size \ -d "custom_fields[1][type]"=dropdown \ -d "custom_fields[1][dropdown][default_value]"=small \ -d "custom_fields[1][dropdown][options][0][value]"=small \ -d "custom_fields[1][dropdown][options][0][label]"=Small \ -d "custom_fields[1][dropdown][options][1][value]"=large \ -d "custom_fields[1][dropdown][options][1][label]"=Large ``` Code snippet calling post /v1/checkout/sessions in cli (resource-based pattern). ```cli stripe checkout sessions create \ --mode=payment \ --ui-mode=embedded \ --return-url="https://example.com/return" \ -d "line_items[0][price]"="{{PRICE_ID}}" \ -d "line_items[0][quantity]"=1 \ -d "custom_fields[0][key]"=engraving \ -d "custom_fields[0][label][type]"=custom \ -d "custom_fields[0][label][custom]"="Personalized engraving" \ -d "custom_fields[0][type]"=text \ -d "custom_fields[0][text][default_value]"=Stella \ -d "custom_fields[1][key]"=size \ -d "custom_fields[1][label][type]"=custom \ -d "custom_fields[1][label][custom]"=Size \ -d "custom_fields[1][type]"=dropdown \ -d "custom_fields[1][dropdown][default_value]"=small \ -d "custom_fields[1][dropdown][options][0][value]"=small \ -d "custom_fields[1][dropdown][options][0][label]"=Small \ -d "custom_fields[1][dropdown][options][1][value]"=large \ -d "custom_fields[1][dropdown][options][1][label]"=Large ``` Code snippet calling post /v1/checkout/sessions in ruby (resource-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key = 'sk_test_BQokikJOvBiI2HlWgH4olfQ2' session = Stripe::Checkout::Session.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: {default_value: 'Stella'}, }, { key: 'size', label: { type: 'custom', custom: 'Size', }, type: 'dropdown', dropdown: { default_value: 'small', options: [ { value: 'small', label: 'Small', }, { value: 'large', label: 'Large', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in ruby (service-based pattern). ```ruby # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = Stripe::StripeClient.new("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.v1.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: {default_value: 'Stella'}, }, { key: 'size', label: { type: 'custom', custom: 'Size', }, type: 'dropdown', dropdown: { default_value: 'small', options: [ { value: 'small', label: 'Small', }, { value: 'large', label: 'Large', }, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in python (resource-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" session = stripe.checkout.Session.create( mode="payment", ui_mode="embedded", return_url="https://example.com/return", line_items=[{"price": "{{PRICE_ID}}", "quantity": 1}], custom_fields=[ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"default_value": "Stella"}, }, { "key": "size", "label": {"type": "custom", "custom": "Size"}, "type": "dropdown", "dropdown": { "default_value": "small", "options": [ {"value": "small", "label": "Small"}, {"value": "large", "label": "Large"}, ], }, }, ], ) ``` Code snippet calling post /v1/checkout/sessions in python (service-based pattern). ```python # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys client = StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2") session = client.checkout.sessions.create({ "mode": "payment", "ui_mode": "embedded", "return_url": "https://example.com/return", "line_items": [{"price": "{{PRICE_ID}}", "quantity": 1}], "custom_fields": [ { "key": "engraving", "label": {"type": "custom", "custom": "Personalized engraving"}, "type": "text", "text": {"default_value": "Stella"}, }, { "key": "size", "label": {"type": "custom", "custom": "Size"}, "type": "dropdown", "dropdown": { "default_value": "small", "options": [ {"value": "small", "label": "Small"}, {"value": "large", "label": "Large"}, ], }, }, ], }) ``` Code snippet calling post /v1/checkout/sessions in php (resource-based pattern). ```php // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys $stripe = new \Stripe\StripeClient('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); $session = $stripe->checkout->sessions->create([ 'mode' => 'payment', 'ui_mode' => 'embedded', 'return_url' => 'https://example.com/return', 'line_items' => [ [ 'price' => '{{PRICE_ID}}', 'quantity' => 1, ], ], 'custom_fields' => [ [ 'key' => 'engraving', 'label' => [ 'type' => 'custom', 'custom' => 'Personalized engraving', ], 'type' => 'text', 'text' => ['default_value' => 'Stella'], ], [ 'key' => 'size', 'label' => [ 'type' => 'custom', 'custom' => 'Size', ], 'type' => 'dropdown', 'dropdown' => [ 'default_value' => 'small', 'options' => [ [ 'value' => 'small', 'label' => 'Small', ], [ 'value' => 'large', 'label' => 'Large', ], ], ], ], ], ]); ``` Code snippet calling post /v1/checkout/sessions in java (resource-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder().setDefaultValue("Stella").build() ) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("size") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Size") .build() ) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .setDefaultValue("small") .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("small") .setLabel("Small") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("large") .setLabel("Large") .build() ) .build() ) .build() ) .build(); Session session = Session.create(params); ``` Code snippet calling post /v1/checkout/sessions in java (service-based pattern). ```java // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeClient client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); SessionCreateParams params = SessionCreateParams.builder() .setMode(SessionCreateParams.Mode.PAYMENT) .setUiMode(SessionCreateParams.UiMode.EMBEDDED) .setReturnUrl("https://example.com/return") .addLineItem( SessionCreateParams.LineItem.builder() .setPrice("{{PRICE_ID}}") .setQuantity(1L) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("engraving") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Personalized engraving") .build() ) .setType(SessionCreateParams.CustomField.Type.TEXT) .setText( SessionCreateParams.CustomField.Text.builder().setDefaultValue("Stella").build() ) .build() ) .addCustomField( SessionCreateParams.CustomField.builder() .setKey("size") .setLabel( SessionCreateParams.CustomField.Label.builder() .setType(SessionCreateParams.CustomField.Label.Type.CUSTOM) .setCustom("Size") .build() ) .setType(SessionCreateParams.CustomField.Type.DROPDOWN) .setDropdown( SessionCreateParams.CustomField.Dropdown.builder() .setDefaultValue("small") .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("small") .setLabel("Small") .build() ) .addOption( SessionCreateParams.CustomField.Dropdown.Option.builder() .setValue("large") .setLabel("Large") .build() ) .build() ) .build() ) .build(); Session session = client.checkout().sessions().create(params); ``` Code snippet calling post /v1/checkout/sessions in node (resource-based pattern). ```node // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'); const session = await stripe.checkout.sessions.create({ mode: 'payment', ui_mode: 'embedded', return_url: 'https://example.com/return', line_items: [ { price: '{{PRICE_ID}}', quantity: 1, }, ], custom_fields: [ { key: 'engraving', label: { type: 'custom', custom: 'Personalized engraving', }, type: 'text', text: { default_value: 'Stella', }, }, { key: 'size', label: { type: 'custom', custom: 'Size', }, type: 'dropdown', dropdown: { default_value: 'small', options: [ { value: 'small', label: 'Small', }, { value: 'large', label: 'Large', }, ], }, }, ], }); ``` Code snippet calling post /v1/checkout/sessions in go (resource-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" params := &stripe.CheckoutSessionParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCustomFieldParams{ &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCustomFieldTextParams{ DefaultValue: stripe.String("Stella"), }, }, &stripe.CheckoutSessionCustomFieldParams{ Key: stripe.String("size"), Label: &stripe.CheckoutSessionCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Size"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCustomFieldDropdownParams{ DefaultValue: stripe.String("small"), Options: []*stripe.CheckoutSessionCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Value: stripe.String("small"), Label: stripe.String("Small"), }, &stripe.CheckoutSessionCustomFieldDropdownOptionParams{ Value: stripe.String("large"), Label: stripe.String("Large"), }, }, }, }, }, }; result, err := session.New(params); ``` Code snippet calling post /v1/checkout/sessions in go (service-based pattern). ```go // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys sc := stripe.NewClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); params := &stripe.CheckoutSessionCreateParams{ Mode: stripe.String(stripe.CheckoutSessionModePayment), UIMode: stripe.String(stripe.CheckoutSessionUIModeEmbedded), ReturnURL: stripe.String("https://example.com/return"), LineItems: []*stripe.CheckoutSessionCreateLineItemParams{ &stripe.CheckoutSessionCreateLineItemParams{ Price: stripe.String("{{PRICE_ID}}"), Quantity: stripe.Int64(1), }, }, CustomFields: []*stripe.CheckoutSessionCreateCustomFieldParams{ &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("engraving"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Personalized engraving"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeText), Text: &stripe.CheckoutSessionCreateCustomFieldTextParams{ DefaultValue: stripe.String("Stella"), }, }, &stripe.CheckoutSessionCreateCustomFieldParams{ Key: stripe.String("size"), Label: &stripe.CheckoutSessionCreateCustomFieldLabelParams{ Type: stripe.String("custom"), Custom: stripe.String("Size"), }, Type: stripe.String(stripe.CheckoutSessionCustomFieldTypeDropdown), Dropdown: &stripe.CheckoutSessionCreateCustomFieldDropdownParams{ DefaultValue: stripe.String("small"), Options: []*stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Value: stripe.String("small"), Label: stripe.String("Small"), }, &stripe.CheckoutSessionCreateCustomFieldDropdownOptionParams{ Value: stripe.String("large"), Label: stripe.String("Large"), }, }, }, }, }, }; result, err := sc.V1CheckoutSessions.Create(context.TODO(), params); ``` Code snippet calling post /v1/checkout/sessions in dotnet (resource-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys StripeConfiguration.ApiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"; var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { DefaultValue = "Stella", }, }, new Stripe.Checkout.SessionCustomFieldOptions { Key = "size", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Size", }, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { DefaultValue = "small", Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "small", Label = "Small", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "large", Label = "Large", }, }, }, }, }, }; var service = new Stripe.Checkout.SessionService(); Stripe.Checkout.Session session = service.Create(options); ``` Code snippet calling post /v1/checkout/sessions in dotnet (service-based pattern). ```dotnet // Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys var options = new Stripe.Checkout.SessionCreateOptions { Mode = "payment", UiMode = "embedded", ReturnUrl = "https://example.com/return", LineItems = new List { new Stripe.Checkout.SessionLineItemOptions { Price = "{{PRICE_ID}}", Quantity = 1, }, }, CustomFields = new List { new Stripe.Checkout.SessionCustomFieldOptions { Key = "engraving", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Personalized engraving", }, Type = "text", Text = new Stripe.Checkout.SessionCustomFieldTextOptions { DefaultValue = "Stella", }, }, new Stripe.Checkout.SessionCustomFieldOptions { Key = "size", Label = new Stripe.Checkout.SessionCustomFieldLabelOptions { Type = "custom", Custom = "Size", }, Type = "dropdown", Dropdown = new Stripe.Checkout.SessionCustomFieldDropdownOptions { DefaultValue = "small", Options = new List { new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "small", Label = "Small", }, new Stripe.Checkout.SessionCustomFieldDropdownOptionOptions { Value = "large", Label = "Large", }, }, }, }, }, }; var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); var service = client.V1.Checkout.Sessions; Stripe.Checkout.Session session = service.Create(options); ``` You can’t add custom fields within the Elements but you can add any additional fields around the Elements or anywhere else on your webpage.