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 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, RadarOptions, RetrieveParams, SearchParams, Shipping, TransferData, UpdateParams

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

#==, #[], #[]=, 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

#amountObject (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).



2951
2952
2953
# File 'lib/stripe/resources/charge.rb', line 2951

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



2953
2954
2955
# File 'lib/stripe/resources/charge.rb', line 2953

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



2955
2956
2957
# File 'lib/stripe/resources/charge.rb', line 2955

def amount_refunded
  @amount_refunded
end

#applicationObject (readonly)

ID of the Connect application that created the charge.



2957
2958
2959
# File 'lib/stripe/resources/charge.rb', line 2957

def application
  @application
end

#application_feeObject (readonly)

The application fee (if any) for the charge. [See the Connect documentation](stripe.com/docs/connect/direct-charges#collect-fees) for details.



2959
2960
2961
# File 'lib/stripe/resources/charge.rb', line 2959

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](stripe.com/docs/connect/direct-charges#collect-fees) for details.



2961
2962
2963
# File 'lib/stripe/resources/charge.rb', line 2961

def application_fee_amount
  @application_fee_amount
end

#authorization_codeObject (readonly)

Authorization code on the charge.



2963
2964
2965
# File 'lib/stripe/resources/charge.rb', line 2963

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



2965
2966
2967
# File 'lib/stripe/resources/charge.rb', line 2965

def balance_transaction
  @balance_transaction
end

#billing_detailsObject (readonly)

Attribute for field billing_details



2967
2968
2969
# File 'lib/stripe/resources/charge.rb', line 2967

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.



2969
2970
2971
# File 'lib/stripe/resources/charge.rb', line 2969

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.



2971
2972
2973
# File 'lib/stripe/resources/charge.rb', line 2971

def captured
  @captured
end

#createdObject (readonly)

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



2973
2974
2975
# File 'lib/stripe/resources/charge.rb', line 2973

def created
  @created
end

#currencyObject (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).



2975
2976
2977
# File 'lib/stripe/resources/charge.rb', line 2975

def currency
  @currency
end

#customerObject (readonly)

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



2977
2978
2979
# File 'lib/stripe/resources/charge.rb', line 2977

def customer
  @customer
end

#descriptionObject (readonly)

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



2979
2980
2981
# File 'lib/stripe/resources/charge.rb', line 2979

def description
  @description
end

#disputedObject (readonly)

Whether the charge has been disputed.



2981
2982
2983
# File 'lib/stripe/resources/charge.rb', line 2981

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.



2983
2984
2985
# File 'lib/stripe/resources/charge.rb', line 2983

def failure_balance_transaction
  @failure_balance_transaction
end

#failure_codeObject (readonly)

Error code explaining reason for charge failure if available (see [the errors section](stripe.com/docs/error-codes) for a list of codes).



2985
2986
2987
# File 'lib/stripe/resources/charge.rb', line 2985

def failure_code
  @failure_code
end

#failure_messageObject (readonly)

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



2987
2988
2989
# File 'lib/stripe/resources/charge.rb', line 2987

def failure_message
  @failure_message
end

#fraud_detailsObject (readonly)

Information on fraud assessments for the charge.



2989
2990
2991
# File 'lib/stripe/resources/charge.rb', line 2989

def fraud_details
  @fraud_details
end

#idObject (readonly)

Unique identifier for the object.



2991
2992
2993
# File 'lib/stripe/resources/charge.rb', line 2991

def id
  @id
end

#invoiceObject (readonly)

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



2993
2994
2995
# File 'lib/stripe/resources/charge.rb', line 2993

def invoice
  @invoice
end

#level3Object (readonly)

Attribute for field level3



2995
2996
2997
# File 'lib/stripe/resources/charge.rb', line 2995

def level3
  @level3
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



2997
2998
2999
# File 'lib/stripe/resources/charge.rb', line 2997

def livemode
  @livemode
end

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



2999
3000
3001
# File 'lib/stripe/resources/charge.rb', line 2999

def 
  @metadata
end

#objectObject (readonly)

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



3001
3002
3003
# File 'lib/stripe/resources/charge.rb', line 3001

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](stripe.com/docs/connect/separate-charges-and-transfers) for details.



3003
3004
3005
# File 'lib/stripe/resources/charge.rb', line 3003

def on_behalf_of
  @on_behalf_of
end

#outcomeObject (readonly)

Details about whether the payment was accepted, and why. See [understanding declines](stripe.com/docs/declines) for details.



3005
3006
3007
# File 'lib/stripe/resources/charge.rb', line 3005

def outcome
  @outcome
end

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



3007
3008
3009
# File 'lib/stripe/resources/charge.rb', line 3007

def paid
  @paid
end

#payment_intentObject (readonly)

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



3009
3010
3011
# File 'lib/stripe/resources/charge.rb', line 3009

def payment_intent
  @payment_intent
end

#payment_methodObject (readonly)

ID of the payment method used in this charge.



3011
3012
3013
# File 'lib/stripe/resources/charge.rb', line 3011

def payment_method
  @payment_method
end

#payment_method_detailsObject (readonly)

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



3013
3014
3015
# File 'lib/stripe/resources/charge.rb', line 3013

def payment_method_details
  @payment_method_details
end

#radar_optionsObject (readonly)

Options to configure Radar. See [Radar Session](stripe.com/docs/radar/radar-session) for more information.



3015
3016
3017
# File 'lib/stripe/resources/charge.rb', line 3015

def radar_options
  @radar_options
end

#receipt_emailObject (readonly)

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



3017
3018
3019
# File 'lib/stripe/resources/charge.rb', line 3017

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.



3019
3020
3021
# File 'lib/stripe/resources/charge.rb', line 3019

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.



3021
3022
3023
# File 'lib/stripe/resources/charge.rb', line 3021

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.



3023
3024
3025
# File 'lib/stripe/resources/charge.rb', line 3023

def refunded
  @refunded
end

#refundsObject (readonly)

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



3025
3026
3027
# File 'lib/stripe/resources/charge.rb', line 3025

def refunds
  @refunds
end

#reviewObject (readonly)

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



3027
3028
3029
# File 'lib/stripe/resources/charge.rb', line 3027

def review
  @review
end

#shippingObject (readonly)

Shipping information for the charge.



3029
3030
3031
# File 'lib/stripe/resources/charge.rb', line 3029

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.



3031
3032
3033
# File 'lib/stripe/resources/charge.rb', line 3031

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](docs.stripe.com/connect/destination-charges) for details.



3033
3034
3035
# File 'lib/stripe/resources/charge.rb', line 3033

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](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.



3037
3038
3039
# File 'lib/stripe/resources/charge.rb', line 3037

def statement_descriptor
  @statement_descriptor
end

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



3039
3040
3041
# File 'lib/stripe/resources/charge.rb', line 3039

def statement_descriptor_suffix
  @statement_descriptor_suffix
end

#statusObject (readonly)

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



3041
3042
3043
# File 'lib/stripe/resources/charge.rb', line 3041

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



3043
3044
3045
# File 'lib/stripe/resources/charge.rb', line 3043

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](stripe.com/docs/connect/destination-charges) for details.



3045
3046
3047
# File 'lib/stripe/resources/charge.rb', line 3045

def transfer_data
  @transfer_data
end

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



3047
3048
3049
# File 'lib/stripe/resources/charge.rb', line 3047

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](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](stripe.com/docs/api/payment_intents/capture).



3068
3069
3070
3071
3072
3073
3074
3075
# File 'lib/stripe/resources/charge.rb', line 3068

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](stripe.com/docs/api/payment_intents) to initiate a new payment instead. Confirmation of the PaymentIntent creates the Charge object used to request payment.



3080
3081
3082
# File 'lib/stripe/resources/charge.rb', line 3080

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/charges", params: params, opts: opts)
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.



3085
3086
3087
# File 'lib/stripe/resources/charge.rb', line 3085

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

.object_nameObject



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

def self.object_name
  "charge"
end

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



3089
3090
3091
# File 'lib/stripe/resources/charge.rb', line 3089

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



3093
3094
3095
# File 'lib/stripe/resources/charge.rb', line 3093

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

.update(id, params = {}, opts = {}) ⇒ Object

Updates the specified charge by setting the values of the parameters passed. Any parameters not provided will be left unchanged.



3098
3099
3100
3101
3102
3103
3104
3105
# File 'lib/stripe/resources/charge.rb', line 3098

def self.update(id, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/charges/%<id>s", { id: CGI.escape(id) }),
    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](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](stripe.com/docs/api/payment_intents/capture).



3054
3055
3056
3057
3058
3059
3060
3061
# File 'lib/stripe/resources/charge.rb', line 3054

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