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.

Constant Summary collapse

OBJECT_NAME =
"charge"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

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

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



42
43
44
45
46
47
48
49
# File 'lib/stripe/resources/charge.rb', line 42

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.



54
55
56
# File 'lib/stripe/resources/charge.rb', line 54

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.



59
60
61
# File 'lib/stripe/resources/charge.rb', line 59

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



63
64
65
# File 'lib/stripe/resources/charge.rb', line 63

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



67
68
69
# File 'lib/stripe/resources/charge.rb', line 67

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.



72
73
74
75
76
77
78
79
# File 'lib/stripe/resources/charge.rb', line 72

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



28
29
30
31
32
33
34
35
# File 'lib/stripe/resources/charge.rb', line 28

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