stripe 5.41.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +256 -0
  3. data/Gemfile +5 -2
  4. data/Makefile +13 -0
  5. data/OPENAPI_VERSION +1 -0
  6. data/README.md +40 -6
  7. data/VERSION +1 -1
  8. data/lib/data/ca-certificates.crt +1241 -1937
  9. data/lib/stripe/api_operations/create.rb +6 -2
  10. data/lib/stripe/api_operations/delete.rb +12 -7
  11. data/lib/stripe/api_operations/list.rb +6 -9
  12. data/lib/stripe/api_operations/nested_resource.rb +62 -34
  13. data/lib/stripe/api_operations/request.rb +10 -0
  14. data/lib/stripe/api_operations/save.rb +13 -3
  15. data/lib/stripe/api_operations/search.rb +16 -0
  16. data/lib/stripe/api_resource.rb +3 -18
  17. data/lib/stripe/api_resource_test_helpers.rb +49 -0
  18. data/lib/stripe/api_version.rb +8 -0
  19. data/lib/stripe/connection_manager.rb +22 -1
  20. data/lib/stripe/instrumentation.rb +45 -7
  21. data/lib/stripe/object_types.rb +29 -10
  22. data/lib/stripe/resources/account.rb +36 -9
  23. data/lib/stripe/resources/account_link.rb +4 -0
  24. data/lib/stripe/resources/application_fee_refund.rb +5 -0
  25. data/lib/stripe/resources/apps/secret.rb +40 -0
  26. data/lib/stripe/resources/balance.rb +11 -0
  27. data/lib/stripe/resources/balance_transaction.rb +4 -0
  28. data/lib/stripe/resources/bank_account.rb +7 -0
  29. data/lib/stripe/resources/billing_portal/configuration.rb +1 -0
  30. data/lib/stripe/resources/billing_portal/session.rb +14 -0
  31. data/lib/stripe/resources/capability.rb +3 -0
  32. data/lib/stripe/resources/card.rb +6 -3
  33. data/lib/stripe/resources/cash_balance.rb +23 -0
  34. data/lib/stripe/resources/charge.rb +23 -3
  35. data/lib/stripe/resources/checkout/session.rb +41 -5
  36. data/lib/stripe/resources/country_spec.rb +6 -0
  37. data/lib/stripe/resources/coupon.rb +3 -0
  38. data/lib/stripe/resources/credit_note.rb +27 -9
  39. data/lib/stripe/resources/credit_note_line_item.rb +1 -0
  40. data/lib/stripe/resources/customer.rb +124 -12
  41. data/lib/stripe/resources/customer_balance_transaction.rb +6 -0
  42. data/lib/stripe/resources/customer_cash_balance_transaction.rb +14 -0
  43. data/lib/stripe/resources/discount.rb +4 -0
  44. data/lib/stripe/resources/dispute.rb +17 -3
  45. data/lib/stripe/resources/event.rb +29 -0
  46. data/lib/stripe/resources/exchange_rate.rb +11 -0
  47. data/lib/stripe/resources/file.rb +7 -0
  48. data/lib/stripe/resources/file_link.rb +3 -0
  49. data/lib/stripe/resources/financial_connections/account.rb +67 -0
  50. data/lib/stripe/resources/financial_connections/account_owner.rb +11 -0
  51. data/lib/stripe/resources/financial_connections/account_ownership.rb +11 -0
  52. data/lib/stripe/resources/financial_connections/session.rb +13 -0
  53. data/lib/stripe/resources/funding_instructions.rb +21 -0
  54. data/lib/stripe/resources/identity/verification_report.rb +11 -0
  55. data/lib/stripe/resources/identity/verification_session.rb +31 -5
  56. data/lib/stripe/resources/invoice.rb +105 -17
  57. data/lib/stripe/resources/invoice_item.rb +11 -0
  58. data/lib/stripe/resources/issuing/authorization.rb +25 -5
  59. data/lib/stripe/resources/issuing/card.rb +78 -8
  60. data/lib/stripe/resources/issuing/cardholder.rb +3 -0
  61. data/lib/stripe/resources/issuing/dispute.rb +13 -3
  62. data/lib/stripe/resources/issuing/transaction.rb +5 -0
  63. data/lib/stripe/resources/line_item.rb +1 -0
  64. data/lib/stripe/resources/login_link.rb +1 -0
  65. data/lib/stripe/resources/mandate.rb +1 -0
  66. data/lib/stripe/resources/payment_intent.rb +103 -6
  67. data/lib/stripe/resources/payment_link.rb +35 -0
  68. data/lib/stripe/resources/payment_method.rb +25 -5
  69. data/lib/stripe/resources/payout.rb +28 -5
  70. data/lib/stripe/resources/person.rb +6 -0
  71. data/lib/stripe/resources/plan.rb +8 -0
  72. data/lib/stripe/resources/price.rb +15 -0
  73. data/lib/stripe/resources/product.rb +17 -0
  74. data/lib/stripe/resources/promotion_code.rb +2 -0
  75. data/lib/stripe/resources/quote.rb +58 -35
  76. data/lib/stripe/resources/radar/early_fraud_warning.rb +4 -0
  77. data/lib/stripe/resources/radar/value_list.rb +3 -0
  78. data/lib/stripe/resources/radar/value_list_item.rb +3 -0
  79. data/lib/stripe/resources/refund.rb +49 -0
  80. data/lib/stripe/resources/reporting/report_run.rb +8 -0
  81. data/lib/stripe/resources/reporting/report_type.rb +8 -1
  82. data/lib/stripe/resources/reversal.rb +13 -0
  83. data/lib/stripe/resources/review.rb +14 -3
  84. data/lib/stripe/resources/setup_attempt.rb +4 -0
  85. data/lib/stripe/resources/setup_intent.rb +60 -5
  86. data/lib/stripe/resources/shipping_rate.rb +2 -0
  87. data/lib/stripe/resources/sigma/scheduled_query_run.rb +4 -0
  88. data/lib/stripe/resources/source.rb +26 -6
  89. data/lib/stripe/resources/source_transaction.rb +4 -0
  90. data/lib/stripe/resources/subscription.rb +57 -3
  91. data/lib/stripe/resources/subscription_item.rb +2 -7
  92. data/lib/stripe/resources/subscription_schedule.rb +23 -5
  93. data/lib/stripe/resources/tax/calculation.rb +33 -0
  94. data/lib/stripe/resources/tax/calculation_line_item.rb +10 -0
  95. data/lib/stripe/resources/tax/settings.rb +15 -0
  96. data/lib/stripe/resources/tax/transaction.rb +49 -0
  97. data/lib/stripe/resources/tax/transaction_line_item.rb +10 -0
  98. data/lib/stripe/resources/tax_code.rb +1 -0
  99. data/lib/stripe/resources/tax_id.rb +4 -0
  100. data/lib/stripe/resources/tax_rate.rb +3 -0
  101. data/lib/stripe/resources/terminal/configuration.rb +16 -0
  102. data/lib/stripe/resources/terminal/connection_token.rb +3 -0
  103. data/lib/stripe/resources/terminal/location.rb +3 -0
  104. data/lib/stripe/resources/terminal/reader.rb +119 -0
  105. data/lib/stripe/resources/test_helpers/test_clock.rb +35 -0
  106. data/lib/stripe/resources/token.rb +20 -0
  107. data/lib/stripe/resources/topup.rb +15 -3
  108. data/lib/stripe/resources/transfer.rb +10 -11
  109. data/lib/stripe/resources/treasury/credit_reversal.rb +14 -0
  110. data/lib/stripe/resources/treasury/debit_reversal.rb +14 -0
  111. data/lib/stripe/resources/treasury/financial_account.rb +52 -0
  112. data/lib/stripe/resources/treasury/financial_account_features.rb +12 -0
  113. data/lib/stripe/resources/treasury/inbound_transfer.rb +94 -0
  114. data/lib/stripe/resources/treasury/outbound_payment.rb +96 -0
  115. data/lib/stripe/resources/treasury/outbound_transfer.rb +100 -0
  116. data/lib/stripe/resources/treasury/received_credit.rb +30 -0
  117. data/lib/stripe/resources/treasury/received_debit.rb +30 -0
  118. data/lib/stripe/resources/treasury/transaction.rb +13 -0
  119. data/lib/stripe/resources/treasury/transaction_entry.rb +17 -0
  120. data/lib/stripe/resources/usage_record.rb +4 -0
  121. data/lib/stripe/resources/webhook_endpoint.rb +7 -0
  122. data/lib/stripe/resources.rb +27 -10
  123. data/lib/stripe/search_result_object.rb +86 -0
  124. data/lib/stripe/stripe_client.rb +37 -22
  125. data/lib/stripe/stripe_configuration.rb +5 -1
  126. data/lib/stripe/stripe_object.rb +2 -2
  127. data/lib/stripe/util.rb +85 -2
  128. data/lib/stripe/version.rb +1 -1
  129. data/lib/stripe.rb +5 -1
  130. data/stripe.gemspec +3 -3
  131. metadata +39 -14
  132. data/lib/stripe/resources/bitcoin_receiver.rb +0 -24
  133. data/lib/stripe/resources/bitcoin_transaction.rb +0 -16
  134. data/lib/stripe/resources/issuing/card_details.rb +0 -10
  135. data/lib/stripe/resources/order.rb +0 -33
  136. data/lib/stripe/resources/order_return.rb +0 -10
  137. data/lib/stripe/resources/recipient.rb +0 -14
  138. data/lib/stripe/resources/sku.rb +0 -13
  139. data/lib/stripe/resources/three_d_secure.rb +0 -14
@@ -0,0 +1,30 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Treasury
6
+ # ReceivedCredits represent funds sent to a [FinancialAccount](https://stripe.com/docs/api#financial_accounts) (for example, via ACH or wire). These money movements are not initiated from the FinancialAccount.
7
+ class ReceivedCredit < APIResource
8
+ extend Stripe::APIOperations::List
9
+
10
+ OBJECT_NAME = "treasury.received_credit"
11
+
12
+ def test_helpers
13
+ TestHelpers.new(self)
14
+ end
15
+
16
+ class TestHelpers < APIResourceTestHelpers
17
+ RESOURCE_CLASS = ReceivedCredit
18
+
19
+ def self.create(params = {}, opts = {})
20
+ request_stripe_object(
21
+ method: :post,
22
+ path: "/v1/test_helpers/treasury/received_credits",
23
+ params: params,
24
+ opts: opts
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Treasury
6
+ # ReceivedDebits represent funds pulled from a [FinancialAccount](https://stripe.com/docs/api#financial_accounts). These are not initiated from the FinancialAccount.
7
+ class ReceivedDebit < APIResource
8
+ extend Stripe::APIOperations::List
9
+
10
+ OBJECT_NAME = "treasury.received_debit"
11
+
12
+ def test_helpers
13
+ TestHelpers.new(self)
14
+ end
15
+
16
+ class TestHelpers < APIResourceTestHelpers
17
+ RESOURCE_CLASS = ReceivedDebit
18
+
19
+ def self.create(params = {}, opts = {})
20
+ request_stripe_object(
21
+ method: :post,
22
+ path: "/v1/test_helpers/treasury/received_debits",
23
+ params: params,
24
+ opts: opts
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Treasury
6
+ # Transactions represent changes to a [FinancialAccount's](https://stripe.com/docs/api#financial_accounts) balance.
7
+ class Transaction < APIResource
8
+ extend Stripe::APIOperations::List
9
+
10
+ OBJECT_NAME = "treasury.transaction"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # File generated from our OpenAPI spec
2
+ # frozen_string_literal: true
3
+
4
+ module Stripe
5
+ module Treasury
6
+ # TransactionEntries represent individual units of money movements within a single [Transaction](https://stripe.com/docs/api#transactions).
7
+ class TransactionEntry < APIResource
8
+ extend Stripe::APIOperations::List
9
+
10
+ OBJECT_NAME = "treasury.transaction_entry"
11
+
12
+ def self.resource_url
13
+ "/v1/treasury/transaction_entries"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,6 +2,10 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # Usage records allow you to report customer usage and metrics to Stripe for
6
+ # metered billing of subscription prices.
7
+ #
8
+ # Related guide: [Metered billing](https://stripe.com/docs/billing/subscriptions/metered-billing)
5
9
  class UsageRecord < APIResource
6
10
  OBJECT_NAME = "usage_record"
7
11
  end
@@ -2,6 +2,13 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
+ # You can configure [webhook endpoints](https://stripe.com/docs/webhooks/) via the API to be
6
+ # notified about events that happen in your Stripe account or connected
7
+ # accounts.
8
+ #
9
+ # Most users configure webhooks from [the dashboard](https://dashboard.stripe.com/webhooks), which provides a user interface for registering and testing your webhook endpoints.
10
+ #
11
+ # Related guide: [Setting up webhooks](https://stripe.com/docs/webhooks/configure)
5
12
  class WebhookEndpoint < APIResource
6
13
  extend Stripe::APIOperations::Create
7
14
  include Stripe::APIOperations::Delete
@@ -3,19 +3,18 @@
3
3
 
4
4
  require "stripe/resources/account"
5
5
  require "stripe/resources/account_link"
6
- require "stripe/resources/alipay_account"
7
6
  require "stripe/resources/apple_pay_domain"
8
7
  require "stripe/resources/application_fee"
9
8
  require "stripe/resources/application_fee_refund"
9
+ require "stripe/resources/apps/secret"
10
10
  require "stripe/resources/balance"
11
11
  require "stripe/resources/balance_transaction"
12
12
  require "stripe/resources/bank_account"
13
13
  require "stripe/resources/billing_portal/configuration"
14
14
  require "stripe/resources/billing_portal/session"
15
- require "stripe/resources/bitcoin_receiver"
16
- require "stripe/resources/bitcoin_transaction"
17
15
  require "stripe/resources/capability"
18
16
  require "stripe/resources/card"
17
+ require "stripe/resources/cash_balance"
19
18
  require "stripe/resources/charge"
20
19
  require "stripe/resources/checkout/session"
21
20
  require "stripe/resources/country_spec"
@@ -24,6 +23,7 @@ require "stripe/resources/credit_note"
24
23
  require "stripe/resources/credit_note_line_item"
25
24
  require "stripe/resources/customer"
26
25
  require "stripe/resources/customer_balance_transaction"
26
+ require "stripe/resources/customer_cash_balance_transaction"
27
27
  require "stripe/resources/discount"
28
28
  require "stripe/resources/dispute"
29
29
  require "stripe/resources/ephemeral_key"
@@ -31,6 +31,11 @@ require "stripe/resources/event"
31
31
  require "stripe/resources/exchange_rate"
32
32
  require "stripe/resources/file"
33
33
  require "stripe/resources/file_link"
34
+ require "stripe/resources/financial_connections/account"
35
+ require "stripe/resources/financial_connections/account_owner"
36
+ require "stripe/resources/financial_connections/account_ownership"
37
+ require "stripe/resources/financial_connections/session"
38
+ require "stripe/resources/funding_instructions"
34
39
  require "stripe/resources/identity/verification_report"
35
40
  require "stripe/resources/identity/verification_session"
36
41
  require "stripe/resources/invoice"
@@ -38,16 +43,14 @@ require "stripe/resources/invoice_item"
38
43
  require "stripe/resources/invoice_line_item"
39
44
  require "stripe/resources/issuing/authorization"
40
45
  require "stripe/resources/issuing/card"
41
- require "stripe/resources/issuing/card_details"
42
46
  require "stripe/resources/issuing/cardholder"
43
47
  require "stripe/resources/issuing/dispute"
44
48
  require "stripe/resources/issuing/transaction"
45
49
  require "stripe/resources/line_item"
46
50
  require "stripe/resources/login_link"
47
51
  require "stripe/resources/mandate"
48
- require "stripe/resources/order"
49
- require "stripe/resources/order_return"
50
52
  require "stripe/resources/payment_intent"
53
+ require "stripe/resources/payment_link"
51
54
  require "stripe/resources/payment_method"
52
55
  require "stripe/resources/payout"
53
56
  require "stripe/resources/person"
@@ -59,8 +62,6 @@ require "stripe/resources/quote"
59
62
  require "stripe/resources/radar/early_fraud_warning"
60
63
  require "stripe/resources/radar/value_list"
61
64
  require "stripe/resources/radar/value_list_item"
62
- require "stripe/resources/recipient"
63
- require "stripe/resources/recipient_transfer"
64
65
  require "stripe/resources/refund"
65
66
  require "stripe/resources/reporting/report_run"
66
67
  require "stripe/resources/reporting/report_type"
@@ -70,22 +71,38 @@ require "stripe/resources/setup_attempt"
70
71
  require "stripe/resources/setup_intent"
71
72
  require "stripe/resources/shipping_rate"
72
73
  require "stripe/resources/sigma/scheduled_query_run"
73
- require "stripe/resources/sku"
74
74
  require "stripe/resources/source"
75
75
  require "stripe/resources/source_transaction"
76
76
  require "stripe/resources/subscription"
77
77
  require "stripe/resources/subscription_item"
78
78
  require "stripe/resources/subscription_schedule"
79
+ require "stripe/resources/tax/calculation"
80
+ require "stripe/resources/tax/calculation_line_item"
81
+ require "stripe/resources/tax/settings"
82
+ require "stripe/resources/tax/transaction"
83
+ require "stripe/resources/tax/transaction_line_item"
79
84
  require "stripe/resources/tax_code"
80
85
  require "stripe/resources/tax_id"
81
86
  require "stripe/resources/tax_rate"
87
+ require "stripe/resources/terminal/configuration"
82
88
  require "stripe/resources/terminal/connection_token"
83
89
  require "stripe/resources/terminal/location"
84
90
  require "stripe/resources/terminal/reader"
85
- require "stripe/resources/three_d_secure"
91
+ require "stripe/resources/test_helpers/test_clock"
86
92
  require "stripe/resources/token"
87
93
  require "stripe/resources/topup"
88
94
  require "stripe/resources/transfer"
95
+ require "stripe/resources/treasury/credit_reversal"
96
+ require "stripe/resources/treasury/debit_reversal"
97
+ require "stripe/resources/treasury/financial_account"
98
+ require "stripe/resources/treasury/financial_account_features"
99
+ require "stripe/resources/treasury/inbound_transfer"
100
+ require "stripe/resources/treasury/outbound_payment"
101
+ require "stripe/resources/treasury/outbound_transfer"
102
+ require "stripe/resources/treasury/received_credit"
103
+ require "stripe/resources/treasury/received_debit"
104
+ require "stripe/resources/treasury/transaction"
105
+ require "stripe/resources/treasury/transaction_entry"
89
106
  require "stripe/resources/usage_record"
90
107
  require "stripe/resources/usage_record_summary"
91
108
  require "stripe/resources/webhook_endpoint"
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class SearchResultObject < StripeObject
5
+ include Enumerable
6
+ include Stripe::APIOperations::Search
7
+ include Stripe::APIOperations::Request
8
+
9
+ OBJECT_NAME = "search_result"
10
+
11
+ # This accessor allows a `SearchResultObject` to inherit various filters
12
+ # that were given to a predecessor. This allows for things like consistent
13
+ # limits, expansions, and predicates as a user pages through resources.
14
+ attr_accessor :filters
15
+
16
+ # An empty search result object. This is returned from +next+ when we know
17
+ # that there isn't a next page in order to replicate the behavior of the API
18
+ # when it attempts to return a page beyond the last.
19
+ def self.empty_search_result(opts = {})
20
+ SearchResultObject.construct_from({ data: [] }, opts)
21
+ end
22
+
23
+ def initialize(*args)
24
+ super
25
+ self.filters = {}
26
+ end
27
+
28
+ def [](key)
29
+ case key
30
+ when String, Symbol
31
+ super
32
+ else
33
+ raise ArgumentError,
34
+ "You tried to access the #{key.inspect} index, but " \
35
+ "SearchResultObject types only support String keys. " \
36
+ "(HINT: Search calls return an object with a 'data' (which is " \
37
+ "the data array). You likely want to call #data[#{key.inspect}])"
38
+ end
39
+ end
40
+
41
+ # Iterates through each resource in the page represented by the current
42
+ # `SearchListObject`.
43
+ #
44
+ # Note that this method makes no effort to fetch a new page when it gets to
45
+ # the end of the current page's resources. See also +auto_paging_each+.
46
+ def each(&blk)
47
+ data.each(&blk)
48
+ end
49
+
50
+ # Returns true if the page object contains no elements.
51
+ def empty?
52
+ data.empty?
53
+ end
54
+
55
+ # Iterates through each resource in all pages, making additional fetches to
56
+ # the API as necessary.
57
+ #
58
+ # Note that this method will make as many API calls as necessary to fetch
59
+ # all resources. For more granular control, please see +each+ and
60
+ # +next_search_result_page+.
61
+ def auto_paging_each(&blk)
62
+ return enum_for(:auto_paging_each) unless block_given?
63
+
64
+ page = self
65
+
66
+ loop do
67
+ page.each(&blk)
68
+ page = page.next_search_result_page
69
+
70
+ break if page.empty?
71
+ end
72
+ end
73
+
74
+ # Fetches the next page in the resource list (if there is one).
75
+ #
76
+ # This method will try to respect the limit of the current page. If none
77
+ # was given, the default limit will be fetched again.
78
+ def next_search_result_page(params = {}, opts = {})
79
+ return self.class.empty_search_result(opts) unless has_more
80
+
81
+ params = filters.merge(page: next_page).merge(params)
82
+
83
+ _search(url, params, opts)
84
+ end
85
+ end
86
+ end
@@ -494,15 +494,16 @@ module Stripe
494
494
  end
495
495
  end
496
496
 
497
- http_resp = execute_request_with_rescues(method, api_base, context) do
498
- self.class
499
- .default_connection_manager(config)
500
- .execute_request(method, url,
501
- body: body,
502
- headers: headers,
503
- query: query,
504
- &response_block)
505
- end
497
+ http_resp =
498
+ execute_request_with_rescues(method, api_base, headers, context) do
499
+ self.class
500
+ .default_connection_manager(config)
501
+ .execute_request(method, url,
502
+ body: body,
503
+ headers: headers,
504
+ query: query,
505
+ &response_block)
506
+ end
506
507
 
507
508
  [http_resp, api_key]
508
509
  end
@@ -564,7 +565,7 @@ module Stripe
564
565
  http_status >= 400
565
566
  end
566
567
 
567
- private def execute_request_with_rescues(method, api_base, context)
568
+ private def execute_request_with_rescues(method, api_base, headers, context)
568
569
  num_retries = 0
569
570
 
570
571
  begin
@@ -585,9 +586,9 @@ module Stripe
585
586
  handle_error_response(resp, context)
586
587
  end
587
588
 
588
- log_response(context, request_start, http_status, resp.body)
589
+ log_response(context, request_start, http_status, resp.body, resp)
589
590
  notify_request_end(context, request_duration, http_status,
590
- num_retries, user_data)
591
+ num_retries, user_data, resp, headers)
591
592
 
592
593
  if config.enable_telemetry? && context.request_id
593
594
  request_duration_ms = (request_duration * 1000).to_i
@@ -609,12 +610,12 @@ module Stripe
609
610
  error_context = context.dup_from_response_headers(e.http_headers)
610
611
  http_status = resp.code.to_i
611
612
  log_response(error_context, request_start,
612
- e.http_status, e.http_body)
613
+ e.http_status, e.http_body, resp)
613
614
  else
614
615
  log_response_error(error_context, request_start, e)
615
616
  end
616
617
  notify_request_end(context, request_duration, http_status, num_retries,
617
- user_data)
618
+ user_data, resp, headers)
618
619
 
619
620
  if self.class.should_retry?(e,
620
621
  method: method,
@@ -657,17 +658,24 @@ module Stripe
657
658
  end
658
659
 
659
660
  private def notify_request_end(context, duration, http_status, num_retries,
660
- user_data)
661
+ user_data, resp, headers)
661
662
  return if !Instrumentation.any_subscribers?(:request_end) &&
662
663
  !Instrumentation.any_subscribers?(:request)
663
664
 
664
- event = Instrumentation::RequestEndEvent.new(
665
+ request_context = Stripe::Instrumentation::RequestContext.new(
665
666
  duration: duration,
667
+ context: context,
668
+ header: headers
669
+ )
670
+ response_context = Stripe::Instrumentation::ResponseContext.new(
666
671
  http_status: http_status,
667
- method: context.method,
672
+ response: resp
673
+ )
674
+
675
+ event = Instrumentation::RequestEndEvent.new(
676
+ request_context: request_context,
677
+ response_context: response_context,
668
678
  num_retries: num_retries,
669
- path: context.path,
670
- request_id: context.request_id,
671
679
  user_data: user_data || {}
672
680
  )
673
681
  Stripe::Instrumentation.notify(:request_end, event)
@@ -903,10 +911,13 @@ module Stripe
903
911
  body: context.body,
904
912
  idempotency_key: context.idempotency_key,
905
913
  query: context.query,
906
- config: config)
914
+ config: config,
915
+ process_id: Process.pid,
916
+ thread_object_id: Thread.current.object_id,
917
+ log_timestamp: Util.monotonic_time)
907
918
  end
908
919
 
909
- private def log_response(context, request_start, status, body)
920
+ private def log_response(context, request_start, status, body, resp)
910
921
  Util.log_info("Response from Stripe API",
911
922
  account: context.account,
912
923
  api_version: context.api_version,
@@ -921,7 +932,11 @@ module Stripe
921
932
  body: body,
922
933
  idempotency_key: context.idempotency_key,
923
934
  request_id: context.request_id,
924
- config: config)
935
+ config: config,
936
+ process_id: Process.pid,
937
+ thread_object_id: Thread.current.object_id,
938
+ response_object_id: resp.object_id,
939
+ log_timestamp: Util.monotonic_time)
925
940
 
926
941
  return unless context.request_id
927
942
 
@@ -63,6 +63,7 @@ module Stripe
63
63
  end
64
64
 
65
65
  def initialize
66
+ @api_version = ApiVersion::CURRENT
66
67
  @ca_bundle_path = Stripe::DEFAULT_CA_BUNDLE_PATH
67
68
  @enable_telemetry = true
68
69
  @verify_ssl_certs = true
@@ -86,13 +87,16 @@ module Stripe
86
87
  val = Stripe::LEVEL_DEBUG
87
88
  elsif val == "info"
88
89
  val = Stripe::LEVEL_INFO
90
+ elsif val == "error"
91
+ val = Stripe::LEVEL_ERROR
89
92
  end
90
93
 
91
94
  levels = [Stripe::LEVEL_INFO, Stripe::LEVEL_DEBUG, Stripe::LEVEL_ERROR]
92
95
 
93
96
  if !val.nil? && !levels.include?(val)
94
97
  raise ArgumentError,
95
- "log_level should only be set to `nil`, `debug` or `info`"
98
+ "log_level should only be set to `nil`, `debug`, `info`," \
99
+ " or `error`"
96
100
  end
97
101
  @log_level = val
98
102
  end
@@ -429,13 +429,13 @@ module Stripe
429
429
  # * +:opts:+ Options for StripeObject like an API key.
430
430
  # * +:partial:+ Indicates that the re-initialization should not attempt to
431
431
  # remove accessors.
432
- protected def initialize_from(values, opts, partial = false)
432
+ protected def initialize_from(values, opts)
433
433
  @opts = Util.normalize_opts(opts)
434
434
 
435
435
  # the `#send` is here so that we can keep this method private
436
436
  @original_values = self.class.send(:deep_copy, values)
437
437
 
438
- removed = partial ? Set.new : Set.new(@values.keys - values.keys)
438
+ removed = Set.new(@values.keys - values.keys)
439
439
  added = Set.new(values.keys - @values.keys)
440
440
 
441
441
  # Wipe old state before setting new. This is useful for e.g. updating a
data/lib/stripe/util.rb CHANGED
@@ -47,6 +47,53 @@ module Stripe
47
47
  Util.object_classes[object_name] == klass
48
48
  end
49
49
 
50
+ # Adds a custom method to a resource class. This is used to add support for
51
+ # non-CRUDL API requests, e.g. capturing charges. custom_method takes the
52
+ # following parameters:
53
+ # - name: the name of the custom method to create (as a symbol)
54
+ # - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
55
+ # - http_path: the path to append to the resource's URL. If not provided,
56
+ # the name is used as the path
57
+ # - resource: the resource implementation class
58
+ # - target: the class that custom static method will be added to
59
+ #
60
+ # For example, this call:
61
+ # custom_method :capture, http_verb: post
62
+ # adds a `capture` class method to the resource class that, when called,
63
+ # will send a POST request to `/v1/<object_name>/capture`.
64
+ def self.custom_method(resource, target, name, http_verb, http_path)
65
+ unless %i[get post delete].include?(http_verb)
66
+ raise ArgumentError,
67
+ "Invalid http_verb value: #{http_verb.inspect}. Should be one " \
68
+ "of :get, :post or :delete."
69
+ end
70
+ unless target.respond_to?(:resource_url)
71
+ raise ArgumentError,
72
+ "Invalid target value: #{target}. Target class should have a " \
73
+ "`resource_url` method."
74
+ end
75
+ http_path ||= name.to_s
76
+ target.define_singleton_method(name) do |id, params = {}, opts = {}|
77
+ unless id.is_a?(String)
78
+ raise ArgumentError,
79
+ "id should be a string representing the ID of an API resource"
80
+ end
81
+
82
+ url = "#{target.resource_url}/"\
83
+ "#{CGI.escape(id)}/"\
84
+ "#{CGI.escape(http_path)}"
85
+
86
+ resp, opts = resource.execute_resource_request(
87
+ http_verb,
88
+ url,
89
+ params,
90
+ opts
91
+ )
92
+
93
+ Util.convert_to_stripe_object_with_params(resp.data, params, opts)
94
+ end
95
+ end
96
+
50
97
  # Converts a hash of fields or an array of hashes into a +StripeObject+ or
51
98
  # array of +StripeObject+s. These new objects will be created as a concrete
52
99
  # type as dictated by their `object` field (e.g. an `object` value of
@@ -57,9 +104,27 @@ module Stripe
57
104
  # ==== Attributes
58
105
  #
59
106
  # * +data+ - Hash of fields and values to be converted into a StripeObject.
107
+ # * +params+ - Params for +StripeObject+ like filters used in search that
108
+ # will be reused on subsequent API calls.
60
109
  # * +opts+ - Options for +StripeObject+ like an API key that will be reused
61
110
  # on subsequent API calls.
62
111
  def self.convert_to_stripe_object(data, opts = {})
112
+ convert_to_stripe_object_with_params(data, {}, opts)
113
+ end
114
+
115
+ # Converts a hash of fields or an array of hashes into a +StripeObject+ or
116
+ # array of +StripeObject+s. These new objects will be created as a concrete
117
+ # type as dictated by their `object` field (e.g. an `object` value of
118
+ # `charge` would create an instance of +Charge+), but if `object` is not
119
+ # present or of an unknown type, the newly created instance will fall back
120
+ # to being a +StripeObject+.
121
+ #
122
+ # ==== Attributes
123
+ #
124
+ # * +data+ - Hash of fields and values to be converted into a StripeObject.
125
+ # * +opts+ - Options for +StripeObject+ like an API key that will be reused
126
+ # on subsequent API calls.
127
+ def self.convert_to_stripe_object_with_params(data, params, opts = {})
63
128
  opts = normalize_opts(opts)
64
129
 
65
130
  case data
@@ -68,8 +133,17 @@ module Stripe
68
133
  when Hash
69
134
  # Try converting to a known object class. If none available, fall back
70
135
  # to generic StripeObject
71
- object_classes.fetch(data[:object], StripeObject)
72
- .construct_from(data, opts)
136
+ object_name = data[:object] || data["object"]
137
+ obj = object_classes.fetch(object_name, StripeObject)
138
+ .construct_from(data, opts)
139
+
140
+ # set filters so that we can fetch the same limit, expansions, and
141
+ # predicates when accessing the next and previous pages
142
+ if obj && (obj.is_a?(SearchResultObject) || obj.is_a?(ListObject))
143
+ obj.filters = params.dup
144
+ end
145
+
146
+ obj
73
147
  else
74
148
  data
75
149
  end
@@ -343,6 +417,15 @@ module Stripe
343
417
  # Hopefully val is a string, but protect in case it's not.
344
418
  val = val.to_s
345
419
 
420
+ # Some values returned by the server are encoded in ASCII-8BIT before
421
+ # being parsed as UTF-8 by Marshal. If we don't transform these here, then
422
+ # puts will fail as it tries to render UTF-8 characters as ASCII-8BIT
423
+ # which is not valid.
424
+ if val && val.encoding == Encoding::ASCII_8BIT
425
+ # Dup the string as it is a frozen literal.
426
+ val = val.dup.force_encoding("UTF-8")
427
+ end
428
+
346
429
  if %r{[^\w\-/]} =~ val
347
430
  # If the string contains any special characters, escape any double
348
431
  # quotes it has, remove newlines, and wrap the whole thing in quotes.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "5.41.0"
4
+ VERSION = "9.0.0"
5
5
  end
data/lib/stripe.rb CHANGED
@@ -15,6 +15,7 @@ require "uri"
15
15
  require "forwardable"
16
16
 
17
17
  # Version
18
+ require "stripe/api_version"
18
19
  require "stripe/version"
19
20
 
20
21
  # API operations
@@ -24,6 +25,7 @@ require "stripe/api_operations/list"
24
25
  require "stripe/api_operations/nested_resource"
25
26
  require "stripe/api_operations/request"
26
27
  require "stripe/api_operations/save"
28
+ require "stripe/api_operations/search"
27
29
 
28
30
  # API resource support classes
29
31
  require "stripe/errors"
@@ -35,8 +37,10 @@ require "stripe/stripe_client"
35
37
  require "stripe/stripe_object"
36
38
  require "stripe/stripe_response"
37
39
  require "stripe/list_object"
40
+ require "stripe/search_result_object"
38
41
  require "stripe/error_object"
39
42
  require "stripe/api_resource"
43
+ require "stripe/api_resource_test_helpers"
40
44
  require "stripe/singleton_api_resource"
41
45
  require "stripe/webhook"
42
46
  require "stripe/stripe_configuration"
@@ -103,7 +107,7 @@ module Stripe
103
107
  # with API requests. Useful for plugin authors to identify their plugin when
104
108
  # communicating with Stripe.
105
109
  #
106
- # Takes a name and optional partner program ID, plugin URL, and version.
110
+ # Takes a name and optional partner program ID, plugin URL, and version.
107
111
  def self.set_app_info(name, partner_id: nil, url: nil, version: nil)
108
112
  @app_info = {
109
113
  name: name,
data/stripe.gemspec CHANGED
@@ -13,16 +13,16 @@ Gem::Specification.new do |s|
13
13
  "See https://stripe.com for details."
14
14
  s.author = "Stripe"
15
15
  s.email = "support@stripe.com"
16
- s.homepage = "https://stripe.com/docs/api/ruby"
16
+ s.homepage = "https://stripe.com/docs/api?lang=ruby"
17
17
  s.license = "MIT"
18
18
 
19
19
  s.metadata = {
20
20
  "bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues",
21
21
  "changelog_uri" =>
22
22
  "https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md",
23
- "documentation_uri" => "https://stripe.com/docs/api/ruby",
23
+ "documentation_uri" => "https://stripe.com/docs/api?lang=ruby",
24
24
  "github_repo" => "ssh://github.com/stripe/stripe-ruby",
25
- "homepage_uri" => "https://stripe.com/docs/api/ruby",
25
+ "homepage_uri" => "https://stripe.com/docs/api?lang=ruby",
26
26
  "source_code_uri" => "https://github.com/stripe/stripe-ruby",
27
27
  }
28
28