• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-ruby / #5867

18 Apr 2024 09:24PM UTC coverage: 92.724% (-4.8%) from 97.485%
#5867

push

github

ramya-stripe
Bump version to 11.2.0

10067 of 10857 relevant lines covered (92.72%)

258.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.63
/lib/stripe/resources/source.rb
1
# File generated from our OpenAPI spec
2
# frozen_string_literal: true
3

4
module Stripe
1✔
5
  # `Source` objects allow you to accept a variety of payment methods. They
6
  # represent a customer's payment instrument, and can be used with the Stripe API
7
  # just like a `Card` object: once chargeable, they can be charged, or can be
8
  # attached to customers.
9
  #
10
  # Stripe doesn't recommend using the deprecated [Sources API](https://stripe.com/docs/api/sources).
11
  # We recommend that you adopt the [PaymentMethods API](https://stripe.com/docs/api/payment_methods).
12
  # This newer API provides access to our latest features and payment method types.
13
  #
14
  # Related guides: [Sources API](https://stripe.com/docs/sources) and [Sources & Customers](https://stripe.com/docs/sources/customers).
15
  class Source < APIResource
1✔
16
    extend Stripe::APIOperations::Create
1✔
17
    extend Stripe::APIOperations::NestedResource
1✔
18
    include Stripe::APIOperations::Save
1✔
19

20
    OBJECT_NAME = "source"
1✔
21
    def self.object_name
1✔
22
      "source"
34✔
23
    end
24

25
    nested_resource_class_methods :source_transaction, operations: %i[retrieve list]
1✔
26

27
    # Creates a new source object.
28
    def self.create(params = {}, opts = {})
1✔
29
      request_stripe_object(method: :post, path: "/v1/sources", params: params, opts: opts)
1✔
30
    end
31

32
    # Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
33
    #
34
    # This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our [payment method guides](https://stripe.com/docs/sources) for more detail.
35
    def self.update(id, params = {}, opts = {})
1✔
36
      request_stripe_object(
2✔
37
        method: :post,
38
        path: format("/v1/sources/%<id>s", { id: CGI.escape(id) }),
1✔
39
        params: params,
40
        opts: opts
41
      )
42
    end
43

44
    # Verify a given source.
45
    def verify(params = {}, opts = {})
1✔
46
      request_stripe_object(
1✔
47
        method: :post,
48
        path: format("/v1/sources/%<source>s/verify", { source: CGI.escape(self["id"]) }),
×
49
        params: params,
50
        opts: opts
51
      )
52
    end
53

54
    # Verify a given source.
55
    def self.verify(source, params = {}, opts = {})
1✔
56
      request_stripe_object(
1✔
57
        method: :post,
58
        path: format("/v1/sources/%<source>s/verify", { source: CGI.escape(source) }),
×
59
        params: params,
60
        opts: opts
61
      )
62
    end
63

64
    def detach(params = {}, opts = {})
1✔
65
      if !respond_to?(:customer) || customer.nil? || customer.empty?
2✔
66
        raise NotImplementedError,
1✔
67
              "This source object does not appear to be currently attached " \
68
              "to a customer object."
69
      end
70

71
      url = "#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
1✔
72
            "/#{CGI.escape(id)}"
1✔
73
      resp, opts = execute_resource_request(:delete, url, params, opts)
1✔
74
      initialize_from(resp.data, opts)
1✔
75
    end
76

77
    def source_transactions(params = {}, opts = {})
1✔
78
      request_stripe_object(
1✔
79
        method: :get,
80
        path: resource_url + "/source_transactions",
×
81
        params: params,
82
        opts: opts
83
      )
84
    end
85
    extend Gem::Deprecate
1✔
86
    deprecate :source_transactions, :"Source.list_source_transactions", 2020, 1
1✔
87
  end
88
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc