Class: Stripe::Charge
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::Charge
- Extended by:
- APIOperations::Create, APIOperations::List, APIOperations::NestedResource, APIOperations::Search
- Includes:
- APIOperations::Save
- Defined in:
- lib/stripe/resources/charge.rb
Overview
The ‘Charge` object represents a single attempt to move money into your Stripe account. PaymentIntent confirmation is the most common way to create Charges, but transferring money to a different Stripe account through Connect also creates Charges. Some legacy payment flows create Charges directly, which is not recommended for new integrations.
Defined Under Namespace
Classes: BillingDetails, CaptureParams, CreateParams, FraudDetails, Level3, ListParams, Outcome, PaymentMethodDetails, PresentmentDetails, RadarOptions, SearchParams, Shipping, TransferData, UpdateParams
Constant Summary collapse
- OBJECT_NAME =
"charge"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Amount intended to be collected by this payment.
-
#amount_captured ⇒ Object
readonly
Amount in cents (or local equivalent) captured (can be less than the amount attribute on the charge if a partial capture was made).
-
#amount_refunded ⇒ Object
readonly
Amount in cents (or local equivalent) refunded (can be less than the amount attribute on the charge if a partial refund was issued).
-
#application ⇒ Object
readonly
ID of the Connect application that created the charge.
-
#application_fee ⇒ Object
readonly
The application fee (if any) for the charge.
-
#application_fee_amount ⇒ Object
readonly
The amount of the application fee (if any) requested for the charge.
-
#authorization_code ⇒ Object
readonly
Authorization code on the charge.
-
#balance_transaction ⇒ Object
readonly
ID of the balance transaction that describes the impact of this charge on your account balance (not including refunds or disputes).
-
#billing_details ⇒ Object
readonly
Attribute for field billing_details.
-
#calculated_statement_descriptor ⇒ Object
readonly
The full statement descriptor that is passed to card networks, and that is displayed on your customers’ credit card and bank statements.
-
#captured ⇒ Object
readonly
If the charge was created without capturing, this Boolean represents whether it is still uncaptured or has since been captured.
-
#created ⇒ Object
readonly
Time at which the object was created.
-
#currency ⇒ Object
readonly
Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase.
-
#customer ⇒ Object
readonly
ID of the customer this charge is for if one exists.
-
#description ⇒ Object
readonly
An arbitrary string attached to the object.
-
#disputed ⇒ Object
readonly
Whether the charge has been disputed.
-
#failure_balance_transaction ⇒ Object
readonly
ID of the balance transaction that describes the reversal of the balance on your account due to payment failure.
-
#failure_code ⇒ Object
readonly
Error code explaining reason for charge failure if available (see [the errors section](stripe.com/docs/error-codes) for a list of codes).
-
#failure_message ⇒ Object
readonly
Message to user further explaining reason for charge failure if available.
-
#fraud_details ⇒ Object
readonly
Information on fraud assessments for the charge.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#level3 ⇒ Object
readonly
Attribute for field level3.
-
#livemode ⇒ Object
readonly
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#on_behalf_of ⇒ Object
readonly
The account (if any) the charge was made on behalf of without triggering an automatic transfer.
-
#outcome ⇒ Object
readonly
Details about whether the payment was accepted, and why.
-
#paid ⇒ Object
readonly
‘true` if the charge succeeded, or was successfully authorized for later capture.
-
#payment_intent ⇒ Object
readonly
ID of the PaymentIntent associated with this charge, if one exists.
-
#payment_method ⇒ Object
readonly
ID of the payment method used in this charge.
-
#payment_method_details ⇒ Object
readonly
Details about the payment method at the time of the transaction.
-
#presentment_details ⇒ Object
readonly
Attribute for field presentment_details.
-
#radar_options ⇒ Object
readonly
Options to configure Radar.
-
#receipt_email ⇒ Object
readonly
This is the email address that the receipt for this charge was sent to.
-
#receipt_number ⇒ Object
readonly
This is the transaction number that appears on email receipts sent for this charge.
-
#receipt_url ⇒ Object
readonly
This is the URL to view the receipt for this charge.
-
#refunded ⇒ Object
readonly
Whether the charge has been fully refunded.
-
#refunds ⇒ Object
readonly
A list of refunds that have been applied to the charge.
-
#review ⇒ Object
readonly
ID of the review associated with this charge if one exists.
-
#shipping ⇒ Object
readonly
Shipping information for the charge.
-
#source ⇒ Object
readonly
This is a legacy field that will be removed in the future.
-
#source_transfer ⇒ Object
readonly
The transfer ID which created this charge.
-
#statement_descriptor ⇒ Object
readonly
For a non-card charge, text that appears on the customer’s statement as the statement descriptor.
-
#statement_descriptor_suffix ⇒ Object
readonly
Provides information about a card charge.
-
#status ⇒ Object
readonly
The status of the payment is either ‘succeeded`, `pending`, or `failed`.
-
#transfer ⇒ Object
readonly
ID of the transfer to the ‘destination` account (only applicable if the charge was created using the `destination` parameter).
-
#transfer_data ⇒ Object
readonly
An optional dictionary including the account to automatically transfer to as part of a destination charge.
-
#transfer_group ⇒ Object
readonly
A string that identifies this transaction as part of a group.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.capture(charge, params = {}, opts = {}) ⇒ Object
Capture the payment of an existing, uncaptured charge that was created with the capture option set to false.
-
.create(params = {}, opts = {}) ⇒ Object
This method is no longer recommended—use the [Payment Intents API](docs.stripe.com/docs/api/payment_intents) to initiate a new payment instead.
- .field_remappings ⇒ Object
- .inner_class_types ⇒ Object
-
.list(params = {}, opts = {}) ⇒ Object
Returns a list of charges you’ve previously created.
- .object_name ⇒ Object
- .search(params = {}, opts = {}) ⇒ Object
- .search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
-
.update(charge, params = {}, opts = {}) ⇒ Object
Updates the specified charge by setting the values of the parameters passed.
Instance Method Summary collapse
-
#capture(params = {}, opts = {}) ⇒ Object
Capture the payment of an existing, uncaptured charge that was created with the capture option set to false.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::NestedResource
Methods included from APIOperations::Search
Methods included from APIOperations::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
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
#amount ⇒ Object (readonly)
Amount intended to be collected by this payment. A positive integer representing how much to charge in the [smallest currency unit](stripe.com/docs/currencies#zero-decimal) (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency). The minimum amount is $0.50 US or [equivalent in charge currency](stripe.com/docs/currencies#minimum-and-maximum-charge-amounts). The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
4149 4150 4151 |
# File 'lib/stripe/resources/charge.rb', line 4149 def amount @amount end |
#amount_captured ⇒ Object (readonly)
Amount in cents (or local equivalent) captured (can be less than the amount attribute on the charge if a partial capture was made).
4151 4152 4153 |
# File 'lib/stripe/resources/charge.rb', line 4151 def amount_captured @amount_captured end |
#amount_refunded ⇒ Object (readonly)
Amount in cents (or local equivalent) refunded (can be less than the amount attribute on the charge if a partial refund was issued).
4153 4154 4155 |
# File 'lib/stripe/resources/charge.rb', line 4153 def amount_refunded @amount_refunded end |
#application ⇒ Object (readonly)
ID of the Connect application that created the charge.
4155 4156 4157 |
# File 'lib/stripe/resources/charge.rb', line 4155 def application @application end |
#application_fee ⇒ Object (readonly)
The application fee (if any) for the charge. [See the Connect documentation](stripe.com/docs/connect/direct-charges#collect-fees) for details.
4157 4158 4159 |
# File 'lib/stripe/resources/charge.rb', line 4157 def application_fee @application_fee end |
#application_fee_amount ⇒ Object (readonly)
The amount of the application fee (if any) requested for the charge. [See the Connect documentation](stripe.com/docs/connect/direct-charges#collect-fees) for details.
4159 4160 4161 |
# File 'lib/stripe/resources/charge.rb', line 4159 def application_fee_amount @application_fee_amount end |
#authorization_code ⇒ Object (readonly)
Authorization code on the charge.
4161 4162 4163 |
# File 'lib/stripe/resources/charge.rb', line 4161 def @authorization_code end |
#balance_transaction ⇒ Object (readonly)
ID of the balance transaction that describes the impact of this charge on your account balance (not including refunds or disputes).
4163 4164 4165 |
# File 'lib/stripe/resources/charge.rb', line 4163 def balance_transaction @balance_transaction end |
#billing_details ⇒ Object (readonly)
Attribute for field billing_details
4165 4166 4167 |
# File 'lib/stripe/resources/charge.rb', line 4165 def billing_details @billing_details end |
#calculated_statement_descriptor ⇒ Object (readonly)
The full statement descriptor that is passed to card networks, and that is displayed on your customers’ credit card and bank statements. Allows you to see what the statement descriptor looks like after the static and dynamic portions are combined. This value only exists for card payments.
4167 4168 4169 |
# File 'lib/stripe/resources/charge.rb', line 4167 def calculated_statement_descriptor @calculated_statement_descriptor end |
#captured ⇒ Object (readonly)
If the charge was created without capturing, this Boolean represents whether it is still uncaptured or has since been captured.
4169 4170 4171 |
# File 'lib/stripe/resources/charge.rb', line 4169 def captured @captured end |
#created ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
4171 4172 4173 |
# File 'lib/stripe/resources/charge.rb', line 4171 def created @created end |
#currency ⇒ Object (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).
4173 4174 4175 |
# File 'lib/stripe/resources/charge.rb', line 4173 def currency @currency end |
#customer ⇒ Object (readonly)
ID of the customer this charge is for if one exists.
4175 4176 4177 |
# File 'lib/stripe/resources/charge.rb', line 4175 def customer @customer end |
#description ⇒ Object (readonly)
An arbitrary string attached to the object. Often useful for displaying to users.
4177 4178 4179 |
# File 'lib/stripe/resources/charge.rb', line 4177 def description @description end |
#disputed ⇒ Object (readonly)
Whether the charge has been disputed.
4179 4180 4181 |
# File 'lib/stripe/resources/charge.rb', line 4179 def disputed @disputed end |
#failure_balance_transaction ⇒ Object (readonly)
ID of the balance transaction that describes the reversal of the balance on your account due to payment failure.
4181 4182 4183 |
# File 'lib/stripe/resources/charge.rb', line 4181 def failure_balance_transaction @failure_balance_transaction end |
#failure_code ⇒ Object (readonly)
Error code explaining reason for charge failure if available (see [the errors section](stripe.com/docs/error-codes) for a list of codes).
4183 4184 4185 |
# File 'lib/stripe/resources/charge.rb', line 4183 def failure_code @failure_code end |
#failure_message ⇒ Object (readonly)
Message to user further explaining reason for charge failure if available.
4185 4186 4187 |
# File 'lib/stripe/resources/charge.rb', line 4185 def @failure_message end |
#fraud_details ⇒ Object (readonly)
Information on fraud assessments for the charge.
4187 4188 4189 |
# File 'lib/stripe/resources/charge.rb', line 4187 def fraud_details @fraud_details end |
#id ⇒ Object (readonly)
Unique identifier for the object.
4189 4190 4191 |
# File 'lib/stripe/resources/charge.rb', line 4189 def id @id end |
#level3 ⇒ Object (readonly)
Attribute for field level3
4191 4192 4193 |
# File 'lib/stripe/resources/charge.rb', line 4191 def level3 @level3 end |
#livemode ⇒ Object (readonly)
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
4193 4194 4195 |
# File 'lib/stripe/resources/charge.rb', line 4193 def livemode @livemode end |
#metadata ⇒ Object (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.
4195 4196 4197 |
# File 'lib/stripe/resources/charge.rb', line 4195 def @metadata end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
4197 4198 4199 |
# File 'lib/stripe/resources/charge.rb', line 4197 def object @object end |
#on_behalf_of ⇒ Object (readonly)
The account (if any) the charge was made on behalf of without triggering an automatic transfer. See the [Connect documentation](stripe.com/docs/connect/separate-charges-and-transfers) for details.
4199 4200 4201 |
# File 'lib/stripe/resources/charge.rb', line 4199 def on_behalf_of @on_behalf_of end |
#outcome ⇒ Object (readonly)
Details about whether the payment was accepted, and why. See [understanding declines](stripe.com/docs/declines) for details.
4201 4202 4203 |
# File 'lib/stripe/resources/charge.rb', line 4201 def outcome @outcome end |
#paid ⇒ Object (readonly)
‘true` if the charge succeeded, or was successfully authorized for later capture.
4203 4204 4205 |
# File 'lib/stripe/resources/charge.rb', line 4203 def paid @paid end |
#payment_intent ⇒ Object (readonly)
ID of the PaymentIntent associated with this charge, if one exists.
4205 4206 4207 |
# File 'lib/stripe/resources/charge.rb', line 4205 def payment_intent @payment_intent end |
#payment_method ⇒ Object (readonly)
ID of the payment method used in this charge.
4207 4208 4209 |
# File 'lib/stripe/resources/charge.rb', line 4207 def payment_method @payment_method end |
#payment_method_details ⇒ Object (readonly)
Details about the payment method at the time of the transaction.
4209 4210 4211 |
# File 'lib/stripe/resources/charge.rb', line 4209 def payment_method_details @payment_method_details end |
#presentment_details ⇒ Object (readonly)
Attribute for field presentment_details
4211 4212 4213 |
# File 'lib/stripe/resources/charge.rb', line 4211 def presentment_details @presentment_details end |
#radar_options ⇒ Object (readonly)
Options to configure Radar. See [Radar Session](stripe.com/docs/radar/radar-session) for more information.
4213 4214 4215 |
# File 'lib/stripe/resources/charge.rb', line 4213 def @radar_options end |
#receipt_email ⇒ Object (readonly)
This is the email address that the receipt for this charge was sent to.
4215 4216 4217 |
# File 'lib/stripe/resources/charge.rb', line 4215 def receipt_email @receipt_email end |
#receipt_number ⇒ Object (readonly)
This is the transaction number that appears on email receipts sent for this charge. This attribute will be ‘null` until a receipt has been sent.
4217 4218 4219 |
# File 'lib/stripe/resources/charge.rb', line 4217 def receipt_number @receipt_number end |
#receipt_url ⇒ Object (readonly)
This is the URL to view the receipt for this charge. The receipt is kept up-to-date to the latest state of the charge, including any refunds. If the charge is for an Invoice, the receipt will be stylized as an Invoice receipt.
4219 4220 4221 |
# File 'lib/stripe/resources/charge.rb', line 4219 def receipt_url @receipt_url end |
#refunded ⇒ Object (readonly)
Whether the charge has been fully refunded. If the charge is only partially refunded, this attribute will still be false.
4221 4222 4223 |
# File 'lib/stripe/resources/charge.rb', line 4221 def refunded @refunded end |
#refunds ⇒ Object (readonly)
A list of refunds that have been applied to the charge.
4223 4224 4225 |
# File 'lib/stripe/resources/charge.rb', line 4223 def refunds @refunds end |
#review ⇒ Object (readonly)
ID of the review associated with this charge if one exists.
4225 4226 4227 |
# File 'lib/stripe/resources/charge.rb', line 4225 def review @review end |
#shipping ⇒ Object (readonly)
Shipping information for the charge.
4227 4228 4229 |
# File 'lib/stripe/resources/charge.rb', line 4227 def shipping @shipping end |
#source ⇒ Object (readonly)
This is a legacy field that will be removed in the future. It contains the Source, Card, or BankAccount object used for the charge. For details about the payment method used for this charge, refer to ‘payment_method` or `payment_method_details` instead.
4229 4230 4231 |
# File 'lib/stripe/resources/charge.rb', line 4229 def source @source end |
#source_transfer ⇒ Object (readonly)
The transfer ID which created this charge. Only present if the charge came from another Stripe account. [See the Connect documentation](docs.stripe.com/connect/destination-charges) for details.
4231 4232 4233 |
# File 'lib/stripe/resources/charge.rb', line 4231 def source_transfer @source_transfer end |
#statement_descriptor ⇒ Object (readonly)
For a non-card charge, text that appears on the customer’s statement as the statement descriptor. This value overrides the account’s default statement descriptor. For information about requirements, including the 22-character limit, see [the Statement Descriptor docs](docs.stripe.com/get-started/account/statement-descriptors).
For a card charge, this value is ignored unless you don’t specify a ‘statement_descriptor_suffix`, in which case this value is used as the suffix.
4235 4236 4237 |
# File 'lib/stripe/resources/charge.rb', line 4235 def statement_descriptor @statement_descriptor end |
#statement_descriptor_suffix ⇒ Object (readonly)
Provides information about a card charge. Concatenated to the account’s [statement descriptor prefix](docs.stripe.com/get-started/account/statement-descriptors#static) to form the complete statement descriptor that appears on the customer’s statement. If the account has no prefix value, the suffix is concatenated to the account’s statement descriptor.
4237 4238 4239 |
# File 'lib/stripe/resources/charge.rb', line 4237 def statement_descriptor_suffix @statement_descriptor_suffix end |
#status ⇒ Object (readonly)
The status of the payment is either ‘succeeded`, `pending`, or `failed`.
4239 4240 4241 |
# File 'lib/stripe/resources/charge.rb', line 4239 def status @status end |
#transfer ⇒ Object (readonly)
ID of the transfer to the ‘destination` account (only applicable if the charge was created using the `destination` parameter).
4241 4242 4243 |
# File 'lib/stripe/resources/charge.rb', line 4241 def transfer @transfer end |
#transfer_data ⇒ Object (readonly)
An optional dictionary including the account to automatically transfer to as part of a destination charge. [See the Connect documentation](stripe.com/docs/connect/destination-charges) for details.
4243 4244 4245 |
# File 'lib/stripe/resources/charge.rb', line 4243 def transfer_data @transfer_data end |
#transfer_group ⇒ Object (readonly)
A string that identifies this transaction as part of a group. See the [Connect documentation](stripe.com/docs/connect/separate-charges-and-transfers#transfer-options) for details.
4245 4246 4247 |
# File 'lib/stripe/resources/charge.rb', line 4245 def transfer_group @transfer_group end |
Class Method Details
.capture(charge, params = {}, opts = {}) ⇒ Object
Capture the payment of an existing, uncaptured charge that was created with the capture option set to false.
Uncaptured payments expire a set number of days after they are created ([7 by default](docs.stripe.com/docs/charges/placing-a-hold)), after which they are marked as refunded and capture attempts will fail.
Don’t use this method to capture a PaymentIntent-initiated charge. Use [Capture a PaymentIntent](docs.stripe.com/docs/api/payment_intents/capture).
4266 4267 4268 4269 4270 4271 4272 4273 |
# File 'lib/stripe/resources/charge.rb', line 4266 def self.capture(charge, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/charges/%<charge>s/capture", { charge: CGI.escape(charge) }), params: params, opts: opts ) end |
.create(params = {}, opts = {}) ⇒ Object
This method is no longer recommended—use the [Payment Intents API](docs.stripe.com/docs/api/payment_intents) to initiate a new payment instead. Confirmation of the PaymentIntent creates the Charge object used to request payment.
4278 4279 4280 |
# File 'lib/stripe/resources/charge.rb', line 4278 def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/charges", params: params, opts: opts) end |
.field_remappings ⇒ Object
4319 4320 4321 |
# File 'lib/stripe/resources/charge.rb', line 4319 def self.field_remappings @field_remappings = {} end |
.inner_class_types ⇒ Object
4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 |
# File 'lib/stripe/resources/charge.rb', line 4305 def self.inner_class_types @inner_class_types = { billing_details: BillingDetails, fraud_details: FraudDetails, level3: Level3, outcome: Outcome, payment_method_details: PaymentMethodDetails, presentment_details: PresentmentDetails, radar_options: RadarOptions, shipping: Shipping, transfer_data: TransferData, } end |
.list(params = {}, opts = {}) ⇒ Object
Returns a list of charges you’ve previously created. The charges are returned in sorted order, with the most recent charges appearing first.
4283 4284 4285 |
# File 'lib/stripe/resources/charge.rb', line 4283 def self.list(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/charges", params: params, opts: opts) end |
.object_name ⇒ Object
17 18 19 |
# File 'lib/stripe/resources/charge.rb', line 17 def self.object_name "charge" end |
.search(params = {}, opts = {}) ⇒ Object
4287 4288 4289 |
# File 'lib/stripe/resources/charge.rb', line 4287 def self.search(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/charges/search", params: params, opts: opts) end |
.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
4291 4292 4293 |
# File 'lib/stripe/resources/charge.rb', line 4291 def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end |
.update(charge, params = {}, opts = {}) ⇒ Object
Updates the specified charge by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
4296 4297 4298 4299 4300 4301 4302 4303 |
# File 'lib/stripe/resources/charge.rb', line 4296 def self.update(charge, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/charges/%<charge>s", { charge: CGI.escape(charge) }), params: params, opts: opts ) end |
Instance Method Details
#capture(params = {}, opts = {}) ⇒ Object
Capture the payment of an existing, uncaptured charge that was created with the capture option set to false.
Uncaptured payments expire a set number of days after they are created ([7 by default](docs.stripe.com/docs/charges/placing-a-hold)), after which they are marked as refunded and capture attempts will fail.
Don’t use this method to capture a PaymentIntent-initiated charge. Use [Capture a PaymentIntent](docs.stripe.com/docs/api/payment_intents/capture).
4252 4253 4254 4255 4256 4257 4258 4259 |
# File 'lib/stripe/resources/charge.rb', line 4252 def capture(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/charges/%<charge>s/capture", { charge: CGI.escape(self["id"]) }), params: params, opts: opts ) end |