40

Stripe API Reference - The Session object

 3 years ago
source link: https://stripe.com/docs/api/checkout/sessions/object
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Stripe API Reference
Sessions

API Reference

The Stripe API is organized around REST. Our API has predictable resource-oriented URLs, accepts form-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.

You can use the Stripe API in test mode, which does not affect your live data or interact with the banking networks. The API key you use to authenticate the request determines whether the request is live mode or test mode.

The Stripe API differs for every account as we release new versions and tailor functionality. Log in to see docs customized to your version of the API, with your test key and data.

Subscribe to Stripe's API announce mailing list for updates.

Was this section helpful?YesNo

Just getting started?

Check out our development quickstart guide.

Not a developer?

Use apps from our partners to get started with Stripe and to do more with your Stripe account—no code required.

Base URL
https://api.stripe.com
Client libraries

By default, the Stripe API Docs demonstrate using curl to interact with the API over HTTP. Select one of our official client libraries to see examples in code.

Authentication

The Stripe API uses API keys to authenticate requests. You can view and manage your API keys in the Stripe Dashboard.

Test mode secret keys have the prefix sk_test_ and live mode secret keys have the prefix sk_live_. Alternatively, you can use restricted API keys for granular permissions.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

Authentication to the API is performed via HTTP Basic Auth. Provide your API key as the basic auth username value. You do not need to provide a password.

If you need to authenticate via bearer auth (e.g., for a cross-origin request), use -H "Authorization: Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc" instead of -u sk_test_4eC39HqLyjWDarjtT1zdp7dc.

All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

Was this section helpful?YesNo

Authenticated Request
curl https://api.stripe.com/v1/charges \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
# The colon prevents curl from asking for a password.
Your API Key

A sample test API key is included in all the examples here, so you can test any example right away.

To test requests using your account, replace the sample API key with your actual API key or sign in.

Connected Accounts

Clients can make requests as connected accounts using the special header Stripe-Account which should contain a Stripe account ID (usually starting with the prefix acct_).

See also Making API calls for connected accounts.

Was this section helpful?YesNo

Per-request account
curl https://api.stripe.com/v1/charges/ch_1I00if2eZvKYlo2C8fQqNMks \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -H "Stripe-Account: acct_1032D82eZvKYlo2C" \
  -G

Errors

Stripe uses conventional HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted, a charge failed, etc.). Codes in the 5xx range indicate an error with Stripe's servers (these are rare).

Some 4xx errors that could be handled programmatically (e.g., a card is declined) include an error code that briefly explains the error reported.

Was this section helpful?YesNo

Attributes
  • type string

    The type of error returned. One of api_connection_error, api_error, authentication_error, card_error, idempotency_error, invalid_request_error, or rate_limit_error

  • code string

    For some errors that could be handled programmatically, a short string indicating the error code reported.

  • decline_code string

    For card errors resulting from a card issuer decline, a short string indicating the card issuer’s reason for the decline if they provide one.

  • message string

    A human-readable message providing more details about the error. For card errors, these messages can be shown to your users.

  • param string

    If the error is parameter-specific, the parameter related to the error. For example, you can use this to display a message near the correct form field.

  • payment_intent hash

    The PaymentIntent object for errors returned on a request involving a PaymentIntent.

    Show child attributes
More attributesExpand all
  • charge string

  • doc_url string

  • payment_method hash

  • payment_method_type string preview feature

  • setup_intent hash

  • source hash

HTTP status code summary
200 - OKEverything worked as expected.400 - Bad RequestThe request was unacceptable, often due to missing a required parameter.401 - UnauthorizedNo valid API key provided.402 - Request FailedThe parameters were valid but the request failed.403 - ForbiddenThe API key doesn't have permissions to perform the request.404 - Not FoundThe requested resource doesn't exist.409 - ConflictThe request conflicts with another request (perhaps due to using the same idempotent key).429 - Too Many RequestsToo many requests hit the API too quickly. We recommend an exponential backoff of your requests.500, 502, 503, 504 - Server ErrorsSomething went wrong on Stripe's end. (These are rare.)
Error types
api_connection_errorFailure to connect to Stripe's API.api_errorAPI errors cover any other type of problem (e.g., a temporary problem with Stripe's servers), and are extremely uncommon.authentication_errorFailure to properly authenticate yourself in the request.card_errorCard errors are the most common type of error you should expect to handle. They result when the user enters a card that can't be charged for some reason.idempotency_errorIdempotency errors occur when an Idempotency-Key is re-used on a request that does not match the first request's API endpoint and parameters.invalid_request_errorInvalid request errors arise when your request has invalid parameters.rate_limit_errorToo many requests hit the API too quickly.validation_errorErrors triggered by our client-side libraries when failing to validate fields (e.g., when a card number or expiration date is invalid or incomplete).

Handling errors

Our Client libraries raise exceptions for many reasons, such as a failed charge, invalid parameters, authentication errors, and network unavailability. We recommend writing code that gracefully handles all possible API exceptions.

Related guide: Error Handling.

# Select a client library to see examples of handling different kinds of errors.

Expanding Responses

Many objects allow you to request additional information as an expanded response by using the expand request parameter. This parameter is available on all API requests, and applies to the response of that request only. Responses can be expanded in two ways.

In many cases, an object contains the ID of a related object in its response properties. For example, a Charge may have an associated Customer ID. Those objects can be expanded inline with the expand request parameter. ID fields that can be expanded into objects are noted in this documentation with theexpandable label.

In some cases, such as the Issuing Card object's number and cvc fields, there are available fields that are not included in responses by default. You can request these fields as an expanded response by using the expand request parameter. Fields that can be included in an expanded response are noted in this documentation with the expandable label.

You can expand recursively by specifying nested fields after a dot (.). For example, requesting invoice.subscription on a charge will expand the invoice property into a full Invoice object, and will then expand the subscription property on that invoice into a full Subscription object.

You can use the expand param on any endpoint which returns expandable fields, including list, create, and update endpoints.

Expansions on list requests start with the data property. For example, you would expand data.customers on a request to list charges and associated customers. Many deep expansions on list requests can be slow.

Expansions have a maximum depth of four levels (so for example, when listing charges,data.invoice.subscription.default_source is the deepest allowed).

You can expand multiple objects at once by identifying multiple items in the expand array.

Related Guide: Expanding responses

Was this section helpful?YesNo

Charge with expanded customer, invoice, and subscription
curl https://api.stripe.com/v1/charges/ch_1I00if2eZvKYlo2C8fQqNMks \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d "expand[]"=customer \
  -d "expand[]"="invoice.subscription" \
  -G
Response
{
  "id": "ch_1I00if2eZvKYlo2C8fQqNMks",
  "object": "charge",
  "customer": {
    "id": "cu_1I00if2eZvKYlo2CI2DQOmwX",
    "object": "customer",
    ...
  },
  "invoice": {
    "id": "in_1I00hM2eZvKYlo2C1GIAcL6k",
    "object": "invoice",
    "subscription": {
      "id": "su_1036Vs2eZvKYlo2CCWtV2RYO",
      "object": "subscription",
      ...
    },
    ...
  },
  ...
}

Idempotent Requests

The API supports idempotency for safely retrying requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response. For example, if a request to create a charge does not respond due to a network connection error, you can retry the request with the same idempotency key to guarantee that no more than one charge is created.

To perform an idempotent request, provide an additional Idempotency-Key: <key> header to the request.

Stripe's idempotency works by saving the resulting status code and body of the first request made for any given idempotency key, regardless of whether it succeeded or failed. Subsequent requests with the same key return the same result, including 500 errors.

An idempotency key is a unique value generated by the client which the server uses to recognize subsequent retries of the same request. How you create unique keys is up to you, but we suggest using V4 UUIDs, or another random string with enough entropy to avoid collisions.

Keys are eligible to be removed from the system automatically after they're at least 24 hours old, and a new request is generated if a key is reused after the original has been pruned. The idempotency layer compares incoming parameters to those of the original request and errors unless they're the same to prevent accidental misuse.

Results are only saved if an API endpoint started executing. If incoming parameters failed validation, or the request conflicted with another that was executing concurrently, no idempotent result is saved because no API endpoint began execution. It is safe to retry these requests.

All POST requests accept idempotency keys. Sending idempotency keys in GET and DELETE requests has no effect and should be avoided, as these requests are idempotent by definition.

Was this section helpful?YesNo

curl https://api.stripe.com/v1/charges \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -H "Idempotency-Key: 8r5N5muVisquDBf5" \
  -d amount=2000 \
  -d currency=usd \
  -d description="My First Test Charge (created for API docs)" \
  -d source=tok_visa

Metadata

Updateable Stripe objects—including Account, Charge, Customer, PaymentIntent, Refund, Subscription, and Transfer—have a metadata parameter. You can use this parameter to attach key-value data to these Stripe objects.

You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long.

Metadata is useful for storing additional, structured information on an object. As an example, you could store your user's full name and corresponding unique identifier from your system on a Stripe Customer object. Metadata is not used by Stripe—for example, not used to authorize or decline a charge—and won't be seen by your users unless you choose to show it to them.

Some of the objects listed above also support a description parameter. You can use the description parameter to annotate a charge—with, for example, a human-readable description like 2 shirts for [email protected]. Unlike metadata, description is a single string, and your users may see it (e.g., in email receipts Stripe sends on your behalf).

Do not store any sensitive information (bank account numbers, card details, etc.) as metadata or in the description parameter.

Was this section helpful?YesNo

Sample metadata use cases
  • Link IDs

    Attach your system's unique IDs to a Stripe object, for easy lookups. For example, add your order number to a charge, your user ID to a customer or recipient, or a unique receipt number to a transfer.

  • Refund papertrails

    Store information about why a refund was created, and by whom.

  • Customer details

    Annotate a customer by storing an internal ID for your later use.

curl https://api.stripe.com/v1/charges \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d amount=2000 \
  -d currency=usd \
  -d source=tok_visa \
  -d "metadata[order_id]"=6735
Response
{
  "id": "ch_1I00if2eZvKYlo2C8fQqNMks",
  "object": "charge",
  "amount": 100,
  "amount_captured": 0,
  "amount_refunded": 0,
  "application": null,
  "application_fee": null,
  "application_fee_amount": null,
  "balance_transaction": "txn_1032HU2eZvKYlo2CEPtcnUvl",
  "billing_details": {
    "address": {
      "city": null,
      "country": null,
      "line1": null,
      "line2": null,
      "postal_code": null,
      "state": null
    },
    "email": null,
    "name": "Jenny Rosen",
    "phone": null
  },
  "calculated_statement_descriptor": null,
  "captured": false,
  "created": 1608366197,
  "currency": "usd",
  "customer": null,
  "description": "My First Test Charge (created for API docs)",
  "disputed": false,
  "failure_code": null,
  "failure_message": null,
  "fraud_details": {},
  "invoice": null,
  "livemode": false,
  "metadata": {
    "order_id": "6735"
  },
  "on_behalf_of": null,
  "order": null,
  "outcome": null,
  "paid": true,
  "payment_intent": null,
  "payment_method": "card_19yUNL2eZvKYlo2CNGsN6EWH",
  "payment_method_details": {
    "card": {
      "brand": "visa",
      "checks": {
        "address_line1_check": null,
        "address_postal_code_check": null,
        "cvc_check": "unchecked"
      },
      "country": "US",
      "exp_month": 12,
      "exp_year": 2020,
      "fingerprint": "Xt5EWLLDS7FJjR1c",
      "funding": "credit",
      "installments": null,
      "last4": "4242",
      "network": "visa",
      "three_d_secure": null,
      "wallet": null
    },
    "type": "card"
  },
  "receipt_email": null,
  "receipt_number": null,
  "receipt_url": "https://pay.stripe.com/receipts/acct_1032D82eZvKYlo2C/ch_1I00if2eZvKYlo2C8fQqNMks/rcpt_IbD8yoODMY2qz3uVIgfIBKOjJqsAvvN",
  "refunded": false,
  "refunds": {
    "object": "list",
    "data": [],
    "has_more": false,
    "url": "/v1/charges/ch_1I00if2eZvKYlo2C8fQqNMks/refunds"
  },
  "review": null,
  "shipping": null,
  "source_transfer": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "status": "succeeded",
  "transfer_data": null,
  "transfer_group": null
}

Pagination

All top-level API resources have support for bulk fetches via "list" API methods. For instance, you can list charges, list customers, and list invoices. These list API methods share a common structure, taking at least these three parameters: limit, starting_after, and ending_before.

Stripe utilizes cursor-based pagination via the starting_after and ending_before parameters. Both parameters take an existing object ID value (see below) and return objects in reverse chronological order. The ending_before parameter returns objects listed before the named object. The starting_after parameter returns objects listed after the named object. These parameters are mutually exclusive -- only one of starting_after orending_before may be used.

Our client libraries offer auto-pagination helpers to easily traverse all pages of a list.

Was this section helpful?YesNo

Parameters
  • limit optional, default is 10

    A limit on the number of objects to be returned, between 1 and 100.

  • starting_after optional

    A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include starting_after=obj_foo in order to fetch the next page of the list.

  • ending_before optional

    A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_bar, your subsequent call can include ending_before=obj_bar in order to fetch the previous page of the list.

List Response Format
  • object string, value is "list"

    A string describing the object type returned.

  • data array

    An array containing the actual response elements, paginated by any request parameters.

  • has_more boolean

    Whether or not there are more elements available after this set. If false, this set comprises the end of the list.

  • url string

    The URL for accessing this list.

Response
{
  "object": "list",
  "url": "/v1/customers",
  "has_more": false,
  "data": [
    {
      "id": "cus_IbD8HDnQucMXtn",
      "object": "customer",
      "address": null,
      "balance": 0,
      "created": 1608366197,
      "currency": "usd",
      "default_source": null,
      "delinquent": false,
      "description": null,
      "discount": null,
      "email": null,
      "invoice_prefix": "DD62BF4",
      "invoice_settings": {
        "custom_fields": null,
        "default_payment_method": null,
        "footer": null
      },
      "livemode": false,
      "metadata": {},
      "name": null,
      "next_invoice_sequence": 1,
      "phone": null,
      "preferred_locales": [],
      "shipping": null,
      "tax_exempt": "none"
    },
    {...},
    {...}
  ]
}

Auto-pagination

Most of our libraries support auto-pagination. This feature easily handles fetching large lists of resources without having to manually paginate results and perform subsequent requests.

Since curl simply emits raw HTTP requests, it doesn't support auto-pagination.

# The auto-pagination feature is specific to Stripe's
  # libraries and cannot be used directly with curl.

Request IDs

Each API request has an associated request identifier. You can find this value in the response headers, under Request-Id. You can also find request identifiers in the URLs of individual request logs in your Dashboard. If you need to contact us about a specific request, providing the request identifier will ensure the fastest possible resolution.

Was this section helpful?YesNo

curl https://api.stripe.com/v1/customers \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -D "-" \
  -X POST

Versioning

When backwards-incompatible changes are made to the API, a new, dated version is released. The current version is 2020-08-27. Read our API upgrades guide to see our API changelog and to learn more about backwards compatibility.

All requests use your account API settings, unless you override the API version. The changelog lists every available version. Note that by default webhook events are structured according to your account API version, unless you set an API version during endpoint creation.

To set the API version on a specific request, send a Stripe-Version header.

You can visit your Dashboard to upgrade your API version. As a precaution, use API versioning to test a new API version before committing to an upgrade.

Was this section helpful?YesNo

curl https://api.stripe.com/v1/charges \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -H "Stripe-Version: 2020-08-27"

Balance

This is an object representing your Stripe balance. You can retrieve it to see the balance currently on your Stripe account…

Balance Transactions

Balance transactions represent funds moving through your Stripe account. They're created for every type of transaction that comes into or flows out of your Stripe account balance…

Charges

To charge a credit or a debit card, you create a Charge object. You can retrieve and refund individual charges as well as list all charges. Charges are identified by a unique, random ID…

Customers

Customer objects allow you to perform recurring charges, and to track multiple charges, that are associated with the same customer. The API allows you to create, delete, and update your customers. You can retrieve individual customers as well as a list of all your customers…

Disputes

A dispute occurs when a customer questions your charge with their card issuer. When this happens, you're given the opportunity to respond to the dispute with evidence that shows that the charge is legitimate. You can find more information about the dispute process in our Disputes and Fraud documentation…

Events

Events are our way of letting you know when something interesting happens in your account. When an interesting event occurs, we create a new Event object. For example, when a charge succeeds, we create a charge.succeeded event; and when an invoice payment attempt fails, we create an invoice.payment_failed event. Note that many API requests may cause multiple events to be created. For example, if you create a new subscription for a customer, you will receive both a customer.subscription.created event and a charge.succeeded event…

Files

This is an object representing a file hosted on Stripe's servers. The file may have been uploaded by yourself using the create file request (for example, when uploading dispute evidence) or it may have been created by Stripe (for example, the results of a Sigma scheduled query)…

File Links

To share the contents of a File object with non-Stripe users, you can create a FileLink. FileLinks contain a URL that can be used to retrieve the contents of the file without authentication.

Mandates

A Mandate is a record of the permission a customer has given you to debit their payment method.

PaymentIntents

A PaymentIntent guides you through the process of collecting a payment from your customer. We recommend that you create exactly one PaymentIntent for each order or customer session in your system. You can reference the PaymentIntent later to see the history of payment attempts for a particular session…

SetupIntents

A SetupIntent guides you through the process of setting up and saving a customer's payment credentials for future payments. For example, you could use a SetupIntent to set up and save your customer's card without immediately collecting a payment. Later, you can use PaymentIntents to drive the payment flow…

SetupAttempts

A SetupAttempt describes one attempted confirmation of a SetupIntent, whether that confirmation was successful or unsuccessful. You can use SetupAttempts to inspect details of a specific attempt at setting up a payment method using a SetupIntent.

Payouts

A Payout object is created when you receive funds from Stripe, or when you initiate a payout to either a bank account or debit card of a connected Stripe account. You can retrieve individual payouts, as well as list all payouts. Payouts are made on varying schedules, depending on your country and industry…

Products

Products describe the specific goods or services you offer to your customers. For example, you might offer a Standard and Premium version of your goods or service; each version would be a separate Product. They can be used in conjunction with Prices to configure pricing in Checkout and Subscriptions…

Prices

Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products. Products help you track inventory or provisioning, and prices help you track payment terms. Different physical goods or levels of service should be represented by products, and pricing options should be represented by prices. This approach lets you change prices without having to change your provisioning scheme…

Refunds

Refund objects allow you to refund a charge that has previously been created but not yet refunded. Funds will be refunded to the credit or debit card that was originally charged…

Tokens

Tokenization is the process Stripe uses to collect sensitive card or bank account details, or personally identifiable information (PII), directly from your customers in a secure manner. A token representing this information is returned to your server to use. You should use our recommended payments integrations to perform this process client-side. This ensures that no sensitive card data touches your server, and allows your integration to operate in a PCI-compliant way…

PaymentMethods

PaymentMethod objects represent your customer's payment instruments. They can be used with PaymentIntents to collect payments or saved to Customer objects to store instrument details for future payments…

Sources

Source objects allow you to accept a variety of payment methods. They represent a customer's payment instrument, and can be used with the Stripe API just like a Card object: once chargeable, they can be charged, or can be attached to customers…

Sessions

A Checkout Session represents your customer's session as they pay for one-time purchases or subscriptions through Checkout. We recommend creating a new Session each time your customer attempts to pay.

Once payment is successful, the Checkout Session will contain a reference to the Customer, and either the successful PaymentIntent or an active Subscription.

You can create a Checkout Session on your server and pass its ID to the client to begin Checkout.

Related guide: Checkout Server Quickstart.

Was this section helpful?YesNo

The Session object

Attributes
  • id string

    Unique identifier for the object. Used to pass to redirectToCheckout in Stripe.js.

  • cancel_url string

    The URL the customer will be directed to if they decide to cancel payment and return to your website.

  • client_reference_id string

    A unique string to reference the Checkout Session. This can be a customer ID, a cart ID, or similar, and can be used to reconcile the Session with your internal systems.

  • customer string

    The ID of the customer for this Session. For Checkout Sessions in payment or subscription mode, Checkout will create a new customer object based on information provided during the payment flow unless an existing customer was provided when the Session was created.

  • customer_email string

    If provided, this value will be used when the Customer object is created. If not provided, customers will be asked to enter their email address. Use this parameter to prefill customer data if you already have an email on file. To access information about the customer once the payment flow is complete, use the customer attribute.

  • line_items list expandable

    The line items purchased by the customer.

    This field is not included by default. To include it in the response, expand the line_items field.

    Show child attributes
  • metadata hash

    Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.

  • mode enum

    The mode of the Checkout Session.

    Possible enum values
    • payment

      Accept one-time payments for cards, iDEAL, and more.

    • setup

      Save payment details to charge your customers later.

    • subscription

      Use Stripe Billing to set up fixed-price subscriptions.

  • payment_intent string

    The ID of the PaymentIntent for Checkout Sessions in payment mode.

  • payment_method_types array containing strings

    A list of the types of payment methods (e.g. card) this Checkout Session is allowed to accept.

  • payment_status enum

    The payment status of the Checkout Session, one of paid, unpaid, or no_payment_required. You can use this value to decide when to fulfill your customer’s order.

    Possible enum values
    • paid

      The payment funds are available in your account.

    • unpaid

      The payment funds are not yet available in your account.

    • no_payment_required

      The Checkout Session is in setup mode and doesn’t require a payment at this time.

  • success_url string

    The URL the customer will be directed to after the payment or subscription creation is successful.

More attributesExpand all
  • object string, value is "checkout.session"

  • allow_promotion_codes boolean

  • amount_subtotal integer

  • amount_total integer

  • billing_address_collection enum

  • currency currency

  • livemode boolean

  • locale enum

  • setup_intent string

  • shipping hash

  • shipping_address_collection hash

  • submit_type enum

  • subscription string

  • total_details hash

The Session object
{
  "id": "cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo",
  "object": "checkout.session",
  "allow_promotion_codes": null,
  "amount_subtotal": null,
  "amount_total": null,
  "billing_address_collection": null,
  "cancel_url": "https://example.com/cancel",
  "client_reference_id": null,
  "currency": null,
  "customer": null,
  "customer_email": null,
  "livemode": false,
  "locale": null,
  "metadata": {},
  "mode": "payment",
  "payment_intent": "pi_1Dj5gB2eZvKYlo2CCY4yvRLi",
  "payment_method_types": [
    "card"
  ],
  "payment_status": "unpaid",
  "setup_intent": null,
  "shipping": null,
  "shipping_address_collection": null,
  "submit_type": null,
  "subscription": null,
  "success_url": "https://example.com/success",
  "total_details": null
}

Create a Session

Creates a Session object.

Parameters
  • cancel_url required

    The URL the customer will be directed to if they decide to cancel payment and return to your website.

  • mode required conditionally

    The mode of the Checkout Session. Required when using prices or setup mode. Pass subscription if the Checkout Session includes at least one recurring item.

    Possible enum values
    • payment

      Accept one-time payments for cards, iDEAL, and more.

    • setup

      Save payment details to charge your customers later.

    • subscription

      Use Stripe Billing to set up fixed-price subscriptions.

  • payment_method_types required

    A list of the types of payment methods (e.g., card) this Checkout Session can accept.

    Read more about the supported payment methods and their requirements in our payment method details guide.

    If multiple payment methods are passed, Checkout will dynamically reorder them to prioritize the most relevant payment methods based on the customer’s location and other characteristics.

    Possible enum values
    • alipay
    • card
    • ideal
    • fpx
    • bacs_debit
    • bancontact
    • giropay
    • Show 5 more
  • success_url required

    The URL to which Stripe should send customers when payment or setup is complete. If you’d like access to the Checkout Session for the successful payment, read more about it in the guide on fulfilling orders.

  • client_reference_id optional

    A unique string to reference the Checkout Session. This can be a customer ID, a cart ID, or similar, and can be used to reconcile the session with your internal systems.

  • customer optional

    ID of an existing customer, if one exists. The email stored on the customer will be used to prefill the email field on the Checkout page. If the customer changes their email on the Checkout page, the Customer object will be updated with the new email. If blank for Checkout Sessions in payment or subscription mode, Checkout will create a new customer object based on information provided during the payment flow.

  • customer_email optional

    If provided, this value will be used when the Customer object is created. If not provided, customers will be asked to enter their email address. Use this parameter to prefill customer data if you already have an email on file. To access information about the customer once a session is complete, use the customer field.

  • line_items optional array of hashes

    A list of items the customer is purchasing. Use this parameter to pass one-time or recurring Prices. One-time Prices in subscription mode will be on the initial invoice only.

    There is a maximum of 100 line items, however it is recommended to consolidate line items if there are more than a few dozen.

    Show child parameters
  • metadata optional dictionary

    Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata.

More parametersExpand all
  • allow_promotion_codes optional

  • billing_address_collection optional enum

  • discounts optional array of hashes

  • locale optional enum

  • payment_intent_data optional dictionary

  • setup_intent_data optional dictionary

  • shipping_address_collection optional dictionary

  • submit_type optional enum

  • subscription_data optional dictionary

Returns

Returns a Session object.

POST 
/v1/checkout/sessions
curl https://api.stripe.com/v1/checkout/sessions \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d success_url="https://example.com/success" \
  -d cancel_url="https://example.com/cancel" \
  -d "payment_method_types[0]"=card \
  -d "line_items[0][price]"=price_H5ggYwtDq4fbrJ \
  -d "line_items[0][quantity]"=2 \
  -d mode=payment
Response
{
  "id": "cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo",
  "object": "checkout.session",
  "allow_promotion_codes": null,
  "amount_subtotal": null,
  "amount_total": null,
  "billing_address_collection": null,
  "cancel_url": "https://example.com/cancel",
  "client_reference_id": null,
  "currency": null,
  "customer": null,
  "customer_email": null,
  "livemode": false,
  "locale": null,
  "metadata": {},
  "mode": "payment",
  "payment_intent": "pi_1Dj5gB2eZvKYlo2CCY4yvRLi",
  "payment_method_types": [
    "card"
  ],
  "payment_status": "unpaid",
  "setup_intent": null,
  "shipping": null,
  "shipping_address_collection": null,
  "submit_type": null,
  "subscription": null,
  "success_url": "https://example.com/success",
  "total_details": null,
  "line_items": [
    {
      "price": "price_H5ggYwtDq4fbrJ",
      "quantity": 2
    }
  ]
}

Retrieve a Session

Retrieves a Session object.

Parameters
  • No parameters.

Returns

Returns a Session object.

GET 
/v1/checkout/sessions/:id
curl https://api.stripe.com/v1/checkout/sessions/cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
Response
{
  "id": "cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo",
  "object": "checkout.session",
  "allow_promotion_codes": null,
  "amount_subtotal": null,
  "amount_total": null,
  "billing_address_collection": null,
  "cancel_url": "https://example.com/cancel",
  "client_reference_id": null,
  "currency": null,
  "customer": null,
  "customer_email": null,
  "livemode": false,
  "locale": null,
  "metadata": {},
  "mode": "payment",
  "payment_intent": "pi_1Dj5gB2eZvKYlo2CCY4yvRLi",
  "payment_method_types": [
    "card"
  ],
  "payment_status": "unpaid",
  "setup_intent": null,
  "shipping": null,
  "shipping_address_collection": null,
  "submit_type": null,
  "subscription": null,
  "success_url": "https://example.com/success",
  "total_details": null
}

List all Checkout Sessions

Returns a list of Checkout Sessions.

Parameters
  • payment_intent optional

    Only return the Checkout Session for the PaymentIntent specified.

  • subscription optional

    Only return the Checkout Session for the subscription specified.

More parametersExpand all
  • ending_before optional

  • limit optional

  • starting_after optional

Returns

A dictionary with a data property that contains an array of up to limit Checkout Sessions, starting after Checkout Session starting_after. Each entry in the array is a separate Checkout Session object. If no more Checkout Sessions are available, the resulting array will be empty.

GET 
/v1/checkout/sessions
curl https://api.stripe.com/v1/checkout/sessions \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d limit=3 \
  -G
Response
{
  "object": "list",
  "url": "/v1/checkout/sessions",
  "has_more": false,
  "data": [
    {
      "id": "cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo",
      "object": "checkout.session",
      "allow_promotion_codes": null,
      "amount_subtotal": null,
      "amount_total": null,
      "billing_address_collection": null,
      "cancel_url": "https://example.com/cancel",
      "client_reference_id": null,
      "currency": null,
      "customer": null,
      "customer_email": null,
      "livemode": false,
      "locale": null,
      "metadata": {},
      "mode": "payment",
      "payment_intent": "pi_1Dj5gB2eZvKYlo2CCY4yvRLi",
      "payment_method_types": [
        "card"
      ],
      "payment_status": "unpaid",
      "setup_intent": null,
      "shipping": null,
      "shipping_address_collection": null,
      "submit_type": null,
      "subscription": null,
      "success_url": "https://example.com/success",
      "total_details": null
    },
    {...},
    {...}
  ]
}

Retrieve a Checkout Session's line items

When retrieving a Checkout Session, there is an includable line_items property containing the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.

ParametersExpand all
  • ending_before optional

  • limit optional

  • starting_after optional

Returns

A dictionary with a data property that contains an array of up to limit Checkout Session line items, starting after Line Item starting_after. Each entry in the array is a separate Line Item object. If no more line items are available, the resulting array will be empty.

GET 
/v1/checkout/sessions/:id/line_items
curl https://api.stripe.com/v1/checkout/sessions/cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo/line_items?limit=5 \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
Response
{
  "object": "list",
  "url": "/v1/checkout/sessions/cs_test_Qu7Mz3T1ecvRHk3CpCt8m8m2sklCVMtEpcEQXVmcU5HrNbW2YaB1Kdzo/line_items",
  "has_more": false,
  "data": [
    {
      "id": "li_1I01Oe2eZvKYlo2CS8HKNRlt",
      "object": "item",
      "amount_subtotal": 0,
      "amount_total": 0,
      "currency": "usd",
      "description": "Camera",
      "price": {
        "id": "price_1Hzw732eZvKYlo2CyTGZq4jD",
        "object": "price",
        "active": true,
        "billing_scheme": "per_unit",
        "created": 1608348489,
        "currency": "usd",
        "livemode": false,
        "lookup_key": null,
        "metadata": {},
        "nickname": null,
        "product": "prod_Ib8NpQZ9YbpwI9",
        "recurring": null,
        "tiers_mode": null,
        "transform_quantity": null,
        "type": "one_time",
        "unit_amount": 39999,
        "unit_amount_decimal": "39999"
      },
      "quantity": 1
    },
    {...},
    {...}
  ]
}

Coupons

A coupon contains information about a percent-off or amount-off discount you might want to apply to a customer. Coupons may be applied to invoices or orders. Coupons do not work with conventional one-off charges.

Customer Balance Transaction

Each customer has a balance value, which denotes a debit or credit that's automatically applied to their next invoice upon finalization. You may modify the value directly by using the update customer API, or by creating a Customer Balance Transaction, which increments or decrements the customer's balance by the specified amount

Customer Portal

A session describes the instantiation of the customer portal for a particular customer. By visiting the session's URL, the customer can manage their subscriptions and billing details. For security reasons, sessions are short-lived and will expire if the customer does not visit the URL. Create sessions on-demand when customers intend to manage their subscriptions and billing details…

Discounts

A discount represents the actual application of a coupon to a particular customer. It contains information about when the discount began and when it will end…

Invoice Items

Sometimes you want to add a charge or credit to a customer, but actually charge or credit the customer's card only at the end of a regular billing cycle. This is useful for combining several charges (to minimize per-transaction fees), or for having Stripe tabulate your usage-based billing totals…

Plans

You can now model subscriptions more flexibly using the Prices API. It replaces the Plans API and is backwards compatible to simplify your migration…

Promotion Code

A Promotion Code represents a customer-redeemable code for a coupon. It can be used to create multiple codes for a single coupon.

Subscription Items

Subscription items allow you to create customer subscriptions with more than one plan, making it easy to represent complex billing relationships.

Usage Records

Usage records allow you to report customer usage and metrics to Stripe for metered billing of subscription prices…

Accounts

This is an object representing a Stripe account. You can retrieve it to see properties on the account like its current e-mail address or if the account is enabled yet to make live charges…

Account Links

Account Links are the means by which a Connect platform grants a connected account permission to access Stripe-hosted applications, such as Connect Onboarding…

Application Fees

When you collect a transaction fee on top of a charge made for your user (using Connect), an Application Fee object is created in your account. You can list, retrieve, and refund application fees…

Application Fee Refunds

Application Fee Refund objects allow you to refund an application fee that has previously been created but not yet refunded. Funds will be refunded to the Stripe account from which the fee was originally collected…

Country Specs

Stripe needs to collect certain pieces of information about each account created. These requirements can differ depending on the account's country. The Country Specs API makes these rules available to your integration…

Top-ups

To top up your Stripe balance, you create a top-up object. You can retrieve individual top-ups, as well as list all top-ups. Top-ups are identified by a unique, random ID…

Transfers

A Transfer object is created when you move funds between Stripe accounts as part of Connect…

Transfer Reversals

Stripe Connect platforms can reverse transfers made to a connected account, either entirely or partially, and can also specify whether to refund any related application fees. Transfer reversals add to the platform's balance and subtract from the destination account's balance…

Early Fraud Warning

An early fraud warning indicates that the card issuer has notified us that a charge may be fraudulent…

Reviews

Reviews can be used to supplement automated fraud detection with human expertise…

Transactions

Any use of an issued card that results in funds entering or leaving your Stripe account, such as a completed purchase or refund, is represented by an Issuing Transaction object…

Connection Token

A Connection Token is used by the Stripe Terminal SDK to connect to a reader…

Orders

Order objects are created to handle end customers' purchases of previously defined products. You can create, retrieve, and pay individual orders, as well as list all orders. Orders are identified by a unique, random ID…

Order Items

A representation of the constituent items of any given order. Can be used to represent SKUs, shipping costs, or taxes owed on the order…

Returns

A return represents the full or partial return of a number of order items. Returns always belong to an order, and may optionally contain a refund…

Stores representations of stock keeping units. SKUs describe specific product variations, taking into account any combination of: attributes, currency, and cost. For example, a product may be a T-shirt, whereas a specific SKU represents the size: large, color: red version of that shirt…

Scheduled Queries

If you have scheduled a Sigma query, you'll receive a sigma.scheduled_query_run.created webhook each time the query runs. The webhook contains a ScheduledQueryRun object, which you can use to retrieve the query results.

Report Runs

The Report Run object represents an instance of a report type generated with specific run parameters. Once the object is created, Stripe begins processing the report. When the report has finished running, it will give you a reference to a file where you can retrieve your results. For an overview, see API Access to Reports

Report Types

The Report Type resource corresponds to a particular type of report, such as the "Activity summary" or "Itemized payouts" reports. These objects are identified by an ID belonging to a set of enumerated values. See API Access to Reports documentation for those Report Type IDs, along with required and optional parameters…


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK