stripe-ruby/lib/stripe/resources/setup_intent.rb
2022-08-23 05:35:55 -07:00

89 lines
3.7 KiB
Ruby

# File generated from our OpenAPI spec
# frozen_string_literal: true
module Stripe
# 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](https://stripe.com/docs/api#payment_intents) to drive the payment flow.
#
# Create a SetupIntent as soon as you're ready to collect your customer's payment credentials.
# Do not maintain long-lived, unconfirmed SetupIntents as they may no longer be valid.
# The SetupIntent then transitions through multiple [statuses](https://stripe.com/docs/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](https://stripe.com/guides/strong-customer-authentication) may need to be run through
# [Strong Customer Authentication](https://stripe.com/docs/strong-customer-authentication) at the time of payment method collection
# in order to streamline later [off-session payments](https://stripe.com/docs/payments/setup-intents).
# If the SetupIntent is used with a [Customer](https://stripe.com/docs/api#setup_intent_object-customer), upon success,
# it will automatically attach the resulting payment method to that Customer.
# We recommend using SetupIntents or [setup_future_usage](https://stripe.com/docs/api#payment_intent_object-setup_future_usage) on
# PaymentIntents to save payment methods in order to prevent saving invalid or unoptimized payment methods.
#
# By using SetupIntents, you ensure that your customers experience the minimum set of required friction,
# even as regulations change over time.
#
# Related guide: [Setup Intents API](https://stripe.com/docs/payments/setup-intents).
class SetupIntent < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
OBJECT_NAME = "setup_intent"
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
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
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
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
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
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
end
end