stripe 8.6.0.pre.beta.2 → 8.6.0.pre.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -1
  3. data/Gemfile +1 -2
  4. data/OPENAPI_VERSION +1 -1
  5. data/VERSION +1 -1
  6. data/lib/stripe/api_operations/request.rb +2 -0
  7. data/lib/stripe/api_version.rb +1 -0
  8. data/lib/stripe/request_signing_authenticator.rb +83 -0
  9. data/lib/stripe/resources/account_link.rb +1 -1
  10. data/lib/stripe/resources/account_session.rb +1 -1
  11. data/lib/stripe/resources/application_fee_refund.rb +1 -1
  12. data/lib/stripe/resources/apps/secret.rb +1 -1
  13. data/lib/stripe/resources/balance.rb +1 -1
  14. data/lib/stripe/resources/balance_transaction.rb +1 -1
  15. data/lib/stripe/resources/bank_account.rb +1 -1
  16. data/lib/stripe/resources/capability.rb +1 -1
  17. data/lib/stripe/resources/card.rb +1 -1
  18. data/lib/stripe/resources/charge.rb +1 -1
  19. data/lib/stripe/resources/checkout/session.rb +1 -1
  20. data/lib/stripe/resources/credit_note.rb +1 -1
  21. data/lib/stripe/resources/customer.rb +1 -1
  22. data/lib/stripe/resources/customer_balance_transaction.rb +2 -2
  23. data/lib/stripe/resources/discount.rb +1 -1
  24. data/lib/stripe/resources/dispute.rb +1 -1
  25. data/lib/stripe/resources/file.rb +1 -1
  26. data/lib/stripe/resources/financial_connections/account.rb +36 -0
  27. data/lib/stripe/resources/funding_instructions.rb +1 -1
  28. data/lib/stripe/resources/invoice.rb +1 -1
  29. data/lib/stripe/resources/issuing/authorization.rb +1 -1
  30. data/lib/stripe/resources/issuing/cardholder.rb +1 -1
  31. data/lib/stripe/resources/issuing/dispute.rb +1 -1
  32. data/lib/stripe/resources/issuing/transaction.rb +1 -1
  33. data/lib/stripe/resources/payment_intent.rb +1 -1
  34. data/lib/stripe/resources/payout.rb +1 -1
  35. data/lib/stripe/resources/person.rb +1 -1
  36. data/lib/stripe/resources/radar/early_fraud_warning.rb +1 -1
  37. data/lib/stripe/resources/radar/value_list.rb +1 -1
  38. data/lib/stripe/resources/radar/value_list_item.rb +1 -1
  39. data/lib/stripe/resources/refund.rb +1 -1
  40. data/lib/stripe/resources/reversal.rb +1 -1
  41. data/lib/stripe/resources/setup_intent.rb +1 -1
  42. data/lib/stripe/resources/subscription.rb +1 -1
  43. data/lib/stripe/resources/subscription_schedule.rb +1 -1
  44. data/lib/stripe/resources/tax/calculation.rb +1 -1
  45. data/lib/stripe/resources/tax/registration.rb +3 -1
  46. data/lib/stripe/resources/tax/settings.rb +1 -1
  47. data/lib/stripe/resources/tax/transaction.rb +1 -1
  48. data/lib/stripe/resources/tax_id.rb +1 -1
  49. data/lib/stripe/resources/tax_rate.rb +1 -1
  50. data/lib/stripe/resources/terminal/connection_token.rb +1 -1
  51. data/lib/stripe/resources/terminal/location.rb +1 -1
  52. data/lib/stripe/resources/terminal/reader.rb +1 -1
  53. data/lib/stripe/resources/token.rb +1 -1
  54. data/lib/stripe/resources/topup.rb +1 -1
  55. data/lib/stripe/resources/transfer.rb +1 -1
  56. data/lib/stripe/resources/usage_record.rb +1 -1
  57. data/lib/stripe/resources/webhook_endpoint.rb +1 -1
  58. data/lib/stripe/stripe_client.rb +51 -18
  59. data/lib/stripe/stripe_configuration.rb +1 -0
  60. data/lib/stripe/util.rb +8 -1
  61. data/lib/stripe/version.rb +1 -1
  62. data/lib/stripe.rb +46 -0
  63. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b51765f7e0a00e3c7e757a9e7959af0511cd8a3b08b4514f6dd0cf465206f4a
4
- data.tar.gz: a735dda919d79edda717051b862bb6dd0767efc5ddf2293284be9e865c71d0d9
3
+ metadata.gz: 8e7519c6f28a8327b6653a879c443e420d3939b228d3ce7e26d78fb5059d2508
4
+ data.tar.gz: ec5c5dab4ae100c4266cb7f482edb7428498896412ef03a5879e2f53ce86010d
5
5
  SHA512:
6
- metadata.gz: 19a6751739586398a67de1384983910cf0c9ed6615264d409cbc3ef1ad729a799f4a1be5a6c3b1c20b3bd473150b2cedd7cca2786d2709c31b524b66e185cfbc
7
- data.tar.gz: 18ded4cf0d4466e896d1b8844949e8b3a6c7e03b4594cead22405604ca59afcdf027d1f72385745723ca49a261babdbf4eeef5859ac62cc6c00cc585aad60fa2
6
+ metadata.gz: f96ccd66620b95fc1727bce8d8bab15b5749049e21aa5276f6733c596aea93ab66074d03df67c118ef07cb598f625655fbb513d2288b6a517b300f2fb215aaef
7
+ data.tar.gz: 8163d80485ac0adc4797a52f22c832121cb690e0f7a07f35706be90bd2818be4ad3eb15bb464397defa9cca30b701f7c62d52ca8f48c6055eff3778bf29b4406
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.6.0-beta.4 - 2023-05-19
4
+ * [#1220](https://github.com/stripe/stripe-ruby/pull/1220) Update generated code for beta
5
+ * Add support for `subscribe` and `unsubscribe` methods on resource `FinancialConnections.Account`
6
+ * [#1217](https://github.com/stripe/stripe-ruby/pull/1217) Add raw_request
7
+ * [#1216](https://github.com/stripe/stripe-ruby/pull/1216) Update generated code for beta
8
+ * [#1214](https://github.com/stripe/stripe-ruby/pull/1214) Update generated code for beta
9
+
10
+
11
+ ## 8.6.0-beta.3 - 2023-04-17
12
+ * [#1211](https://github.com/stripe/stripe-ruby/pull/1211) Update generated code for beta
13
+ * [#1210](https://github.com/stripe/stripe-ruby/pull/1210), [#1212](https://github.com/stripe/stripe-ruby/pull/1212), [#1213](https://github.com/stripe/stripe-ruby/pull/1213) Add support for request signing
14
+
3
15
  ## 8.6.0-beta.2 - 2023-04-13
4
16
  * [#1206](https://github.com/stripe/stripe-ruby/pull/1206) Update generated code for beta
5
17
  * Add support for `collect_payment_method` and `confirm_payment_intent` methods on resource `Terminal.Reader`
@@ -12,7 +24,7 @@
12
24
 
13
25
  ## 8.5.0 - 2023-03-30
14
26
  * [#1203](https://github.com/stripe/stripe-ruby/pull/1203) Update generated code
15
- * Remove support for `create` method on resource `Tax.Transaction`
27
+ * Remove support for `create` method on resource `Tax.Transaction`
16
28
  * This is not a breaking change, as this method was deprecated before the Tax Transactions API was released in favor of the `create_from_calculation` method.
17
29
  * [#1201](https://github.com/stripe/stripe-ruby/pull/1201) Update save deprecation message
18
30
 
data/Gemfile CHANGED
@@ -10,8 +10,7 @@ group :development do
10
10
  gem "rack", ">= 2.0.6"
11
11
  gem "rake"
12
12
 
13
- # Update to 2.0.0 once it ships.
14
- gem "shoulda-context", "2.0.0.rc4"
13
+ gem "shoulda-context", "2.0.0"
15
14
 
16
15
  gem "test-unit"
17
16
 
data/OPENAPI_VERSION CHANGED
@@ -1 +1 @@
1
- v296
1
+ v351
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.6.0-beta.2
1
+ 8.6.0-beta.4
@@ -47,6 +47,7 @@ module Stripe
47
47
  api_key = headers.delete(:api_key)
48
48
  api_base = headers.delete(:api_base)
49
49
  client = headers.delete(:client)
50
+ api_mode = headers.delete(:api_mode)
50
51
  # Assume all remaining opts must be headers
51
52
 
52
53
  resp, opts[:api_key] = client.send(
@@ -54,6 +55,7 @@ module Stripe
54
55
  method, url,
55
56
  api_base: api_base, api_key: api_key,
56
57
  headers: headers, params: params,
58
+ api_mode: api_mode,
57
59
  &read_body_chunk_block
58
60
  )
59
61
 
@@ -4,5 +4,6 @@
4
4
  module Stripe
5
5
  module ApiVersion
6
6
  CURRENT = "2022-11-15"
7
+ PREVIEW = "2023-05-16.preview-v2"
7
8
  end
8
9
  end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class RequestSigningAuthenticator
5
+ AUTHORIZATION_HEADER_NAME = "Authorization"
6
+ CONTENT_TYPE_HEADER_NAME = "Content-Type"
7
+ STRIPE_CONTEXT_HEADER_NAME = "Stripe-Context"
8
+ STRIPE_ACCOUNT_HEADER_NAME = "Stripe-Account"
9
+ CONTENT_DIGEST_HEADER_NAME = "Content-Digest"
10
+ SIGNATURE_INPUT_HEADER_NAME = "Signature-Input"
11
+ SIGNATURE_HEADER_NAME = "Signature"
12
+
13
+ attr_reader :auth_token, :sign_lambda
14
+
15
+ def initialize(auth_token, sign_lambda)
16
+ unless auth_token.is_a?(String)
17
+ raise ArgumentError, "auth_token must be a string"
18
+ end
19
+ unless sign_lambda.is_a?(Proc)
20
+ raise ArgumentError, "sign_lambda must be a lambda"
21
+ end
22
+
23
+ @auth_token = auth_token
24
+ @sign_lambda = sign_lambda
25
+ end
26
+
27
+ def authenticate(method, headers, body)
28
+ covered_headers = [CONTENT_TYPE_HEADER_NAME,
29
+ CONTENT_DIGEST_HEADER_NAME,
30
+ STRIPE_CONTEXT_HEADER_NAME,
31
+ STRIPE_ACCOUNT_HEADER_NAME,
32
+ AUTHORIZATION_HEADER_NAME,]
33
+
34
+ headers[AUTHORIZATION_HEADER_NAME] = "STRIPE-V2-SIG #{auth_token}"
35
+
36
+ if method == :get
37
+ covered_headers -= [CONTENT_TYPE_HEADER_NAME,
38
+ CONTENT_DIGEST_HEADER_NAME,]
39
+ else
40
+ content = body || ""
41
+ headers[CONTENT_DIGEST_HEADER_NAME] =
42
+ %(sha-256=:#{content_digest(content)}:)
43
+ end
44
+
45
+ covered_headers_formatted = covered_headers
46
+ .map { |string| %("#{string.downcase}") }
47
+ .join(" ")
48
+
49
+ signature_input = "(#{covered_headers_formatted});created=#{created_time}"
50
+
51
+ inputs = covered_headers
52
+ .map { |header| %("#{header.downcase}": #{headers[header]}) }
53
+ .join("\n")
54
+
55
+ signature_base = %(#{inputs}\n"@signature-params": #{signature_input})
56
+ .encode(Encoding::UTF_8)
57
+
58
+ headers[SIGNATURE_INPUT_HEADER_NAME] = "sig1=#{signature_input}"
59
+
60
+ headers[SIGNATURE_HEADER_NAME] =
61
+ "sig1=:#{encoded_signature(signature_base)}:"
62
+ end
63
+
64
+ private def sign(signature_base)
65
+ @sign_lambda.call(signature_base)
66
+ end
67
+
68
+ private def encoded_signature(signature_base)
69
+ Base64.strict_encode64(sign(signature_base))
70
+ rescue StandardError
71
+ raise AuthenticationError, "Encountered '#{e.message} (#{e.class})' "\
72
+ "when calculating request signature."
73
+ end
74
+
75
+ private def content_digest(content)
76
+ Base64.strict_encode64(OpenSSL::Digest.new("SHA256").digest(content))
77
+ end
78
+
79
+ private def created_time
80
+ Time.now.to_i
81
+ end
82
+ end
83
+ end
@@ -5,7 +5,7 @@ module Stripe
5
5
  # Account Links are the means by which a Connect platform grants a connected account permission to access
6
6
  # Stripe-hosted applications, such as Connect Onboarding.
7
7
  #
8
- # Related guide: [Connect Onboarding](https://stripe.com/docs/connect/connect-onboarding).
8
+ # Related guide: [Connect Onboarding](https://stripe.com/docs/connect/connect-onboarding)
9
9
  class AccountLink < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
 
@@ -8,7 +8,7 @@ module Stripe
8
8
  # to your user. Do not save AccountSessions to your database as they expire relatively
9
9
  # quickly, and cannot be used more than once.
10
10
  #
11
- # Related guide: [Connect embedded components](https://stripe.com/docs/connect/get-started-connect-embedded-components).
11
+ # Related guide: [Connect embedded components](https://stripe.com/docs/connect/get-started-connect-embedded-components)
12
12
  class AccountSession < APIResource
13
13
  extend Stripe::APIOperations::Create
14
14
 
@@ -6,7 +6,7 @@ module Stripe
6
6
  # has previously been created but not yet refunded. Funds will be refunded to
7
7
  # the Stripe account from which the fee was originally collected.
8
8
  #
9
- # Related guide: [Refunding Application Fees](https://stripe.com/docs/connect/destination-charges#refunding-app-fee).
9
+ # Related guide: [Refunding application fees](https://stripe.com/docs/connect/destination-charges#refunding-app-fee)
10
10
  class ApplicationFeeRefund < APIResource
11
11
  extend Stripe::APIOperations::List
12
12
  include Stripe::APIOperations::Save
@@ -11,7 +11,7 @@ module Stripe
11
11
  #
12
12
  # A `user` scoped secret is accessible by the app backend and one specific Dashboard user. Use the `user` scope for per-user secrets like per-user OAuth tokens, where different users might have different permissions.
13
13
  #
14
- # Related guide: [Store data between page reloads](https://stripe.com/docs/stripe-apps/store-auth-data-custom-objects).
14
+ # Related guide: [Store data between page reloads](https://stripe.com/docs/stripe-apps/store-auth-data-custom-objects)
15
15
  class Secret < APIResource
16
16
  extend Stripe::APIOperations::Create
17
17
  extend Stripe::APIOperations::List
@@ -12,7 +12,7 @@ module Stripe
12
12
  # The available and pending amounts for each currency are broken down further by
13
13
  # payment source types.
14
14
  #
15
- # Related guide: [Understanding Connect Account Balances](https://stripe.com/docs/connect/account-balances).
15
+ # Related guide: [Understanding Connect account balances](https://stripe.com/docs/connect/account-balances)
16
16
  class Balance < SingletonAPIResource
17
17
  OBJECT_NAME = "balance"
18
18
  end
@@ -5,7 +5,7 @@ module Stripe
5
5
  # Balance transactions represent funds moving through your Stripe account.
6
6
  # They're created for every type of transaction that comes into or flows out of your Stripe account balance.
7
7
  #
8
- # Related guide: [Balance Transaction Types](https://stripe.com/docs/reports/balance-transaction-types).
8
+ # Related guide: [Balance transaction types](https://stripe.com/docs/reports/balance-transaction-types)
9
9
  class BalanceTransaction < APIResource
10
10
  extend Stripe::APIOperations::List
11
11
 
@@ -8,7 +8,7 @@ module Stripe
8
8
  # destinations on `Account` objects for [Custom accounts](https://stripe.com/docs/connect/custom-accounts).
9
9
  # They can be bank accounts or debit cards as well, and are documented in the links above.
10
10
  #
11
- # Related guide: [Bank Debits and Transfers](https://stripe.com/docs/payments/bank-debits-transfers).
11
+ # Related guide: [Bank debits and transfers](https://stripe.com/docs/payments/bank-debits-transfers)
12
12
  class BankAccount < APIResource
13
13
  include Stripe::APIOperations::Delete
14
14
  extend Stripe::APIOperations::List
@@ -4,7 +4,7 @@
4
4
  module Stripe
5
5
  # This is an object representing a capability for a Stripe account.
6
6
  #
7
- # Related guide: [Account capabilities](https://stripe.com/docs/connect/account-capabilities).
7
+ # Related guide: [Account capabilities](https://stripe.com/docs/connect/account-capabilities)
8
8
  class Capability < APIResource
9
9
  extend Stripe::APIOperations::List
10
10
  include Stripe::APIOperations::Save
@@ -6,7 +6,7 @@ module Stripe
6
6
  # later. You can also store multiple debit cards on a recipient in order to
7
7
  # transfer to those cards later.
8
8
  #
9
- # Related guide: [Card Payments with Sources](https://stripe.com/docs/sources/cards).
9
+ # Related guide: [Card payments with Sources](https://stripe.com/docs/sources/cards)
10
10
  class Card < APIResource
11
11
  include Stripe::APIOperations::Delete
12
12
  extend Stripe::APIOperations::List
@@ -6,7 +6,7 @@ module Stripe
6
6
  # retrieve and refund individual charges as well as list all charges. Charges
7
7
  # are identified by a unique, random ID.
8
8
  #
9
- # Related guide: [Accept a payment with the Charges API](https://stripe.com/docs/payments/accept-a-payment-charges).
9
+ # Related guide: [Accept a payment with the Charges API](https://stripe.com/docs/payments/accept-a-payment-charges)
10
10
  class Charge < APIResource
11
11
  extend Stripe::APIOperations::Create
12
12
  extend Stripe::APIOperations::List
@@ -16,7 +16,7 @@ module Stripe
16
16
  # You can create a Checkout Session on your server and redirect to its URL
17
17
  # to begin Checkout.
18
18
  #
19
- # Related guide: [Checkout Quickstart](https://stripe.com/docs/checkout/quickstart).
19
+ # Related guide: [Checkout quickstart](https://stripe.com/docs/checkout/quickstart)
20
20
  class Session < APIResource
21
21
  extend Stripe::APIOperations::Create
22
22
  extend Stripe::APIOperations::List
@@ -4,7 +4,7 @@
4
4
  module Stripe
5
5
  # Issue a credit note to adjust an invoice's amount after the invoice is finalized.
6
6
  #
7
- # Related guide: [Credit Notes](https://stripe.com/docs/billing/invoices/credit-notes).
7
+ # Related guide: [Credit notes](https://stripe.com/docs/billing/invoices/credit-notes)
8
8
  class CreditNote < APIResource
9
9
  extend Stripe::APIOperations::Create
10
10
  extend Stripe::APIOperations::List
@@ -4,7 +4,7 @@
4
4
  module Stripe
5
5
  # This object represents a customer of your business. It lets you create recurring charges and track payments that belong to the same customer.
6
6
  #
7
- # Related guide: [Save a card during payment](https://stripe.com/docs/payments/save-during-payment).
7
+ # Related guide: [Save a card during payment](https://stripe.com/docs/payments/save-during-payment)
8
8
  class Customer < APIResource
9
9
  extend Stripe::APIOperations::Create
10
10
  include Stripe::APIOperations::Delete
@@ -2,12 +2,12 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
- # Each customer has a [`balance`](https://stripe.com/docs/api/customers/object#customer_object-balance) value,
5
+ # Each customer has a [Balance](https://stripe.com/docs/api/customers/object#customer_object-balance) value,
6
6
  # which denotes a debit or credit that's automatically applied to their next invoice upon finalization.
7
7
  # You may modify the value directly by using the [update customer API](https://stripe.com/docs/api/customers/update),
8
8
  # or by creating a Customer Balance Transaction, which increments or decrements the customer's `balance` by the specified `amount`.
9
9
  #
10
- # Related guide: [Customer Balance](https://stripe.com/docs/billing/customer/balance) to learn more.
10
+ # Related guide: [Customer balance](https://stripe.com/docs/billing/customer/balance)
11
11
  class CustomerBalanceTransaction < APIResource
12
12
  extend Stripe::APIOperations::List
13
13
  include Stripe::APIOperations::Save
@@ -5,7 +5,7 @@ module Stripe
5
5
  # A discount represents the actual application of a [coupon](https://stripe.com/docs/api#coupons) or [promotion code](https://stripe.com/docs/api#promotion_codes).
6
6
  # It contains information about when the discount began, when it will end, and what it is applied to.
7
7
  #
8
- # Related guide: [Applying Discounts to Subscriptions](https://stripe.com/docs/billing/subscriptions/discounts).
8
+ # Related guide: [Applying discounts to subscriptions](https://stripe.com/docs/billing/subscriptions/discounts)
9
9
  class Discount < StripeObject
10
10
  OBJECT_NAME = "discount"
11
11
  end
@@ -8,7 +8,7 @@ module Stripe
8
8
  # information about the dispute process in our [Disputes and
9
9
  # Fraud](https://stripe.com/docs/disputes) documentation.
10
10
  #
11
- # Related guide: [Disputes and Fraud](https://stripe.com/docs/disputes).
11
+ # Related guide: [Disputes and fraud](https://stripe.com/docs/disputes)
12
12
  class Dispute < APIResource
13
13
  extend Stripe::APIOperations::List
14
14
  include Stripe::APIOperations::Save
@@ -8,7 +8,7 @@ module Stripe
8
8
  # been created by Stripe (for example, the results of a [Sigma scheduled
9
9
  # query](https://stripe.com/docs/api#scheduled_queries)).
10
10
  #
11
- # Related guide: [File Upload Guide](https://stripe.com/docs/file-upload).
11
+ # Related guide: [File upload guide](https://stripe.com/docs/file-upload)
12
12
  class File < APIResource
13
13
  extend Stripe::APIOperations::Create
14
14
  extend Stripe::APIOperations::List
@@ -39,6 +39,24 @@ module Stripe
39
39
  )
40
40
  end
41
41
 
42
+ def subscribe(params = {}, opts = {})
43
+ request_stripe_object(
44
+ method: :post,
45
+ path: format("/v1/financial_connections/accounts/%<account>s/subscribe", { account: CGI.escape(self["id"]) }),
46
+ params: params,
47
+ opts: opts
48
+ )
49
+ end
50
+
51
+ def unsubscribe(params = {}, opts = {})
52
+ request_stripe_object(
53
+ method: :post,
54
+ path: format("/v1/financial_connections/accounts/%<account>s/unsubscribe", { account: CGI.escape(self["id"]) }),
55
+ params: params,
56
+ opts: opts
57
+ )
58
+ end
59
+
42
60
  def self.disconnect(account, params = {}, opts = {})
43
61
  request_stripe_object(
44
62
  method: :post,
@@ -65,6 +83,24 @@ module Stripe
65
83
  opts: opts
66
84
  )
67
85
  end
86
+
87
+ def self.subscribe(account, params = {}, opts = {})
88
+ request_stripe_object(
89
+ method: :post,
90
+ path: format("/v1/financial_connections/accounts/%<account>s/subscribe", { account: CGI.escape(account) }),
91
+ params: params,
92
+ opts: opts
93
+ )
94
+ end
95
+
96
+ def self.unsubscribe(account, params = {}, opts = {})
97
+ request_stripe_object(
98
+ method: :post,
99
+ path: format("/v1/financial_connections/accounts/%<account>s/unsubscribe", { account: CGI.escape(account) }),
100
+ params: params,
101
+ opts: opts
102
+ )
103
+ end
68
104
  end
69
105
  end
70
106
  end
@@ -6,7 +6,7 @@ module Stripe
6
6
  # automatically applied to future invoices and payments using the `customer_balance` payment method.
7
7
  # Customers can fund this balance by initiating a bank transfer to any account in the
8
8
  # `financial_addresses` field.
9
- # Related guide: [Customer Balance - Funding Instructions](https://stripe.com/docs/payments/customer-balance/funding-instructions) to learn more
9
+ # Related guide: [Customer balance funding instructions](https://stripe.com/docs/payments/customer-balance/funding-instructions)
10
10
  class FundingInstructions < APIResource
11
11
  OBJECT_NAME = "funding_instructions"
12
12
 
@@ -33,7 +33,7 @@ module Stripe
33
33
  # More details on the customer's credit balance are
34
34
  # [here](https://stripe.com/docs/billing/customer/balance).
35
35
  #
36
- # Related guide: [Send Invoices to Customers](https://stripe.com/docs/billing/invoices/sending).
36
+ # Related guide: [Send invoices to customers](https://stripe.com/docs/billing/invoices/sending)
37
37
  class Invoice < APIResource
38
38
  extend Stripe::APIOperations::Create
39
39
  include Stripe::APIOperations::Delete
@@ -7,7 +7,7 @@ module Stripe
7
7
  # object is created. [Authorizations](https://stripe.com/docs/issuing/purchases/authorizations) must be approved for the
8
8
  # purchase to be completed successfully.
9
9
  #
10
- # Related guide: [Issued Card Authorizations](https://stripe.com/docs/issuing/purchases/authorizations).
10
+ # Related guide: [Issued card authorizations](https://stripe.com/docs/issuing/purchases/authorizations)
11
11
  class Authorization < APIResource
12
12
  extend Stripe::APIOperations::List
13
13
  include Stripe::APIOperations::Save
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Issuing
6
6
  # An Issuing `Cardholder` object represents an individual or business entity who is [issued](https://stripe.com/docs/issuing) cards.
7
7
  #
8
- # Related guide: [How to create a Cardholder](https://stripe.com/docs/issuing/cards#create-cardholder)
8
+ # Related guide: [How to create a cardholder](https://stripe.com/docs/issuing/cards#create-cardholder)
9
9
  class Cardholder < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
  extend Stripe::APIOperations::List
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Issuing
6
6
  # As a [card issuer](https://stripe.com/docs/issuing), you can dispute transactions that the cardholder does not recognize, suspects to be fraudulent, or has other issues with.
7
7
  #
8
- # Related guide: [Disputing Transactions](https://stripe.com/docs/issuing/purchases/disputes)
8
+ # Related guide: [Issuing disputes](https://stripe.com/docs/issuing/purchases/disputes)
9
9
  class Dispute < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
  extend Stripe::APIOperations::List
@@ -7,7 +7,7 @@ module Stripe
7
7
  # your Stripe account, such as a completed purchase or refund, is represented by an Issuing
8
8
  # `Transaction` object.
9
9
  #
10
- # Related guide: [Issued Card Transactions](https://stripe.com/docs/issuing/purchases/transactions).
10
+ # Related guide: [Issued card transactions](https://stripe.com/docs/issuing/purchases/transactions)
11
11
  class Transaction < APIResource
12
12
  extend Stripe::APIOperations::List
13
13
  include Stripe::APIOperations::Save
@@ -12,7 +12,7 @@ module Stripe
12
12
  # throughout its lifetime as it interfaces with Stripe.js to perform
13
13
  # authentication flows and ultimately creates at most one successful charge.
14
14
  #
15
- # Related guide: [Payment Intents API](https://stripe.com/docs/payments/payment-intents).
15
+ # Related guide: [Payment Intents API](https://stripe.com/docs/payments/payment-intents)
16
16
  class PaymentIntent < APIResource
17
17
  extend Stripe::APIOperations::Create
18
18
  extend Stripe::APIOperations::List
@@ -9,7 +9,7 @@ module Stripe
9
9
  # schedules](https://stripe.com/docs/connect/manage-payout-schedule), depending on your country and
10
10
  # industry.
11
11
  #
12
- # Related guide: [Receiving Payouts](https://stripe.com/docs/payouts).
12
+ # Related guide: [Receiving payouts](https://stripe.com/docs/payouts)
13
13
  class Payout < APIResource
14
14
  extend Stripe::APIOperations::Create
15
15
  extend Stripe::APIOperations::List
@@ -7,7 +7,7 @@ module Stripe
7
7
  # A platform cannot access a Standard or Express account's persons after the account starts onboarding, such as after generating an account link for the account.
8
8
  # See the [Standard onboarding](https://stripe.com/docs/connect/standard-accounts) or [Express onboarding documentation](https://stripe.com/docs/connect/express-accounts) for information about platform pre-filling and account onboarding steps.
9
9
  #
10
- # Related guide: [Handling Identity Verification with the API](https://stripe.com/docs/connect/identity-verification-api#person-information).
10
+ # Related guide: [Handling identity verification with the API](https://stripe.com/docs/connect/identity-verification-api#person-information)
11
11
  class Person < APIResource
12
12
  extend Stripe::APIOperations::List
13
13
  include Stripe::APIOperations::Save
@@ -6,7 +6,7 @@ module Stripe
6
6
  # An early fraud warning indicates that the card issuer has notified us that a
7
7
  # charge may be fraudulent.
8
8
  #
9
- # Related guide: [Early Fraud Warnings](https://stripe.com/docs/disputes/measuring#early-fraud-warnings).
9
+ # Related guide: [Early fraud warnings](https://stripe.com/docs/disputes/measuring#early-fraud-warnings)
10
10
  class EarlyFraudWarning < APIResource
11
11
  extend Stripe::APIOperations::List
12
12
 
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Radar
6
6
  # Value lists allow you to group values together which can then be referenced in rules.
7
7
  #
8
- # Related guide: [Default Stripe Lists](https://stripe.com/docs/radar/lists#managing-list-items).
8
+ # Related guide: [Default Stripe lists](https://stripe.com/docs/radar/lists#managing-list-items)
9
9
  class ValueList < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
  include Stripe::APIOperations::Delete
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Radar
6
6
  # Value list items allow you to add specific values to a given Radar value list, which can then be used in rules.
7
7
  #
8
- # Related guide: [Managing List Items](https://stripe.com/docs/radar/lists#managing-list-items).
8
+ # Related guide: [Managing list items](https://stripe.com/docs/radar/lists#managing-list-items)
9
9
  class ValueListItem < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
  include Stripe::APIOperations::Delete
@@ -6,7 +6,7 @@ module Stripe
6
6
  # but not yet refunded. Funds will be refunded to the credit or debit card that
7
7
  # was originally charged.
8
8
  #
9
- # Related guide: [Refunds](https://stripe.com/docs/refunds).
9
+ # Related guide: [Refunds](https://stripe.com/docs/refunds)
10
10
  class Refund < APIResource
11
11
  extend Stripe::APIOperations::Create
12
12
  extend Stripe::APIOperations::List
@@ -14,7 +14,7 @@ module Stripe
14
14
  # transfer only if the destination account has enough balance to cover the
15
15
  # reversal.
16
16
  #
17
- # Related guide: [Reversing Transfers](https://stripe.com/docs/connect/charges-transfers#reversing-transfers).
17
+ # Related guide: [Reversing transfers](https://stripe.com/docs/connect/charges-transfers#reversing-transfers)
18
18
  class Reversal < APIResource
19
19
  extend Stripe::APIOperations::List
20
20
  include Stripe::APIOperations::Save
@@ -23,7 +23,7 @@ module Stripe
23
23
  # By using SetupIntents, you ensure that your customers experience the minimum set of required friction,
24
24
  # even as regulations change over time.
25
25
  #
26
- # Related guide: [Setup Intents API](https://stripe.com/docs/payments/setup-intents).
26
+ # Related guide: [Setup Intents API](https://stripe.com/docs/payments/setup-intents)
27
27
  class SetupIntent < APIResource
28
28
  extend Stripe::APIOperations::Create
29
29
  extend Stripe::APIOperations::List
@@ -4,7 +4,7 @@
4
4
  module Stripe
5
5
  # Subscriptions allow you to charge a customer on a recurring basis.
6
6
  #
7
- # Related guide: [Creating Subscriptions](https://stripe.com/docs/billing/subscriptions/creating).
7
+ # Related guide: [Creating subscriptions](https://stripe.com/docs/billing/subscriptions/creating)
8
8
  class Subscription < APIResource
9
9
  extend Stripe::APIOperations::Create
10
10
  extend Stripe::APIOperations::List
@@ -4,7 +4,7 @@
4
4
  module Stripe
5
5
  # A subscription schedule allows you to create and manage the lifecycle of a subscription by predefining expected changes.
6
6
  #
7
- # Related guide: [Subscription Schedules](https://stripe.com/docs/billing/subscriptions/subscription-schedules).
7
+ # Related guide: [Subscription schedules](https://stripe.com/docs/billing/subscriptions/subscription-schedules)
8
8
  class SubscriptionSchedule < APIResource
9
9
  extend Stripe::APIOperations::Create
10
10
  extend Stripe::APIOperations::List
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Tax
6
6
  # A Tax Calculation allows you to calculate the tax to collect from your customer.
7
7
  #
8
- # Related guide: [Calculate tax in your custom payment flow](https://stripe.com/docs/tax/custom).
8
+ # Related guide: [Calculate tax in your custom payment flow](https://stripe.com/docs/tax/custom)
9
9
  class Calculation < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
 
@@ -5,7 +5,9 @@ module Stripe
5
5
  module Tax
6
6
  # A Tax `Registration` lets us know that your business is registered to collect tax on payments within a region, enabling you to [automatically collect tax](https://stripe.com/docs/tax).
7
7
  #
8
- # Stripe will not register on your behalf with the relevant authorities when you create a Tax `Registration` object. For more information on how to register to collect tax, see [our guide](https://stripe.com/docs/tax/registering).
8
+ # Stripe doesn't register on your behalf with the relevant authorities when you create a Tax `Registration` object. For more information on how to register to collect tax, see [our guide](https://stripe.com/docs/tax/registering).
9
+ #
10
+ # Related guide: [Using the Registrations API](https://stripe.com/docs/tax/registrations-api)
9
11
  class Registration < APIResource
10
12
  extend Stripe::APIOperations::Create
11
13
  extend Stripe::APIOperations::List
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Tax
6
6
  # You can use Tax `Settings` to manage configurations used by Stripe Tax calculations.
7
7
  #
8
- # Related guide: [Account settings](https://stripe.com/docs/tax/connect/settings).
8
+ # Related guide: [Using the Settings API](https://stripe.com/docs/tax/settings-api)
9
9
  class Settings < SingletonAPIResource
10
10
  include Stripe::APIOperations::Save
11
11
 
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Tax
6
6
  # A Tax Transaction records the tax collected from or refunded to your customer.
7
7
  #
8
- # Related guide: [Calculate tax in your custom payment flow](https://stripe.com/docs/tax/custom#tax-transaction).
8
+ # Related guide: [Calculate tax in your custom payment flow](https://stripe.com/docs/tax/custom#tax-transaction)
9
9
  class Transaction < APIResource
10
10
  OBJECT_NAME = "tax.transaction"
11
11
 
@@ -5,7 +5,7 @@ module Stripe
5
5
  # You can add one or multiple tax IDs to a [customer](https://stripe.com/docs/api/customers).
6
6
  # A customer's tax IDs are displayed on invoices and credit notes issued for the customer.
7
7
  #
8
- # Related guide: [Customer Tax Identification Numbers](https://stripe.com/docs/billing/taxes/tax-ids).
8
+ # Related guide: [Customer tax identification numbers](https://stripe.com/docs/billing/taxes/tax-ids)
9
9
  class TaxId < APIResource
10
10
  include Stripe::APIOperations::Delete
11
11
  extend Stripe::APIOperations::List
@@ -4,7 +4,7 @@
4
4
  module Stripe
5
5
  # Tax rates can be applied to [invoices](https://stripe.com/docs/billing/invoices/tax-rates), [subscriptions](https://stripe.com/docs/billing/subscriptions/taxes) and [Checkout Sessions](https://stripe.com/docs/payments/checkout/set-up-a-subscription#tax-rates) to collect tax.
6
6
  #
7
- # Related guide: [Tax Rates](https://stripe.com/docs/billing/taxes/tax-rates).
7
+ # Related guide: [Tax rates](https://stripe.com/docs/billing/taxes/tax-rates)
8
8
  class TaxRate < APIResource
9
9
  extend Stripe::APIOperations::Create
10
10
  extend Stripe::APIOperations::List
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Terminal
6
6
  # A Connection Token is used by the Stripe Terminal SDK to connect to a reader.
7
7
  #
8
- # Related guide: [Fleet Management](https://stripe.com/docs/terminal/fleet/locations).
8
+ # Related guide: [Fleet management](https://stripe.com/docs/terminal/fleet/locations)
9
9
  class ConnectionToken < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
 
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Terminal
6
6
  # A Location represents a grouping of readers.
7
7
  #
8
- # Related guide: [Fleet Management](https://stripe.com/docs/terminal/fleet/locations).
8
+ # Related guide: [Fleet management](https://stripe.com/docs/terminal/fleet/locations)
9
9
  class Location < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
  include Stripe::APIOperations::Delete
@@ -5,7 +5,7 @@ module Stripe
5
5
  module Terminal
6
6
  # A Reader represents a physical device for accepting payment details.
7
7
  #
8
- # Related guide: [Connecting to a Reader](https://stripe.com/docs/terminal/payments/connect-reader).
8
+ # Related guide: [Connecting to a reader](https://stripe.com/docs/terminal/payments/connect-reader)
9
9
  class Reader < APIResource
10
10
  extend Stripe::APIOperations::Create
11
11
  include Stripe::APIOperations::Delete
@@ -23,7 +23,7 @@ module Stripe
23
23
  # [Radar](https://stripe.com/docs/radar), our integrated solution for automatic fraud protection,
24
24
  # performs best with integrations that use client-side tokenization.
25
25
  #
26
- # Related guide: [Accept a payment](https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token)
26
+ # Related guide: [Accept a payment with Charges and Tokens](https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token)
27
27
  class Token < APIResource
28
28
  extend Stripe::APIOperations::Create
29
29
 
@@ -6,7 +6,7 @@ module Stripe
6
6
  # individual top-ups, as well as list all top-ups. Top-ups are identified by a
7
7
  # unique, random ID.
8
8
  #
9
- # Related guide: [Topping Up your Platform Account](https://stripe.com/docs/connect/top-ups).
9
+ # Related guide: [Topping up your platform account](https://stripe.com/docs/connect/top-ups)
10
10
  class Topup < APIResource
11
11
  extend Stripe::APIOperations::Create
12
12
  extend Stripe::APIOperations::List
@@ -11,7 +11,7 @@ module Stripe
11
11
  # information, read about the
12
12
  # [transfer/payout split](https://stripe.com/docs/transfer-payout-split).
13
13
  #
14
- # Related guide: [Creating Separate Charges and Transfers](https://stripe.com/docs/connect/charges-transfers).
14
+ # Related guide: [Creating separate charges and transfers](https://stripe.com/docs/connect/charges-transfers)
15
15
  class Transfer < APIResource
16
16
  extend Stripe::APIOperations::Create
17
17
  extend Stripe::APIOperations::List
@@ -5,7 +5,7 @@ module Stripe
5
5
  # Usage records allow you to report customer usage and metrics to Stripe for
6
6
  # metered billing of subscription prices.
7
7
  #
8
- # Related guide: [Metered Billing](https://stripe.com/docs/billing/subscriptions/metered-billing).
8
+ # Related guide: [Metered billing](https://stripe.com/docs/billing/subscriptions/metered-billing)
9
9
  class UsageRecord < APIResource
10
10
  OBJECT_NAME = "usage_record"
11
11
  end
@@ -8,7 +8,7 @@ module Stripe
8
8
  #
9
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
10
  #
11
- # Related guide: [Setting up Webhooks](https://stripe.com/docs/webhooks/configure).
11
+ # Related guide: [Setting up webhooks](https://stripe.com/docs/webhooks/configure)
12
12
  class WebhookEndpoint < APIResource
13
13
  extend Stripe::APIOperations::Create
14
14
  include Stripe::APIOperations::Delete
@@ -212,9 +212,10 @@ module Stripe
212
212
  end
213
213
 
214
214
  def execute_request(method, path,
215
- api_base: nil, api_key: nil, headers: {}, params: {})
215
+ api_base: nil, api_key: nil,
216
+ headers: {}, params: {}, api_mode: nil)
216
217
  http_resp, api_key = execute_request_internal(
217
- method, path, api_base, api_key, headers, params
218
+ method, path, api_base, api_key, headers, params, api_mode
218
219
  )
219
220
 
220
221
  begin
@@ -245,6 +246,7 @@ module Stripe
245
246
  def execute_request_stream(method, path,
246
247
  api_base: nil, api_key: nil,
247
248
  headers: {}, params: {},
249
+ api_mode: nil,
248
250
  &read_body_chunk_block)
249
251
  unless block_given?
250
252
  raise ArgumentError,
@@ -252,7 +254,8 @@ module Stripe
252
254
  end
253
255
 
254
256
  http_resp, api_key = execute_request_internal(
255
- method, path, api_base, api_key, headers, params, &read_body_chunk_block
257
+ method, path, api_base, api_key,
258
+ headers, params, api_mode, &read_body_chunk_block
256
259
  )
257
260
 
258
261
  # When the read_body_chunk_block is given, we no longer have access to the
@@ -432,7 +435,7 @@ module Stripe
432
435
 
433
436
  private def execute_request_internal(method, path,
434
437
  api_base, api_key, headers, params,
435
- &read_body_chunk_block)
438
+ api_mode, &read_body_chunk_block)
436
439
  raise ArgumentError, "method should be a symbol" \
437
440
  unless method.is_a?(Symbol)
438
441
  raise ArgumentError, "path should be a string" \
@@ -440,9 +443,10 @@ module Stripe
440
443
 
441
444
  api_base ||= config.api_base
442
445
  api_key ||= config.api_key
446
+ authenticator ||= config.authenticator
443
447
  params = Util.objects_to_ids(params)
444
448
 
445
- check_api_key!(api_key)
449
+ check_keys!(api_key, authenticator)
446
450
 
447
451
  body_params = nil
448
452
  query_params = nil
@@ -455,8 +459,9 @@ module Stripe
455
459
 
456
460
  query_params, path = merge_query_params(query_params, path)
457
461
 
458
- headers = request_headers(api_key, method)
462
+ headers = request_headers(api_key, method, api_mode)
459
463
  .update(Util.normalize_headers(headers))
464
+
460
465
  url = api_url(path, api_base)
461
466
 
462
467
  # Merge given query parameters with any already encoded in the path.
@@ -467,13 +472,16 @@ module Stripe
467
472
  # a log-friendly variant of the encoded form. File objects are displayed
468
473
  # as such instead of as their file contents.
469
474
  body, body_log =
470
- body_params ? encode_body(body_params, headers) : [nil, nil]
475
+ body_params ? encode_body(body_params, headers, api_mode) : [nil, nil]
476
+
477
+ authenticator.authenticate(method, headers, body) unless api_key
471
478
 
472
479
  # stores information on the request we're about to make so that we don't
473
480
  # have to pass as many parameters around for logging.
474
481
  context = RequestLogContext.new
475
482
  context.account = headers["Stripe-Account"]
476
483
  context.api_key = api_key
484
+ context.authenticator = authenticator
477
485
  context.api_version = headers["Stripe-Version"]
478
486
  context.body = body_log
479
487
  context.idempotency_key = headers["Idempotency-Key"]
@@ -512,8 +520,16 @@ module Stripe
512
520
  (api_base || config.api_base) + url
513
521
  end
514
522
 
515
- private def check_api_key!(api_key)
516
- unless api_key
523
+ private def check_keys!(api_key, authenticator)
524
+ if api_key && authenticator
525
+ raise AuthenticationError, "Can't specify both API key " \
526
+ "and authenticator. Either set your API key" \
527
+ 'using "Stripe.api_key = <API-KEY>", or set your authenticator ' \
528
+ 'using "Stripe.authenticator = <AUTHENTICATOR>"' \
529
+ end
530
+
531
+ unless api_key || authenticator
532
+ # Default to missing API key error message for general users.
517
533
  raise AuthenticationError, "No API key provided. " \
518
534
  'Set your API key using "Stripe.api_key = <API-KEY>". ' \
519
535
  "You can generate API keys from the Stripe web interface. " \
@@ -532,7 +548,7 @@ module Stripe
532
548
  # Encodes a set of body parameters using multipart if `Content-Type` is set
533
549
  # for that, or standard form-encoding otherwise. Returns the encoded body
534
550
  # and a version of the encoded body that's safe to be logged.
535
- private def encode_body(body_params, headers)
551
+ private def encode_body(body_params, headers, api_mode)
536
552
  body = nil
537
553
  flattened_params = Util.flatten_params(body_params)
538
554
 
@@ -548,15 +564,22 @@ module Stripe
548
564
  flattened_params =
549
565
  flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
550
566
 
567
+ elsif api_mode == :preview
568
+ body = JSON.generate(body_params)
569
+ headers["Content-Type"] = "application/json"
551
570
  else
552
571
  body = Util.encode_parameters(body_params)
553
572
  end
554
573
 
555
- # We don't use `Util.encode_parameters` partly as an optimization (to not
556
- # redo work we've already done), and partly because the encoded forms of
557
- # certain characters introduce a lot of visual noise and it's nice to
558
- # have a clearer format for logs.
559
- body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
574
+ if api_mode == :preview
575
+ body_log = body
576
+ else
577
+ # We don't use `Util.encode_parameters` partly as an optimization (to
578
+ # not redo work we've already done), and partly because the encoded
579
+ # forms of certain characters introduce a lot of visual noise and it's
580
+ # nice to have a clearer format for logs.
581
+ body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
582
+ end
560
583
 
561
584
  [body, body_log]
562
585
  end
@@ -856,7 +879,7 @@ module Stripe
856
879
  message + "\n\n(Network error: #{error.message})"
857
880
  end
858
881
 
859
- private def request_headers(api_key, method)
882
+ private def request_headers(api_key, method, api_mode)
860
883
  user_agent = "Stripe/v1 RubyBindings/#{Stripe::VERSION}"
861
884
  unless Stripe.app_info.nil?
862
885
  user_agent += " " + format_app_info(Stripe.app_info)
@@ -865,9 +888,13 @@ module Stripe
865
888
  headers = {
866
889
  "User-Agent" => user_agent,
867
890
  "Authorization" => "Bearer #{api_key}",
868
- "Content-Type" => "application/x-www-form-urlencoded",
869
891
  }
870
892
 
893
+ if api_mode != :preview
894
+ # TODO: (major) don't set Content-Type if method is not post
895
+ headers["Content-Type"] = "application/x-www-form-urlencoded"
896
+ end
897
+
871
898
  if config.enable_telemetry? && !@last_request_metrics.nil?
872
899
  headers["X-Stripe-Client-Telemetry"] = JSON.generate(
873
900
  last_request_metrics: @last_request_metrics.payload
@@ -880,7 +907,12 @@ module Stripe
880
907
  headers["Idempotency-Key"] ||= SecureRandom.uuid
881
908
  end
882
909
 
883
- headers["Stripe-Version"] = config.api_version if config.api_version
910
+ if api_mode == :preview
911
+ headers["Stripe-Version"] = ApiVersion::PREVIEW
912
+ elsif config.api_version
913
+ headers["Stripe-Version"] = config.api_version
914
+ end
915
+
884
916
  headers["Stripe-Account"] = config.stripe_account if config.stripe_account
885
917
 
886
918
  user_agent = @system_profiler.user_agent
@@ -966,6 +998,7 @@ module Stripe
966
998
  attr_accessor :body
967
999
  attr_accessor :account
968
1000
  attr_accessor :api_key
1001
+ attr_accessor :authenticator
969
1002
  attr_accessor :api_version
970
1003
  attr_accessor :idempotency_key
971
1004
  attr_accessor :method
@@ -27,6 +27,7 @@ module Stripe
27
27
  class StripeConfiguration
28
28
  attr_accessor :api_key
29
29
  attr_accessor :api_version
30
+ attr_accessor :authenticator
30
31
  attr_accessor :client_id
31
32
  attr_accessor :enable_telemetry
32
33
  attr_accessor :logger
data/lib/stripe/util.rb CHANGED
@@ -7,6 +7,7 @@ module Stripe
7
7
  # Options that a user is allowed to specify.
8
8
  OPTS_USER_SPECIFIED = Set[
9
9
  :api_key,
10
+ :authenticator,
10
11
  :idempotency_key,
11
12
  :stripe_account,
12
13
  :stripe_version
@@ -281,7 +282,13 @@ module Stripe
281
282
  when String
282
283
  { api_key: opts }
283
284
  when Hash
284
- check_api_key!(opts.fetch(:api_key)) if opts.key?(:api_key)
285
+ # If the user is using request signing for authentication,
286
+ # no need to check the api_key per request.
287
+ if !(opts.key?(:client) &&
288
+ opts.fetch(:client).config.authenticator) &&
289
+ opts.key?(:api_key)
290
+ check_api_key!(opts.fetch(:api_key))
291
+ end
285
292
  # Explicitly use dup here instead of clone to avoid preserving freeze
286
293
  # state on input params.
287
294
  opts.dup
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "8.6.0-beta.2"
4
+ VERSION = "8.6.0-beta.4"
5
5
  end
data/lib/stripe.rb CHANGED
@@ -13,6 +13,7 @@ require "set"
13
13
  require "socket"
14
14
  require "uri"
15
15
  require "forwardable"
16
+ require "base64"
16
17
 
17
18
  # Version
18
19
  require "stripe/api_version"
@@ -44,6 +45,7 @@ require "stripe/api_resource_test_helpers"
44
45
  require "stripe/singleton_api_resource"
45
46
  require "stripe/webhook"
46
47
  require "stripe/stripe_configuration"
48
+ require "stripe/request_signing_authenticator"
47
49
 
48
50
  # Named API resources
49
51
  require "stripe/resources"
@@ -70,6 +72,7 @@ module Stripe
70
72
 
71
73
  # User configurable options
72
74
  def_delegators :@config, :api_key, :api_key=
75
+ def_delegators :@config, :authenticator, :authenticator=
73
76
  def_delegators :@config, :api_version, :api_version=
74
77
  def_delegators :@config, :stripe_account, :stripe_account=
75
78
  def_delegators :@config, :api_base, :api_base=
@@ -116,6 +119,49 @@ module Stripe
116
119
  version: version,
117
120
  }
118
121
  end
122
+
123
+ class Preview
124
+ def self._get_default_opts(opts)
125
+ { api_mode: :preview }.merge(opts)
126
+ end
127
+
128
+ def self.get(url, opts = {})
129
+ Stripe.raw_request(:get, url, {}, _get_default_opts(opts))
130
+ end
131
+
132
+ def self.post(url, params = {}, opts = {})
133
+ Stripe.raw_request(:post, url, params, _get_default_opts(opts))
134
+ end
135
+
136
+ def self.delete(url, opts = {})
137
+ Stripe.raw_request(:delete, url, {}, _get_default_opts(opts))
138
+ end
139
+ end
140
+
141
+ class RawRequest
142
+ include Stripe::APIOperations::Request
143
+
144
+ def initialize
145
+ @opts = {}
146
+ end
147
+
148
+ def execute(method, url, params = {}, opts = {})
149
+ resp, = execute_resource_request(method, url, params, opts)
150
+
151
+ resp
152
+ end
153
+ end
154
+
155
+ # Sends a request to Stripe REST API
156
+ def self.raw_request(method, url, params = {}, opts = {})
157
+ req = RawRequest.new
158
+ req.execute(method, url, params, opts)
159
+ end
160
+
161
+ def self.deserialize(data)
162
+ data = JSON.parse(data) if data.is_a?(String)
163
+ Util.convert_to_stripe_object(data, {})
164
+ end
119
165
  end
120
166
 
121
167
  Stripe.log_level = ENV["STRIPE_LOG"] unless ENV["STRIPE_LOG"].nil?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.6.0.pre.beta.2
4
+ version: 8.6.0.pre.beta.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-13 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Stripe is the easiest way to accept payments online. See https://stripe.com
14
14
  for details.
@@ -50,6 +50,7 @@ files:
50
50
  - lib/stripe/multipart_encoder.rb
51
51
  - lib/stripe/oauth.rb
52
52
  - lib/stripe/object_types.rb
53
+ - lib/stripe/request_signing_authenticator.rb
53
54
  - lib/stripe/resources.rb
54
55
  - lib/stripe/resources/account.rb
55
56
  - lib/stripe/resources/account_link.rb