Class: Stripe::Charge

Inherits:
APIResource show all
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 Account Debits may also create Charges. Some legacy payment flows create Charges directly, which is not recommended for new integrations.

Defined Under Namespace

Classes: BillingDetails, FraudDetails, Level3, Outcome, PaymentMethodDetails, PresentmentDetails, RadarOptions, Shipping, TransferData

Constant Summary collapse

OBJECT_NAME =
"charge"

Constants inherited from StripeObject

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

nested_resource_class_methods

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

#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, field_encodings, #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

#amountObject (readonly)

Amount intended to be collected by this payment. A positive integer representing how much to charge in the smallest currency unit (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. The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).



2244
2245
2246
# File 'lib/stripe/resources/charge.rb', line 2244

def amount
  @amount
end

#amount_capturedObject (readonly)

Amount in cents (or local equivalent) captured (can be less than the amount attribute on the charge if a partial capture was made).



2246
2247
2248
# File 'lib/stripe/resources/charge.rb', line 2246

def amount_captured
  @amount_captured
end

#amount_refundedObject (readonly)

Amount in cents (or local equivalent) refunded (can be less than the amount attribute on the charge if a partial refund was issued).



2248
2249
2250
# File 'lib/stripe/resources/charge.rb', line 2248

def amount_refunded
  @amount_refunded
end

#applicationObject (readonly)

ID of the Connect application that created the charge.



2250
2251
2252
# File 'lib/stripe/resources/charge.rb', line 2250

def application
  @application
end

#application_feeObject (readonly)

The application fee (if any) for the charge. See the Connect documentation for details.



2252
2253
2254
# File 'lib/stripe/resources/charge.rb', line 2252

def application_fee
  @application_fee
end

#application_fee_amountObject (readonly)

The amount of the application fee (if any) requested for the charge. See the Connect documentation for details.



2254
2255
2256
# File 'lib/stripe/resources/charge.rb', line 2254

def application_fee_amount
  @application_fee_amount
end

#authorization_codeObject (readonly)

Authorization code on the charge.



2256
2257
2258
# File 'lib/stripe/resources/charge.rb', line 2256

def authorization_code
  @authorization_code
end

#balance_transactionObject (readonly)

ID of the balance transaction that describes the impact of this charge on your account balance (not including refunds or disputes).



2258
2259
2260
# File 'lib/stripe/resources/charge.rb', line 2258

def balance_transaction
  @balance_transaction
end

#billing_detailsObject (readonly)

Attribute for field billing_details



2260
2261
2262
# File 'lib/stripe/resources/charge.rb', line 2260

def billing_details
  @billing_details
end

#calculated_statement_descriptorObject (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.



2262
2263
2264
# File 'lib/stripe/resources/charge.rb', line 2262

def calculated_statement_descriptor
  @calculated_statement_descriptor
end

#capturedObject (readonly)

If the charge was created without capturing, this Boolean represents whether it is still uncaptured or has since been captured.



2264
2265
2266
# File 'lib/stripe/resources/charge.rb', line 2264

def captured
  @captured
end

#createdObject (readonly)

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



2266
2267
2268
# File 'lib/stripe/resources/charge.rb', line 2266

def created
  @created
end

#currencyObject (readonly)

Three-letter ISO currency code, in lowercase. Must be a supported currency.



2268
2269
2270
# File 'lib/stripe/resources/charge.rb', line 2268

def currency
  @currency
end

#customerObject (readonly)

ID of the customer this charge is for if one exists.



2270
2271
2272
# File 'lib/stripe/resources/charge.rb', line 2270

def customer
  @customer
end

#descriptionObject (readonly)

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



2272
2273
2274
# File 'lib/stripe/resources/charge.rb', line 2272

def description
  @description
end

#disputedObject (readonly)

Whether the charge has been disputed.



2274
2275
2276
# File 'lib/stripe/resources/charge.rb', line 2274

def disputed
  @disputed
end

#failure_balance_transactionObject (readonly)

ID of the balance transaction that describes the reversal of the balance on your account due to payment failure.



2276
2277
2278
# File 'lib/stripe/resources/charge.rb', line 2276

def failure_balance_transaction
  @failure_balance_transaction
end

#failure_codeObject (readonly)

Error code explaining reason for charge failure if available (see the errors section for a list of codes).



2278
2279
2280
# File 'lib/stripe/resources/charge.rb', line 2278

def failure_code
  @failure_code
end

#failure_messageObject (readonly)

Message to user further explaining reason for charge failure if available.



2280
2281
2282
# File 'lib/stripe/resources/charge.rb', line 2280

def failure_message
  @failure_message
end

#fraud_detailsObject (readonly)

Information on fraud assessments for the charge.



2282
2283
2284
# File 'lib/stripe/resources/charge.rb', line 2282

def fraud_details
  @fraud_details
end

#idObject (readonly)

Unique identifier for the object.



2284
2285
2286
# File 'lib/stripe/resources/charge.rb', line 2284

def id
  @id
end

#level3Object (readonly)

Attribute for field level3



2286
2287
2288
# File 'lib/stripe/resources/charge.rb', line 2286

def level3
  @level3
end

#livemodeObject (readonly)

If the object exists in live mode, the value is true. If the object exists in test mode, the value is false.



2288
2289
2290
# File 'lib/stripe/resources/charge.rb', line 2288

def livemode
  @livemode
end

#metadataObject (readonly)

Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



2290
2291
2292
# File 'lib/stripe/resources/charge.rb', line 2290

def 
  @metadata
end

#objectObject (readonly)

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



2292
2293
2294
# File 'lib/stripe/resources/charge.rb', line 2292

def object
  @object
end

#on_behalf_ofObject (readonly)

The account (if any) the charge was made on behalf of without triggering an automatic transfer. See the Connect documentation for details.



2294
2295
2296
# File 'lib/stripe/resources/charge.rb', line 2294

def on_behalf_of
  @on_behalf_of
end

#outcomeObject (readonly)

Details about whether the payment was accepted, and why. See understanding declines for details.



2296
2297
2298
# File 'lib/stripe/resources/charge.rb', line 2296

def outcome
  @outcome
end

true if the charge succeeded, or was successfully authorized for later capture.



2298
2299
2300
# File 'lib/stripe/resources/charge.rb', line 2298

def paid
  @paid
end

#payment_intentObject (readonly)

ID of the PaymentIntent associated with this charge, if one exists.



2300
2301
2302
# File 'lib/stripe/resources/charge.rb', line 2300

def payment_intent
  @payment_intent
end

#payment_methodObject (readonly)

ID of the payment method used in this charge.



2302
2303
2304
# File 'lib/stripe/resources/charge.rb', line 2302

def payment_method
  @payment_method
end

#payment_method_detailsObject (readonly)

Details about the payment method at the time of the transaction.



2304
2305
2306
# File 'lib/stripe/resources/charge.rb', line 2304

def payment_method_details
  @payment_method_details
end

#presentment_detailsObject (readonly)

Attribute for field presentment_details



2306
2307
2308
# File 'lib/stripe/resources/charge.rb', line 2306

def presentment_details
  @presentment_details
end

#radar_optionsObject (readonly)

Options to configure Radar. See Radar Session for more information.



2308
2309
2310
# File 'lib/stripe/resources/charge.rb', line 2308

def radar_options
  @radar_options
end

#receipt_emailObject (readonly)

This is the email address that the receipt for this charge was sent to.



2310
2311
2312
# File 'lib/stripe/resources/charge.rb', line 2310

def receipt_email
  @receipt_email
end

#receipt_numberObject (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.



2312
2313
2314
# File 'lib/stripe/resources/charge.rb', line 2312

def receipt_number
  @receipt_number
end

#receipt_urlObject (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.



2314
2315
2316
# File 'lib/stripe/resources/charge.rb', line 2314

def receipt_url
  @receipt_url
end

#refundedObject (readonly)

Whether the charge has been fully refunded. If the charge is only partially refunded, this attribute will still be false.



2316
2317
2318
# File 'lib/stripe/resources/charge.rb', line 2316

def refunded
  @refunded
end

#refundsObject (readonly)

A list of refunds that have been applied to the charge.



2318
2319
2320
# File 'lib/stripe/resources/charge.rb', line 2318

def refunds
  @refunds
end

#reviewObject (readonly)

ID of the review associated with this charge if one exists.



2320
2321
2322
# File 'lib/stripe/resources/charge.rb', line 2320

def review
  @review
end

#shippingObject (readonly)

Shipping information for the charge.



2322
2323
2324
# File 'lib/stripe/resources/charge.rb', line 2322

def shipping
  @shipping
end

#sourceObject (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.



2324
2325
2326
# File 'lib/stripe/resources/charge.rb', line 2324

def source
  @source
end

#source_transferObject (readonly)

The transfer ID which created this charge. Only present if the charge came from another Stripe account. See the Connect documentation for details.



2326
2327
2328
# File 'lib/stripe/resources/charge.rb', line 2326

def source_transfer
  @source_transfer
end

#statement_descriptorObject (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.

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.



2330
2331
2332
# File 'lib/stripe/resources/charge.rb', line 2330

def statement_descriptor
  @statement_descriptor
end

#statement_descriptor_suffixObject (readonly)

Provides information about a card charge. Concatenated to the account's statement descriptor prefix 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.



2332
2333
2334
# File 'lib/stripe/resources/charge.rb', line 2332

def statement_descriptor_suffix
  @statement_descriptor_suffix
end

#statusObject (readonly)

The status of the payment is either succeeded, pending, or failed.



2334
2335
2336
# File 'lib/stripe/resources/charge.rb', line 2334

def status
  @status
end

#transferObject (readonly)

ID of the transfer to the destination account (only applicable if the charge was created using the destination parameter).



2336
2337
2338
# File 'lib/stripe/resources/charge.rb', line 2336

def transfer
  @transfer
end

#transfer_dataObject (readonly)

An optional dictionary including the account to automatically transfer to as part of a destination charge. See the Connect documentation for details.



2338
2339
2340
# File 'lib/stripe/resources/charge.rb', line 2338

def transfer_data
  @transfer_data
end

#transfer_groupObject (readonly)

A string that identifies this transaction as part of a group. See the Connect documentation for details.



2340
2341
2342
# File 'lib/stripe/resources/charge.rb', line 2340

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), 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.



2361
2362
2363
2364
2365
2366
2367
2368
# File 'lib/stripe/resources/charge.rb', line 2361

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 to initiate a new payment instead. Confirmation of the PaymentIntent creates the Charge object used to request payment.



2373
2374
2375
# File 'lib/stripe/resources/charge.rb', line 2373

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

.field_remappingsObject



2414
2415
2416
# File 'lib/stripe/resources/charge.rb', line 2414

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
# File 'lib/stripe/resources/charge.rb', line 2400

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.



2378
2379
2380
# File 'lib/stripe/resources/charge.rb', line 2378

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

.object_nameObject



16
17
18
# File 'lib/stripe/resources/charge.rb', line 16

def self.object_name
  "charge"
end

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



2382
2383
2384
# File 'lib/stripe/resources/charge.rb', line 2382

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



2386
2387
2388
# File 'lib/stripe/resources/charge.rb', line 2386

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.



2391
2392
2393
2394
2395
2396
2397
2398
# File 'lib/stripe/resources/charge.rb', line 2391

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), 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.



2347
2348
2349
2350
2351
2352
2353
2354
# File 'lib/stripe/resources/charge.rb', line 2347

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