Class: Stripe::PaymentIntent

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

Overview

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.

A PaymentIntent transitions through [multiple statuses](stripe.com/docs/payments/intents#intent-statuses) throughout its lifetime as it interfaces with Stripe.js to perform authentication flows and ultimately creates at most one successful charge.

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

Constant Summary collapse

OBJECT_NAME =
"payment_intent"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

Attributes inherited from APIResource

#save_with_parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Search

_search

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

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

Manually reconcile the remaining amount for a customer_balance PaymentIntent.



138
139
140
141
142
143
144
145
# File 'lib/stripe/resources/payment_intent.rb', line 138

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

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

You can cancel a PaymentIntent object when it’s in one of these statuses: requires_payment_method, requires_capture, requires_confirmation, requires_action or, [in rare cases](stripe.com/docs/payments/intents), processing.

After it’s canceled, no additional charges are made by the PaymentIntent and any operations on the PaymentIntent fail with an error. For PaymentIntents with a status of requires_capture, the remaining amount_capturable is automatically refunded.

You can’t cancel the PaymentIntent for a Checkout Session. [Expire the Checkout Session](stripe.com/docs/api/checkout/sessions/expire) instead.



152
153
154
155
156
157
158
159
# File 'lib/stripe/resources/payment_intent.rb', line 152

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

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

Capture the funds of an existing uncaptured PaymentIntent when its status is requires_capture.

Uncaptured PaymentIntents are cancelled a set number of days (7 by default) after their creation.

Learn more about [separate authorization and capture](stripe.com/docs/payments/capture-later).



166
167
168
169
170
171
172
173
# File 'lib/stripe/resources/payment_intent.rb', line 166

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

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

Confirm that your customer intends to pay with current or provided payment method. Upon confirmation, the PaymentIntent will attempt to initiate a payment. If the selected payment method requires additional authentication steps, the PaymentIntent will transition to the requires_action status and suggest additional actions via next_action. If payment fails, the PaymentIntent transitions to the requires_payment_method status or the canceled status if the confirmation limit is reached. If payment succeeds, the PaymentIntent will transition to the succeeded status (or requires_capture, if capture_method is set to manual). If the confirmation_method is automatic, payment may be attempted using our [client SDKs](stripe.com/docs/stripe-js/reference#stripe-handle-card-payment) and the PaymentIntent’s [client_secret](stripe.com/docs/api#payment_intent_object-client_secret). After next_actions are handled by the client, no additional confirmation is required to complete the payment. If the confirmation_method is manual, all payment attempts must be initiated using a secret key. If any actions are required for the payment, the PaymentIntent will return to the requires_confirmation state after those actions are completed. Your server needs to then explicitly re-confirm the PaymentIntent to initiate the next payment attempt. Read the [expanded documentation](stripe.com/docs/payments/payment-intents/web-manual) to learn more about manual confirmation.



198
199
200
201
202
203
204
205
# File 'lib/stripe/resources/payment_intent.rb', line 198

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

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

Perform an incremental authorization on an eligible [PaymentIntent](stripe.com/docs/api/payment_intents/object). To be eligible, the PaymentIntent’s status must be requires_capture and [incremental_authorization_supported](stripe.com/docs/api/charges/object#charge_object-payment_method_details-card_present-incremental_authorization_supported) must be true.

Incremental authorizations attempt to increase the authorized amount on your customer’s card to the new, higher amount provided. Similar to the initial authorization, incremental authorizations can be declined. A single PaymentIntent can call this endpoint multiple times to further increase the authorized amount.

If the incremental authorization succeeds, the PaymentIntent object returns with the updated [amount](stripe.com/docs/api/payment_intents/object#payment_intent_object-amount). If the incremental authorization fails, a [card_declined](stripe.com/docs/error-codes#card-declined) error returns, and no other fields on the PaymentIntent or Charge update. The PaymentIntent object remains capturable for the previously authorized amount.

Each PaymentIntent can have a maximum of 10 incremental authorization attempts, including declines. After it’s captured, a PaymentIntent can no longer be incremented.

Learn more about [incremental authorizations](stripe.com/docs/terminal/features/incremental-authorizations).



231
232
233
234
235
236
237
238
# File 'lib/stripe/resources/payment_intent.rb', line 231

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

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



250
251
252
# File 'lib/stripe/resources/payment_intent.rb', line 250

def self.search(params = {}, opts = {})
  _search("/v1/payment_intents/search", params, opts)
end

.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object



254
255
256
# File 'lib/stripe/resources/payment_intent.rb', line 254

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
  search(params, opts).auto_paging_each(&blk)
end

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

Verifies microdeposits on a PaymentIntent object.



241
242
243
244
245
246
247
248
# File 'lib/stripe/resources/payment_intent.rb', line 241

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

Instance Method Details

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

Manually reconcile the remaining amount for a customer_balance PaymentIntent.



25
26
27
28
29
30
31
32
# File 'lib/stripe/resources/payment_intent.rb', line 25

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

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

You can cancel a PaymentIntent object when it’s in one of these statuses: requires_payment_method, requires_capture, requires_confirmation, requires_action or, [in rare cases](stripe.com/docs/payments/intents), processing.

After it’s canceled, no additional charges are made by the PaymentIntent and any operations on the PaymentIntent fail with an error. For PaymentIntents with a status of requires_capture, the remaining amount_capturable is automatically refunded.

You can’t cancel the PaymentIntent 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/payment_intent.rb', line 39

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

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

Capture the funds of an existing uncaptured PaymentIntent when its status is requires_capture.

Uncaptured PaymentIntents are cancelled a set number of days (7 by default) after their creation.

Learn more about [separate authorization and capture](stripe.com/docs/payments/capture-later).



53
54
55
56
57
58
59
60
# File 'lib/stripe/resources/payment_intent.rb', line 53

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

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

Confirm that your customer intends to pay with current or provided payment method. Upon confirmation, the PaymentIntent will attempt to initiate a payment. If the selected payment method requires additional authentication steps, the PaymentIntent will transition to the requires_action status and suggest additional actions via next_action. If payment fails, the PaymentIntent transitions to the requires_payment_method status or the canceled status if the confirmation limit is reached. If payment succeeds, the PaymentIntent will transition to the succeeded status (or requires_capture, if capture_method is set to manual). If the confirmation_method is automatic, payment may be attempted using our [client SDKs](stripe.com/docs/stripe-js/reference#stripe-handle-card-payment) and the PaymentIntent’s [client_secret](stripe.com/docs/api#payment_intent_object-client_secret). After next_actions are handled by the client, no additional confirmation is required to complete the payment. If the confirmation_method is manual, all payment attempts must be initiated using a secret key. If any actions are required for the payment, the PaymentIntent will return to the requires_confirmation state after those actions are completed. Your server needs to then explicitly re-confirm the PaymentIntent to initiate the next payment attempt. Read the [expanded documentation](stripe.com/docs/payments/payment-intents/web-manual) to learn more about manual confirmation.



85
86
87
88
89
90
91
92
# File 'lib/stripe/resources/payment_intent.rb', line 85

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

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

Perform an incremental authorization on an eligible [PaymentIntent](stripe.com/docs/api/payment_intents/object). To be eligible, the PaymentIntent’s status must be requires_capture and [incremental_authorization_supported](stripe.com/docs/api/charges/object#charge_object-payment_method_details-card_present-incremental_authorization_supported) must be true.

Incremental authorizations attempt to increase the authorized amount on your customer’s card to the new, higher amount provided. Similar to the initial authorization, incremental authorizations can be declined. A single PaymentIntent can call this endpoint multiple times to further increase the authorized amount.

If the incremental authorization succeeds, the PaymentIntent object returns with the updated [amount](stripe.com/docs/api/payment_intents/object#payment_intent_object-amount). If the incremental authorization fails, a [card_declined](stripe.com/docs/error-codes#card-declined) error returns, and no other fields on the PaymentIntent or Charge update. The PaymentIntent object remains capturable for the previously authorized amount.

Each PaymentIntent can have a maximum of 10 incremental authorization attempts, including declines. After it’s captured, a PaymentIntent can no longer be incremented.

Learn more about [incremental authorizations](stripe.com/docs/terminal/features/incremental-authorizations).



118
119
120
121
122
123
124
125
# File 'lib/stripe/resources/payment_intent.rb', line 118

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

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

Verifies microdeposits on a PaymentIntent object.



128
129
130
131
132
133
134
135
# File 'lib/stripe/resources/payment_intent.rb', line 128

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