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)

Constant Summary collapse

OBJECT_NAME =
"setup_intent"

Constants inherited from StripeObject

Stripe::StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

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

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](stripe.com/docs/api/checkout/sessions/expire) instead.



51
52
53
54
55
56
57
58
# File 'lib/stripe/resources/setup_intent.rb', line 51

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.



97
98
99
100
101
102
103
104
# File 'lib/stripe/resources/setup_intent.rb', line 97

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](stripe.com/docs/api/setup_intents/confirm) it to collect any required permissions to charge the payment method later.



110
111
112
# File 'lib/stripe/resources/setup_intent.rb', line 110

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

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

Returns a list of SetupIntents.



115
116
117
# File 'lib/stripe/resources/setup_intent.rb', line 115

def self.list(filters = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/setup_intents", params: filters, 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(id, params = {}, opts = {}) ⇒ Object

Updates a SetupIntent object.



120
121
122
123
124
125
126
127
# File 'lib/stripe/resources/setup_intent.rb', line 120

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

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

Verifies microdeposits on a SetupIntent object.



140
141
142
143
144
145
146
147
# File 'lib/stripe/resources/setup_intent.rb', line 140

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](stripe.com/docs/api/checkout/sessions/expire) instead.



39
40
41
42
43
44
45
46
# File 'lib/stripe/resources/setup_intent.rb', line 39

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.



74
75
76
77
78
79
80
81
# File 'lib/stripe/resources/setup_intent.rb', line 74

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.



130
131
132
133
134
135
136
137
# File 'lib/stripe/resources/setup_intent.rb', line 130

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