# File generated from our OpenAPI spec # frozen_string_literal: true module Stripe # 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. class Charge < APIResource extend Stripe::APIOperations::Create extend Stripe::APIOperations::List extend Stripe::APIOperations::Search include Stripe::APIOperations::Save OBJECT_NAME = "charge" def self.object_name "charge" end # 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](https://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](https://stripe.com/docs/api/payment_intents/capture). def capture(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/charges/%s/capture", { charge: CGI.escape(self["id"]) }), params: params, opts: opts ) end # 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](https://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](https://stripe.com/docs/api/payment_intents/capture). def self.capture(charge, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/charges/%s/capture", { charge: CGI.escape(charge) }), params: params, opts: opts ) end # This method is no longer recommended—use the [Payment Intents API](https://stripe.com/docs/api/payment_intents) # to initiate a new payment instead. Confirmation of the PaymentIntent creates the Charge # object used to request payment. def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/charges", params: params, opts: opts) end # Returns a list of charges you've previously created. The charges are returned in sorted order, with the most recent charges appearing first. def self.list(filters = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/charges", params: filters, opts: opts) end def self.search(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/charges/search", params: params, opts: opts) end def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end # Updates the specified charge by setting the values of the parameters passed. Any parameters not provided will be left unchanged. def self.update(id, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/charges/%s", { id: CGI.escape(id) }), params: params, opts: opts ) end end end