Class: Stripe::SetupIntent

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

Overview

A SetupIntent guides you through the process of setting up and saving a customer’s payment credentials for future payments. For example, you can use a SetupIntent to set up and save your customer’s card without immediately collecting a payment. Later, you can use [PaymentIntents](stripe.com/docs/api#payment_intents) to drive the payment flow.

Create a SetupIntent when you’re ready to collect your customer’s payment credentials. Don’t maintain long-lived, unconfirmed SetupIntents because they might not be valid. The SetupIntent transitions through multiple [statuses](docs.stripe.com/payments/intents#intent-statuses) as it guides you through the setup process.

Successful SetupIntents result in payment credentials that are optimized for future payments. For example, cardholders in [certain regions](stripe.com/guides/strong-customer-authentication) might need to be run through [Strong Customer Authentication](docs.stripe.com/strong-customer-authentication) during payment method collection to streamline later [off-session payments](docs.stripe.com/payments/setup-intents). If you use the SetupIntent with a [Customer](stripe.com/docs/api#setup_intent_object-customer), it automatically attaches the resulting payment method to that Customer after successful setup. We recommend using SetupIntents or [setup_future_usage](stripe.com/docs/api#payment_intent_object-setup_future_usage) on PaymentIntents to save payment methods to prevent saving invalid or unoptimized payment methods.

By using SetupIntents, you can reduce friction for your customers, even as regulations change over time.

Related guide: [Setup Intents API](docs.stripe.com/payments/setup-intents)

Defined Under Namespace

Classes: AutomaticPaymentMethods, CancelParams, ConfirmParams, CreateParams, LastSetupError, ListParams, NextAction, PaymentMethodConfigurationDetails, PaymentMethodOptions, UpdateParams, VerifyMicrodepositsParams

Constant Summary collapse

OBJECT_NAME =
"setup_intent"

Constants inherited from StripeObject

Stripe::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

#==, #[], #[]=, #_get_inner_class_type, 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

#applicationObject (readonly)

ID of the Connect application that created the SetupIntent.



4605
4606
4607
# File 'lib/stripe/resources/setup_intent.rb', line 4605

def application
  @application
end

#attach_to_selfObject (readonly)

If present, the SetupIntent’s payment method will be attached to the in-context Stripe Account.

It can only be used for this Stripe Account’s own money movement flows like InboundTransfer and OutboundTransfers. It cannot be set to true when setting up a PaymentMethod for a Customer, and defaults to false when attaching a PaymentMethod to a Customer.



4609
4610
4611
# File 'lib/stripe/resources/setup_intent.rb', line 4609

def attach_to_self
  @attach_to_self
end

#automatic_payment_methodsObject (readonly)

Settings for dynamic payment methods compatible with this Setup Intent



4611
4612
4613
# File 'lib/stripe/resources/setup_intent.rb', line 4611

def automatic_payment_methods
  @automatic_payment_methods
end

#cancellation_reasonObject (readonly)

Reason for cancellation of this SetupIntent, one of ‘abandoned`, `requested_by_customer`, or `duplicate`.



4613
4614
4615
# File 'lib/stripe/resources/setup_intent.rb', line 4613

def cancellation_reason
  @cancellation_reason
end

#client_secretObject (readonly)

The client secret of this SetupIntent. Used for client-side retrieval using a publishable key.

The client secret can be used to complete payment setup from your frontend. It should not be stored, logged, or exposed to anyone other than the customer. Make sure that you have TLS enabled on any page that includes the client secret.



4617
4618
4619
# File 'lib/stripe/resources/setup_intent.rb', line 4617

def client_secret
  @client_secret
end

#createdObject (readonly)

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



4619
4620
4621
# File 'lib/stripe/resources/setup_intent.rb', line 4619

def created
  @created
end

#customerObject (readonly)

ID of the Customer this SetupIntent belongs to, if one exists.

If present, the SetupIntent’s payment method will be attached to the Customer on successful setup. Payment methods attached to other Customers cannot be used with this SetupIntent.



4623
4624
4625
# File 'lib/stripe/resources/setup_intent.rb', line 4623

def customer
  @customer
end

#customer_accountObject (readonly)

ID of the Account this SetupIntent belongs to, if one exists.

If present, the SetupIntent’s payment method will be attached to the Account on successful setup. Payment methods attached to other Accounts cannot be used with this SetupIntent.



4627
4628
4629
# File 'lib/stripe/resources/setup_intent.rb', line 4627

def 
  @customer_account
end

#descriptionObject (readonly)

An arbitrary string attached to the object. Often useful for displaying to users.



4629
4630
4631
# File 'lib/stripe/resources/setup_intent.rb', line 4629

def description
  @description
end

#flow_directionsObject (readonly)

Indicates the directions of money movement for which this payment method is intended to be used.

Include ‘inbound` if you intend to use the payment method as the origin to pull funds from. Include `outbound` if you intend to use the payment method as the destination to send funds to. You can include both if you intend to use the payment method for both purposes.



4633
4634
4635
# File 'lib/stripe/resources/setup_intent.rb', line 4633

def flow_directions
  @flow_directions
end

#idObject (readonly)

Unique identifier for the object.



4635
4636
4637
# File 'lib/stripe/resources/setup_intent.rb', line 4635

def id
  @id
end

#last_setup_errorObject (readonly)

The error encountered in the previous SetupIntent confirmation.



4637
4638
4639
# File 'lib/stripe/resources/setup_intent.rb', line 4637

def last_setup_error
  @last_setup_error
end

#latest_attemptObject (readonly)

The most recent SetupAttempt for this SetupIntent.



4639
4640
4641
# File 'lib/stripe/resources/setup_intent.rb', line 4639

def latest_attempt
  @latest_attempt
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.



4641
4642
4643
# File 'lib/stripe/resources/setup_intent.rb', line 4641

def livemode
  @livemode
end

#mandateObject (readonly)

ID of the multi use Mandate generated by the SetupIntent.



4643
4644
4645
# File 'lib/stripe/resources/setup_intent.rb', line 4643

def mandate
  @mandate
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.



4645
4646
4647
# File 'lib/stripe/resources/setup_intent.rb', line 4645

def 
  @metadata
end

#next_actionObject (readonly)

If present, this property tells you what actions you need to take in order for your customer to continue payment setup.



4647
4648
4649
# File 'lib/stripe/resources/setup_intent.rb', line 4647

def next_action
  @next_action
end

#objectObject (readonly)

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



4649
4650
4651
# File 'lib/stripe/resources/setup_intent.rb', line 4649

def object
  @object
end

#on_behalf_ofObject (readonly)

The account (if any) for which the setup is intended.



4651
4652
4653
# File 'lib/stripe/resources/setup_intent.rb', line 4651

def on_behalf_of
  @on_behalf_of
end

#payment_methodObject (readonly)

ID of the payment method used with this SetupIntent. If the payment method is ‘card_present` and isn’t a digital wallet, then the [generated_card](docs.stripe.com/api/setup_attempts/object#setup_attempt_object-payment_method_details-card_present-generated_card) associated with the ‘latest_attempt` is attached to the Customer instead.



4653
4654
4655
# File 'lib/stripe/resources/setup_intent.rb', line 4653

def payment_method
  @payment_method
end

#payment_method_configuration_detailsObject (readonly)

Information about the [payment method configuration](stripe.com/docs/api/payment_method_configurations) used for this Setup Intent.



4655
4656
4657
# File 'lib/stripe/resources/setup_intent.rb', line 4655

def payment_method_configuration_details
  @payment_method_configuration_details
end

#payment_method_optionsObject (readonly)

Payment method-specific configuration for this SetupIntent.



4657
4658
4659
# File 'lib/stripe/resources/setup_intent.rb', line 4657

def payment_method_options
  @payment_method_options
end

#payment_method_typesObject (readonly)

The list of payment method types (e.g. card) that this SetupIntent is allowed to set up. A list of valid payment method types can be found [here](docs.stripe.com/api/payment_methods/object#payment_method_object-type).



4659
4660
4661
# File 'lib/stripe/resources/setup_intent.rb', line 4659

def payment_method_types
  @payment_method_types
end

#single_use_mandateObject (readonly)

ID of the single_use Mandate generated by the SetupIntent.



4661
4662
4663
# File 'lib/stripe/resources/setup_intent.rb', line 4661

def single_use_mandate
  @single_use_mandate
end

#statusObject (readonly)

[Status](stripe.com/docs/payments/intents#intent-statuses) of this SetupIntent, one of ‘requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `canceled`, or `succeeded`.



4663
4664
4665
# File 'lib/stripe/resources/setup_intent.rb', line 4663

def status
  @status
end

#usageObject (readonly)

Indicates how the payment method is intended to be used in the future.

Use ‘on_session` if you intend to only reuse the payment method when the customer is in your checkout flow. Use `off_session` if your customer may or may not be in your checkout flow. If not provided, this value defaults to `off_session`.



4667
4668
4669
# File 'lib/stripe/resources/setup_intent.rb', line 4667

def usage
  @usage
end

Class Method Details

.cancel(intent, params = {}, opts = {}) ⇒ Object

You can cancel a SetupIntent object when it’s in one of these statuses: requires_payment_method, requires_confirmation, or requires_action.

After you cancel it, setup is abandoned and any operations on the SetupIntent fail with an error. You can’t cancel the SetupIntent for a Checkout Session. [Expire the Checkout Session](docs.stripe.com/docs/api/checkout/sessions/expire) instead.



4684
4685
4686
4687
4688
4689
4690
4691
# File 'lib/stripe/resources/setup_intent.rb', line 4684

def self.cancel(intent, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/setup_intents/%<intent>s/cancel", { intent: CGI.escape(intent) }),
    params: params,
    opts: opts
  )
end

.confirm(intent, params = {}, opts = {}) ⇒ Object

Confirm that your customer intends to set up the current or provided payment method. For example, you would confirm a SetupIntent when a customer hits the “Save” button on a payment method management page on your website.

If the selected payment method does not require any additional steps from the customer, the SetupIntent will transition to the succeeded status.

Otherwise, it will transition to the requires_action status and suggest additional actions via next_action. If setup fails, the SetupIntent will transition to the requires_payment_method status or the canceled status if the confirmation limit is reached.



4730
4731
4732
4733
4734
4735
4736
4737
# File 'lib/stripe/resources/setup_intent.rb', line 4730

def self.confirm(intent, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/setup_intents/%<intent>s/confirm", { intent: CGI.escape(intent) }),
    params: params,
    opts: opts
  )
end

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

Creates a SetupIntent object.

After you create the SetupIntent, attach a payment method and [confirm](docs.stripe.com/docs/api/setup_intents/confirm) it to collect any required permissions to charge the payment method later.



4743
4744
4745
# File 'lib/stripe/resources/setup_intent.rb', line 4743

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

.field_remappingsObject



4792
4793
4794
# File 'lib/stripe/resources/setup_intent.rb', line 4792

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



4782
4783
4784
4785
4786
4787
4788
4789
4790
# File 'lib/stripe/resources/setup_intent.rb', line 4782

def self.inner_class_types
  @inner_class_types = {
    automatic_payment_methods: AutomaticPaymentMethods,
    last_setup_error: LastSetupError,
    next_action: NextAction,
    payment_method_configuration_details: PaymentMethodConfigurationDetails,
    payment_method_options: PaymentMethodOptions,
  }
end

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

Returns a list of SetupIntents.



4748
4749
4750
# File 'lib/stripe/resources/setup_intent.rb', line 4748

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

.object_nameObject



32
33
34
# File 'lib/stripe/resources/setup_intent.rb', line 32

def self.object_name
  "setup_intent"
end

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

Updates a SetupIntent object.



4753
4754
4755
4756
4757
4758
4759
4760
# File 'lib/stripe/resources/setup_intent.rb', line 4753

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

.verify_microdeposits(intent, params = {}, opts = {}) ⇒ Object

Verifies microdeposits on a SetupIntent object.



4773
4774
4775
4776
4777
4778
4779
4780
# File 'lib/stripe/resources/setup_intent.rb', line 4773

def self.verify_microdeposits(intent, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/setup_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(intent) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

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

You can cancel a SetupIntent object when it’s in one of these statuses: requires_payment_method, requires_confirmation, or requires_action.

After you cancel it, setup is abandoned and any operations on the SetupIntent fail with an error. You can’t cancel the SetupIntent for a Checkout Session. [Expire the Checkout Session](docs.stripe.com/docs/api/checkout/sessions/expire) instead.



4672
4673
4674
4675
4676
4677
4678
4679
# File 'lib/stripe/resources/setup_intent.rb', line 4672

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

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

Confirm that your customer intends to set up the current or provided payment method. For example, you would confirm a SetupIntent when a customer hits the “Save” button on a payment method management page on your website.

If the selected payment method does not require any additional steps from the customer, the SetupIntent will transition to the succeeded status.

Otherwise, it will transition to the requires_action status and suggest additional actions via next_action. If setup fails, the SetupIntent will transition to the requires_payment_method status or the canceled status if the confirmation limit is reached.



4707
4708
4709
4710
4711
4712
4713
4714
# File 'lib/stripe/resources/setup_intent.rb', line 4707

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

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

Verifies microdeposits on a SetupIntent object.



4763
4764
4765
4766
4767
4768
4769
4770
# File 'lib/stripe/resources/setup_intent.rb', line 4763

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