Class: Stripe::Checkout::Session

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/checkout/session.rb

Overview

A Checkout Session represents your customer’s session as they pay for one-time purchases or subscriptions through [Checkout](stripe.com/docs/payments/checkout) or [Payment Links](stripe.com/docs/payments/payment-links). 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](stripe.com/docs/api/customers), and either the successful [PaymentIntent](stripe.com/docs/api/payment_intents) or an active [Subscription](stripe.com/docs/api/subscriptions).

You can create a Checkout Session on your server and redirect to its URL to begin Checkout.

Related guide: [Checkout quickstart](stripe.com/docs/checkout/quickstart)

Defined Under Namespace

Classes: AdaptivePricing, AfterExpiration, AutomaticTax, CollectedInformation, Consent, ConsentCollection, CreateParams, CurrencyConversion, CustomField, CustomText, CustomerDetails, Discount, ExpireParams, InvoiceCreation, ListLineItemsParams, ListParams, PaymentMethodConfigurationDetails, PaymentMethodOptions, Permissions, PhoneNumberCollection, RetrieveParams, SavedPaymentMethodOptions, ShippingAddressCollection, ShippingCost, ShippingDetails, ShippingOption, TaxIdCollection, TotalDetails, UpdateParams

Constant Summary collapse

OBJECT_NAME =
"checkout.session"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #save

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#adaptive_pricingObject (readonly)

Settings for price localization with [Adaptive Pricing](docs.stripe.com/payments/checkout/adaptive-pricing).



3584
3585
3586
# File 'lib/stripe/resources/checkout/session.rb', line 3584

def adaptive_pricing
  @adaptive_pricing
end

#after_expirationObject (readonly)

When set, provides configuration for actions to take if this Checkout Session expires.



3586
3587
3588
# File 'lib/stripe/resources/checkout/session.rb', line 3586

def after_expiration
  @after_expiration
end

#allow_promotion_codesObject (readonly)

Enables user redeemable promotion codes.



3588
3589
3590
# File 'lib/stripe/resources/checkout/session.rb', line 3588

def allow_promotion_codes
  @allow_promotion_codes
end

#amount_subtotalObject (readonly)

Total of all items before discounts or taxes are applied.



3590
3591
3592
# File 'lib/stripe/resources/checkout/session.rb', line 3590

def amount_subtotal
  @amount_subtotal
end

#amount_totalObject (readonly)

Total of all items after discounts and taxes are applied.



3592
3593
3594
# File 'lib/stripe/resources/checkout/session.rb', line 3592

def amount_total
  @amount_total
end

#automatic_taxObject (readonly)

Attribute for field automatic_tax



3594
3595
3596
# File 'lib/stripe/resources/checkout/session.rb', line 3594

def automatic_tax
  @automatic_tax
end

#billing_address_collectionObject (readonly)

Describes whether Checkout should collect the customer’s billing address. Defaults to ‘auto`.



3596
3597
3598
# File 'lib/stripe/resources/checkout/session.rb', line 3596

def billing_address_collection
  @billing_address_collection
end

#cancel_urlObject (readonly)

If set, Checkout displays a back button and customers will be directed to this URL if they decide to cancel payment and return to your website.



3598
3599
3600
# File 'lib/stripe/resources/checkout/session.rb', line 3598

def cancel_url
  @cancel_url
end

#client_reference_idObject (readonly)

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.



3602
3603
3604
# File 'lib/stripe/resources/checkout/session.rb', line 3602

def client_reference_id
  @client_reference_id
end

#client_secretObject (readonly)

The client secret of the Session. Use this with [initCheckout](stripe.com/docs/js/custom_checkout/init) on your front end.



3604
3605
3606
# File 'lib/stripe/resources/checkout/session.rb', line 3604

def client_secret
  @client_secret
end

#collected_informationObject (readonly)

Information about the customer collected within the Checkout Session.



3606
3607
3608
# File 'lib/stripe/resources/checkout/session.rb', line 3606

def collected_information
  @collected_information
end

Results of ‘consent_collection` for this session.



3608
3609
3610
# File 'lib/stripe/resources/checkout/session.rb', line 3608

def consent
  @consent
end

When set, provides configuration for the Checkout Session to gather active consent from customers.



3610
3611
3612
# File 'lib/stripe/resources/checkout/session.rb', line 3610

def consent_collection
  @consent_collection
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



3612
3613
3614
# File 'lib/stripe/resources/checkout/session.rb', line 3612

def created
  @created
end

#currencyObject (readonly)

Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](stripe.com/docs/currencies).



3614
3615
3616
# File 'lib/stripe/resources/checkout/session.rb', line 3614

def currency
  @currency
end

#currency_conversionObject (readonly)

Currency conversion details for [Adaptive Pricing](docs.stripe.com/payments/checkout/adaptive-pricing) sessions



3616
3617
3618
# File 'lib/stripe/resources/checkout/session.rb', line 3616

def currency_conversion
  @currency_conversion
end

#custom_fieldsObject (readonly)

Collect additional information from your customer using custom fields. Up to 3 fields are supported.



3618
3619
3620
# File 'lib/stripe/resources/checkout/session.rb', line 3618

def custom_fields
  @custom_fields
end

#custom_textObject (readonly)

Attribute for field custom_text



3620
3621
3622
# File 'lib/stripe/resources/checkout/session.rb', line 3620

def custom_text
  @custom_text
end

#customerObject (readonly)

The ID of the customer for this Session. For Checkout Sessions in ‘subscription` mode or Checkout Sessions with `customer_creation` set as `always` in `payment` 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.



3626
3627
3628
# File 'lib/stripe/resources/checkout/session.rb', line 3626

def customer
  @customer
end

#customer_creationObject (readonly)

Configure whether a Checkout Session creates a Customer when the Checkout Session completes.



3628
3629
3630
# File 'lib/stripe/resources/checkout/session.rb', line 3628

def customer_creation
  @customer_creation
end

#customer_detailsObject (readonly)

The customer details including the customer’s tax exempt status and the customer’s tax IDs. Customer’s address details are not present on Sessions in ‘setup` mode.



3630
3631
3632
# File 'lib/stripe/resources/checkout/session.rb', line 3630

def customer_details
  @customer_details
end

#customer_emailObject (readonly)

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.



3636
3637
3638
# File 'lib/stripe/resources/checkout/session.rb', line 3636

def customer_email
  @customer_email
end

#discountsObject (readonly)

List of coupons and promotion codes attached to the Checkout Session.



3638
3639
3640
# File 'lib/stripe/resources/checkout/session.rb', line 3638

def discounts
  @discounts
end

#expires_atObject (readonly)

The timestamp at which the Checkout Session will expire.



3640
3641
3642
# File 'lib/stripe/resources/checkout/session.rb', line 3640

def expires_at
  @expires_at
end

#idObject (readonly)

Unique identifier for the object.



3642
3643
3644
# File 'lib/stripe/resources/checkout/session.rb', line 3642

def id
  @id
end

#invoiceObject (readonly)

ID of the invoice created by the Checkout Session, if it exists.



3644
3645
3646
# File 'lib/stripe/resources/checkout/session.rb', line 3644

def invoice
  @invoice
end

#invoice_creationObject (readonly)

Details on the state of invoice creation for the Checkout Session.



3646
3647
3648
# File 'lib/stripe/resources/checkout/session.rb', line 3646

def invoice_creation
  @invoice_creation
end

#line_itemsObject (readonly)

The line items purchased by the customer.



3648
3649
3650
# File 'lib/stripe/resources/checkout/session.rb', line 3648

def line_items
  @line_items
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



3650
3651
3652
# File 'lib/stripe/resources/checkout/session.rb', line 3650

def livemode
  @livemode
end

#localeObject (readonly)

The IETF language tag of the locale Checkout is displayed in. If blank or ‘auto`, the browser’s locale is used.



3652
3653
3654
# File 'lib/stripe/resources/checkout/session.rb', line 3652

def locale
  @locale
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



3654
3655
3656
# File 'lib/stripe/resources/checkout/session.rb', line 3654

def 
  @metadata
end

#modeObject (readonly)

The mode of the Checkout Session.



3656
3657
3658
# File 'lib/stripe/resources/checkout/session.rb', line 3656

def mode
  @mode
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



3658
3659
3660
# File 'lib/stripe/resources/checkout/session.rb', line 3658

def object
  @object
end

#payment_intentObject (readonly)

The ID of the PaymentIntent for Checkout Sessions in ‘payment` mode. You can’t confirm or cancel the PaymentIntent for a Checkout Session. To cancel, [expire the Checkout Session](stripe.com/docs/api/checkout/sessions/expire) instead.



3660
3661
3662
# File 'lib/stripe/resources/checkout/session.rb', line 3660

def payment_intent
  @payment_intent
end

The ID of the Payment Link that created this Session.



3662
3663
3664
# File 'lib/stripe/resources/checkout/session.rb', line 3662

def payment_link
  @payment_link
end

#payment_method_collectionObject (readonly)

Configure whether a Checkout Session should collect a payment method. Defaults to ‘always`.



3664
3665
3666
# File 'lib/stripe/resources/checkout/session.rb', line 3664

def payment_method_collection
  @payment_method_collection
end

#payment_method_configuration_detailsObject (readonly)

Information about the payment method configuration used for this Checkout session if using dynamic payment methods.



3666
3667
3668
# File 'lib/stripe/resources/checkout/session.rb', line 3666

def payment_method_configuration_details
  @payment_method_configuration_details
end

#payment_method_optionsObject (readonly)

Payment-method-specific configuration for the PaymentIntent or SetupIntent of this CheckoutSession.



3668
3669
3670
# File 'lib/stripe/resources/checkout/session.rb', line 3668

def payment_method_options
  @payment_method_options
end

#payment_method_typesObject (readonly)

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



3671
3672
3673
# File 'lib/stripe/resources/checkout/session.rb', line 3671

def payment_method_types
  @payment_method_types
end

#payment_statusObject (readonly)

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.



3674
3675
3676
# File 'lib/stripe/resources/checkout/session.rb', line 3674

def payment_status
  @payment_status
end

#permissionsObject (readonly)

This property is used to set up permissions for various actions (e.g., update) on the CheckoutSession object.

For specific permissions, please refer to their dedicated subsections, such as ‘permissions.update.shipping_details`.



3678
3679
3680
# File 'lib/stripe/resources/checkout/session.rb', line 3678

def permissions
  @permissions
end

#phone_number_collectionObject (readonly)

Attribute for field phone_number_collection



3680
3681
3682
# File 'lib/stripe/resources/checkout/session.rb', line 3680

def phone_number_collection
  @phone_number_collection
end

#recovered_fromObject (readonly)

The ID of the original expired Checkout Session that triggered the recovery flow.



3682
3683
3684
# File 'lib/stripe/resources/checkout/session.rb', line 3682

def recovered_from
  @recovered_from
end

#redirect_on_completionObject (readonly)

This parameter applies to ‘ui_mode: embedded`. Learn more about the [redirect behavior](stripe.com/docs/payments/checkout/custom-success-page?payment-ui=embedded-form) of embedded sessions. Defaults to `always`.



3684
3685
3686
# File 'lib/stripe/resources/checkout/session.rb', line 3684

def redirect_on_completion
  @redirect_on_completion
end

#return_urlObject (readonly)

Applies to Checkout Sessions with ‘ui_mode: embedded` or `ui_mode: custom`. The URL to redirect your customer back to after they authenticate or cancel their payment on the payment method’s app or site.



3686
3687
3688
# File 'lib/stripe/resources/checkout/session.rb', line 3686

def return_url
  @return_url
end

#saved_payment_method_optionsObject (readonly)

Controls saved payment method settings for the session. Only available in ‘payment` and `subscription` mode.



3688
3689
3690
# File 'lib/stripe/resources/checkout/session.rb', line 3688

def saved_payment_method_options
  @saved_payment_method_options
end

#setup_intentObject (readonly)

The ID of the SetupIntent for Checkout Sessions in ‘setup` mode. You can’t confirm or cancel the SetupIntent for a Checkout Session. To cancel, [expire the Checkout Session](stripe.com/docs/api/checkout/sessions/expire) instead.



3690
3691
3692
# File 'lib/stripe/resources/checkout/session.rb', line 3690

def setup_intent
  @setup_intent
end

#shipping_address_collectionObject (readonly)

When set, provides configuration for Checkout to collect a shipping address from a customer.



3692
3693
3694
# File 'lib/stripe/resources/checkout/session.rb', line 3692

def shipping_address_collection
  @shipping_address_collection
end

#shipping_costObject (readonly)

The details of the customer cost of shipping, including the customer chosen ShippingRate.



3694
3695
3696
# File 'lib/stripe/resources/checkout/session.rb', line 3694

def shipping_cost
  @shipping_cost
end

#shipping_detailsObject (readonly)

Shipping information for this Checkout Session.



3696
3697
3698
# File 'lib/stripe/resources/checkout/session.rb', line 3696

def shipping_details
  @shipping_details
end

#shipping_optionsObject (readonly)

The shipping rate options applied to this Session.



3698
3699
3700
# File 'lib/stripe/resources/checkout/session.rb', line 3698

def shipping_options
  @shipping_options
end

#statusObject (readonly)

The status of the Checkout Session, one of ‘open`, `complete`, or `expired`.



3700
3701
3702
# File 'lib/stripe/resources/checkout/session.rb', line 3700

def status
  @status
end

#submit_typeObject (readonly)

Describes the type of transaction being performed by Checkout in order to customize relevant text on the page, such as the submit button. ‘submit_type` can only be specified on Checkout Sessions in `payment` mode. If blank or `auto`, `pay` is used.



3704
3705
3706
# File 'lib/stripe/resources/checkout/session.rb', line 3704

def submit_type
  @submit_type
end

#subscriptionObject (readonly)

The ID of the subscription for Checkout Sessions in ‘subscription` mode.



3706
3707
3708
# File 'lib/stripe/resources/checkout/session.rb', line 3706

def subscription
  @subscription
end

#success_urlObject (readonly)

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



3709
3710
3711
# File 'lib/stripe/resources/checkout/session.rb', line 3709

def success_url
  @success_url
end

#tax_id_collectionObject (readonly)

Attribute for field tax_id_collection



3711
3712
3713
# File 'lib/stripe/resources/checkout/session.rb', line 3711

def tax_id_collection
  @tax_id_collection
end

#total_detailsObject (readonly)

Tax and discount details for the computed total amount.



3713
3714
3715
# File 'lib/stripe/resources/checkout/session.rb', line 3713

def total_details
  @total_details
end

#ui_modeObject (readonly)

The UI mode of the Session. Defaults to ‘hosted`.



3715
3716
3717
# File 'lib/stripe/resources/checkout/session.rb', line 3715

def ui_mode
  @ui_mode
end

#urlObject (readonly)

The URL to the Checkout Session. Redirect customers to this URL to take them to Checkout. If you’re using [Custom Domains](stripe.com/docs/payments/checkout/custom-domains), the URL will use your subdomain. Otherwise, it’ll use ‘checkout.stripe.com.` This value is only present when the session is active.



3718
3719
3720
# File 'lib/stripe/resources/checkout/session.rb', line 3718

def url
  @url
end

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

Creates a Session object.



3721
3722
3723
3724
3725
3726
3727
3728
# File 'lib/stripe/resources/checkout/session.rb', line 3721

def self.create(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: "/v1/checkout/sessions",
    params: params,
    opts: opts
  )
end

.expire(session, params = {}, opts = {}) ⇒ Object

A Session can be expired when it is in one of these statuses: open

After it expires, a customer can’t complete a Session and customers loading the Session see a message saying the Session is expired.



3745
3746
3747
3748
3749
3750
3751
3752
# File 'lib/stripe/resources/checkout/session.rb', line 3745

def self.expire(session, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/checkout/sessions/%<session>s/expire", { session: CGI.escape(session) }),
    params: params,
    opts: opts
  )
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of Checkout Sessions.



3755
3756
3757
3758
3759
3760
3761
3762
# File 'lib/stripe/resources/checkout/session.rb', line 3755

def self.list(params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: "/v1/checkout/sessions",
    params: params,
    opts: opts
  )
end

.list_line_items(session, params = {}, opts = {}) ⇒ Object

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.



3775
3776
3777
3778
3779
3780
3781
3782
# File 'lib/stripe/resources/checkout/session.rb', line 3775

def self.list_line_items(session, params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/checkout/sessions/%<session>s/line_items", { session: CGI.escape(session) }),
    params: params,
    opts: opts
  )
end

.object_nameObject



26
27
28
# File 'lib/stripe/resources/checkout/session.rb', line 26

def self.object_name
  "checkout.session"
end

.update(session, params = {}, opts = {}) ⇒ Object

Updates a Session object.



3785
3786
3787
3788
3789
3790
3791
3792
# File 'lib/stripe/resources/checkout/session.rb', line 3785

def self.update(session, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/checkout/sessions/%<session>s", { session: CGI.escape(session) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

#expire(params = {}, opts = {}) ⇒ Object

A Session can be expired when it is in one of these statuses: open

After it expires, a customer can’t complete a Session and customers loading the Session see a message saying the Session is expired.



3733
3734
3735
3736
3737
3738
3739
3740
# File 'lib/stripe/resources/checkout/session.rb', line 3733

def expire(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/checkout/sessions/%<session>s/expire", { session: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

#list_line_items(params = {}, opts = {}) ⇒ Object

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.



3765
3766
3767
3768
3769
3770
3771
3772
# File 'lib/stripe/resources/checkout/session.rb', line 3765

def list_line_items(params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: format("/v1/checkout/sessions/%<session>s/line_items", { session: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end