stripe 8.6.0.pre.beta.1 → 8.6.0.pre.beta.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bb18aa99427adfd4362824cf23ec3860ebe83d291e40a6006ac9fc59242fbcc
4
- data.tar.gz: 82a2ec4c057b6537d643d0c6e900eb5c2965654ba98dba5affb3c11440c83ed1
3
+ metadata.gz: b8329baf2324481281bac8a14057e933252bcc1fccbde79f4303fb1e84d113c9
4
+ data.tar.gz: bce0345d4c34fb1b25278e55a5ca31db6303d7b5b69037d05e55b3aa8f68537e
5
5
  SHA512:
6
- metadata.gz: acf1af5b7188d27e6f9d064127d13ff22d713a743b81035a210f0881e261a21b49511f1019bf3cfff842979199d372b7d97cd38c7a8e6c201b6c1544d2d07537
7
- data.tar.gz: 2791cbf6e65421c6fb891bb4972146b52d289d8257e8a86ebcc073d03aedb66d83e71d8b66d94cec1d8ba06028fc9434aa98be64277d98410a116d16b5e67e88
6
+ metadata.gz: 7055e66eae45c2a9e3cf0d3dd6f65c1da2e7ef6a0189feb9a7cbf04de25b857a37e7888c7cfe8f391004192c9cbce4f3f30ee25236fa2f94bd4b7d4263ae696a
7
+ data.tar.gz: 47077ba02bc7c0c73071d92500333e84bce73cae25ea88ec0ff5c47b378bc5b2e0473cb5bc8cdc9d65d9151b6f74f5361df674685af2ce194d452ae0fe6d5df7
data/CHANGELOG.md CHANGED
@@ -1,12 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.6.0-beta.3 - 2023-04-17
4
+ * [#1211](https://github.com/stripe/stripe-ruby/pull/1211) Update generated code for beta
5
+ * [#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
6
+
7
+ ## 8.6.0-beta.2 - 2023-04-13
8
+ * [#1206](https://github.com/stripe/stripe-ruby/pull/1206) Update generated code for beta
9
+ * Add support for `collect_payment_method` and `confirm_payment_intent` methods on resource `Terminal.Reader`
10
+ * [#1205](https://github.com/stripe/stripe-ruby/pull/1205) Update generated code for beta
11
+
12
+
3
13
  ## 8.6.0-beta.1 - 2023-03-30
4
14
  * [#1202](https://github.com/stripe/stripe-ruby/pull/1202) Update generated code for beta
5
15
 
6
16
 
7
17
  ## 8.5.0 - 2023-03-30
8
18
  * [#1203](https://github.com/stripe/stripe-ruby/pull/1203) Update generated code
9
- * Remove support for `create` method on resource `Tax.Transaction`
19
+ * Remove support for `create` method on resource `Tax.Transaction`
10
20
  * 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.
11
21
  * [#1201](https://github.com/stripe/stripe-ruby/pull/1201) Update save deprecation message
12
22
 
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
- v287
1
+ v299
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.6.0-beta.1
1
+ 8.6.0-beta.3
@@ -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
@@ -2,13 +2,13 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Stripe
5
- # An AccountSession allows a Connect platform to grant access to a connected account in Connect embedded UIs.
5
+ # An AccountSession allows a Connect platform to grant access to a connected account in Connect embedded components.
6
6
  #
7
- # We recommend that you create an AccountSession each time you need to display an embedded UI
7
+ # We recommend that you create an AccountSession each time you need to display an embedded component
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 UIs](https://stripe.com/docs/connect/get-started-connect-embedded-uis).
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
 
@@ -3,7 +3,9 @@
3
3
 
4
4
  module Stripe
5
5
  module Tax
6
- # A Tax `Calculation` allows you to calculate the tax to collect from your customer.
6
+ # A Tax Calculation allows you to calculate the tax to collect from your customer.
7
+ #
8
+ # Related guide: [Calculate tax in your custom payment flow](https://stripe.com/docs/tax/custom).
7
9
  class Calculation < APIResource
8
10
  extend Stripe::APIOperations::Create
9
11
 
@@ -3,7 +3,9 @@
3
3
 
4
4
  module Stripe
5
5
  module Tax
6
- # A Tax transaction records the tax collected from or refunded to your customer.
6
+ # A Tax Transaction records the tax collected from or refunded to your customer.
7
+ #
8
+ # Related guide: [Calculate tax in your custom payment flow](https://stripe.com/docs/tax/custom#tax-transaction).
7
9
  class Transaction < APIResource
8
10
  OBJECT_NAME = "tax.transaction"
9
11
 
@@ -32,6 +32,24 @@ module Stripe
32
32
  )
33
33
  end
34
34
 
35
+ def collect_payment_method(params = {}, opts = {})
36
+ request_stripe_object(
37
+ method: :post,
38
+ path: format("/v1/terminal/readers/%<reader>s/collect_payment_method", { reader: CGI.escape(self["id"]) }),
39
+ params: params,
40
+ opts: opts
41
+ )
42
+ end
43
+
44
+ def confirm_payment_intent(params = {}, opts = {})
45
+ request_stripe_object(
46
+ method: :post,
47
+ path: format("/v1/terminal/readers/%<reader>s/confirm_payment_intent", { reader: CGI.escape(self["id"]) }),
48
+ params: params,
49
+ opts: opts
50
+ )
51
+ end
52
+
35
53
  def process_payment_intent(params = {}, opts = {})
36
54
  request_stripe_object(
37
55
  method: :post,
@@ -86,6 +104,24 @@ module Stripe
86
104
  )
87
105
  end
88
106
 
107
+ def self.collect_payment_method(reader, params = {}, opts = {})
108
+ request_stripe_object(
109
+ method: :post,
110
+ path: format("/v1/terminal/readers/%<reader>s/collect_payment_method", { reader: CGI.escape(reader) }),
111
+ params: params,
112
+ opts: opts
113
+ )
114
+ end
115
+
116
+ def self.confirm_payment_intent(reader, params = {}, opts = {})
117
+ request_stripe_object(
118
+ method: :post,
119
+ path: format("/v1/terminal/readers/%<reader>s/confirm_payment_intent", { reader: CGI.escape(reader) }),
120
+ params: params,
121
+ opts: opts
122
+ )
123
+ end
124
+
89
125
  def self.process_payment_intent(reader, params = {}, opts = {})
90
126
  request_stripe_object(
91
127
  method: :post,
@@ -440,9 +440,10 @@ module Stripe
440
440
 
441
441
  api_base ||= config.api_base
442
442
  api_key ||= config.api_key
443
+ authenticator ||= config.authenticator
443
444
  params = Util.objects_to_ids(params)
444
445
 
445
- check_api_key!(api_key)
446
+ check_keys!(api_key, authenticator)
446
447
 
447
448
  body_params = nil
448
449
  query_params = nil
@@ -469,11 +470,14 @@ module Stripe
469
470
  body, body_log =
470
471
  body_params ? encode_body(body_params, headers) : [nil, nil]
471
472
 
473
+ authenticator.authenticate(method, headers, body) unless api_key
474
+
472
475
  # stores information on the request we're about to make so that we don't
473
476
  # have to pass as many parameters around for logging.
474
477
  context = RequestLogContext.new
475
478
  context.account = headers["Stripe-Account"]
476
479
  context.api_key = api_key
480
+ context.authenticator = authenticator
477
481
  context.api_version = headers["Stripe-Version"]
478
482
  context.body = body_log
479
483
  context.idempotency_key = headers["Idempotency-Key"]
@@ -512,8 +516,16 @@ module Stripe
512
516
  (api_base || config.api_base) + url
513
517
  end
514
518
 
515
- private def check_api_key!(api_key)
516
- unless api_key
519
+ private def check_keys!(api_key, authenticator)
520
+ if api_key && authenticator
521
+ raise AuthenticationError, "Can't specify both API key " \
522
+ "and authenticator. Either set your API key" \
523
+ 'using "Stripe.api_key = <API-KEY>", or set your authenticator ' \
524
+ 'using "Stripe.authenticator = <AUTHENTICATOR>"' \
525
+ end
526
+
527
+ unless api_key || authenticator
528
+ # Default to missing API key error message for general users.
517
529
  raise AuthenticationError, "No API key provided. " \
518
530
  'Set your API key using "Stripe.api_key = <API-KEY>". ' \
519
531
  "You can generate API keys from the Stripe web interface. " \
@@ -966,6 +978,7 @@ module Stripe
966
978
  attr_accessor :body
967
979
  attr_accessor :account
968
980
  attr_accessor :api_key
981
+ attr_accessor :authenticator
969
982
  attr_accessor :api_version
970
983
  attr_accessor :idempotency_key
971
984
  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.1"
4
+ VERSION = "8.6.0-beta.3"
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=
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.1
4
+ version: 8.6.0.pre.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-30 00:00:00.000000000 Z
11
+ date: 2023-04-17 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