stripe-ruby-mock 2.5.8 → 3.1.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -9
  4. data/CHANGELOG.md +41 -0
  5. data/Gemfile +1 -0
  6. data/README.md +17 -11
  7. data/lib/stripe_mock.rb +8 -0
  8. data/lib/stripe_mock/api/client.rb +1 -1
  9. data/lib/stripe_mock/api/errors.rb +34 -28
  10. data/lib/stripe_mock/api/instance.rb +1 -1
  11. data/lib/stripe_mock/api/webhooks.rb +5 -0
  12. data/lib/stripe_mock/client.rb +2 -1
  13. data/lib/stripe_mock/data.rb +285 -16
  14. data/lib/stripe_mock/data/list.rb +42 -9
  15. data/lib/stripe_mock/instance.rb +18 -4
  16. data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
  17. data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
  18. data/lib/stripe_mock/request_handlers/charges.rb +6 -4
  19. data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
  20. data/lib/stripe_mock/request_handlers/checkout_session.rb +22 -0
  21. data/lib/stripe_mock/request_handlers/customers.rb +35 -18
  22. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
  23. data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
  24. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +5 -0
  25. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +12 -7
  26. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
  27. data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
  28. data/lib/stripe_mock/request_handlers/payment_intents.rb +182 -0
  29. data/lib/stripe_mock/request_handlers/payment_methods.rb +120 -0
  30. data/lib/stripe_mock/request_handlers/plans.rb +1 -1
  31. data/lib/stripe_mock/request_handlers/prices.rb +44 -0
  32. data/lib/stripe_mock/request_handlers/products.rb +1 -0
  33. data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
  34. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  35. data/lib/stripe_mock/request_handlers/subscriptions.rb +45 -22
  36. data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
  37. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +123 -9
  38. data/lib/stripe_mock/server.rb +2 -2
  39. data/lib/stripe_mock/test_strategies/base.rb +67 -8
  40. data/lib/stripe_mock/test_strategies/live.rb +23 -12
  41. data/lib/stripe_mock/test_strategies/mock.rb +6 -2
  42. data/lib/stripe_mock/version.rb +1 -1
  43. data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
  44. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
  45. data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
  46. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
  47. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
  48. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
  49. data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
  50. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
  51. data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
  52. data/spec/instance_spec.rb +10 -12
  53. data/spec/list_spec.rb +38 -0
  54. data/spec/server_spec.rb +6 -3
  55. data/spec/shared_stripe_examples/account_examples.rb +1 -1
  56. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  57. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  58. data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
  59. data/spec/shared_stripe_examples/bank_examples.rb +3 -3
  60. data/spec/shared_stripe_examples/card_examples.rb +4 -4
  61. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  62. data/spec/shared_stripe_examples/charge_examples.rb +9 -22
  63. data/spec/shared_stripe_examples/checkout_examples.rb +47 -0
  64. data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
  65. data/spec/shared_stripe_examples/customer_examples.rb +93 -53
  66. data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
  67. data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
  68. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  69. data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
  70. data/spec/shared_stripe_examples/invoice_examples.rb +41 -39
  71. data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
  72. data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
  73. data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
  74. data/spec/shared_stripe_examples/payout_examples.rb +2 -2
  75. data/spec/shared_stripe_examples/plan_examples.rb +135 -92
  76. data/spec/shared_stripe_examples/price_examples.rb +183 -0
  77. data/spec/shared_stripe_examples/product_examples.rb +147 -0
  78. data/spec/shared_stripe_examples/refund_examples.rb +25 -21
  79. data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
  80. data/spec/shared_stripe_examples/subscription_examples.rb +430 -318
  81. data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
  82. data/spec/shared_stripe_examples/transfer_examples.rb +6 -6
  83. data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
  84. data/spec/spec_helper.rb +7 -4
  85. data/spec/stripe_mock_spec.rb +4 -4
  86. data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
  87. data/spec/support/stripe_examples.rb +9 -1
  88. data/stripe-ruby-mock.gemspec +8 -3
  89. metadata +72 -34
  90. data/spec/shared_stripe_examples/product_example.rb +0 -65
@@ -36,7 +36,7 @@ module StripeMock
36
36
 
37
37
  def get_card_or_bank_by_token(token)
38
38
  token_id = token['id'] || token
39
- @card_tokens[token_id] || @bank_tokens[token_id] || raise(Stripe::InvalidRequestError.new("Invalid token id: #{token_id}", 'tok', http_status: 404))
39
+ @card_tokens[token_id] || @bank_tokens[token_id] || raise(Stripe::InvalidRequestError.new("Invalid token id: #{token_id}", 'tok', http_status: 404))
40
40
  end
41
41
 
42
42
  end
@@ -56,13 +56,14 @@ module StripeMock
56
56
  invoices[$1].merge!(:paid => true, :attempted => true, :charge => charge[:id])
57
57
  end
58
58
 
59
- def upcoming_invoice(route, method_url, params, headers)
59
+ def upcoming_invoice(route, method_url, params, headers = {})
60
+ stripe_account = headers && headers[:stripe_account] || Stripe.api_key
60
61
  route =~ method_url
61
- raise Stripe::InvalidRequestError.new('Missing required param: customer', nil, http_status: 400) if params[:customer].nil?
62
+ raise Stripe::InvalidRequestError.new('Missing required param: customer if subscription is not provided', nil, http_status: 400) if params[:customer].nil? && params[:subscription].nil?
62
63
  raise Stripe::InvalidRequestError.new('When previewing changes to a subscription, you must specify either `subscription` or `subscription_items`', nil, http_status: 400) if !params[:subscription_proration_date].nil? && params[:subscription].nil? && params[:subscription_plan].nil?
63
64
  raise Stripe::InvalidRequestError.new('Cannot specify proration date without specifying a subscription', nil, http_status: 400) if !params[:subscription_proration_date].nil? && params[:subscription].nil?
64
65
 
65
- customer = customers[params[:customer]]
66
+ customer = customers[stripe_account][params[:customer]]
66
67
  assert_existence :customer, params[:customer], customer
67
68
 
68
69
  raise Stripe::InvalidRequestError.new("No upcoming invoices for customer: #{customer[:id]}", nil, http_status: 404) if customer[:subscriptions][:data].length == 0
@@ -99,7 +100,12 @@ module StripeMock
99
100
  invoice_lines = []
100
101
 
101
102
  if prorating
102
- unused_amount = subscription[:plan][:amount] * subscription[:quantity] * (subscription[:current_period_end] - subscription_proration_date.to_i) / (subscription[:current_period_end] - subscription[:current_period_start])
103
+ unused_amount = (
104
+ subscription[:plan][:amount].to_f *
105
+ subscription[:quantity] *
106
+ (subscription[:current_period_end] - subscription_proration_date.to_i) / (subscription[:current_period_end] - subscription[:current_period_start])
107
+ ).ceil
108
+
103
109
  invoice_lines << Data.mock_line_item(
104
110
  id: new_id('ii'),
105
111
  amount: -unused_amount,
@@ -0,0 +1,182 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module PaymentIntents
4
+ ALLOWED_PARAMS = [:description, :metadata, :receipt_email, :shipping, :destination, :payment_method, :payment_method_types, :setup_future_usage, :transfer_data, :amount, :currency]
5
+
6
+ def PaymentIntents.included(klass)
7
+ klass.add_handler 'post /v1/payment_intents', :new_payment_intent
8
+ klass.add_handler 'get /v1/payment_intents', :get_payment_intents
9
+ klass.add_handler 'get /v1/payment_intents/(.*)', :get_payment_intent
10
+ klass.add_handler 'post /v1/payment_intents/(.*)/confirm', :confirm_payment_intent
11
+ klass.add_handler 'post /v1/payment_intents/(.*)/capture', :capture_payment_intent
12
+ klass.add_handler 'post /v1/payment_intents/(.*)/cancel', :cancel_payment_intent
13
+ klass.add_handler 'post /v1/payment_intents/(.*)', :update_payment_intent
14
+ end
15
+
16
+ def new_payment_intent(route, method_url, params, headers)
17
+ id = new_id('pi')
18
+
19
+ ensure_payment_intent_required_params(params)
20
+ status = case params[:amount]
21
+ when 3184 then 'requires_action'
22
+ when 3178 then 'requires_payment_method'
23
+ when 3055 then 'requires_capture'
24
+ else
25
+ 'succeeded'
26
+ end
27
+ last_payment_error = params[:amount] == 3178 ? last_payment_error_generator(code: 'card_declined', decline_code: 'insufficient_funds', message: 'Not enough funds.') : nil
28
+ payment_intents[id] = Data.mock_payment_intent(
29
+ params.merge(
30
+ id: id,
31
+ status: status,
32
+ last_payment_error: last_payment_error
33
+ )
34
+ )
35
+
36
+ if params[:confirm] && status == 'succeeded'
37
+ payment_intents[id] = succeeded_payment_intent(payment_intents[id])
38
+ end
39
+
40
+ payment_intents[id].clone
41
+ end
42
+
43
+ def update_payment_intent(route, method_url, params, headers)
44
+ route =~ method_url
45
+ id = $1
46
+
47
+ payment_intent = assert_existence :payment_intent, id, payment_intents[id]
48
+ payment_intents[id] = Util.rmerge(payment_intent, params.select{ |k,v| ALLOWED_PARAMS.include?(k)})
49
+ end
50
+
51
+ def get_payment_intents(route, method_url, params, headers)
52
+ params[:offset] ||= 0
53
+ params[:limit] ||= 10
54
+
55
+ clone = payment_intents.clone
56
+
57
+ if params[:customer]
58
+ clone.delete_if { |k,v| v[:customer] != params[:customer] }
59
+ end
60
+
61
+ Data.mock_list_object(clone.values, params)
62
+ end
63
+
64
+ def get_payment_intent(route, method_url, params, headers)
65
+ route =~ method_url
66
+ payment_intent_id = $1 || params[:payment_intent]
67
+ payment_intent = assert_existence :payment_intent, payment_intent_id, payment_intents[payment_intent_id]
68
+
69
+ payment_intent = payment_intent.clone
70
+ payment_intent
71
+ end
72
+
73
+ def capture_payment_intent(route, method_url, params, headers)
74
+ route =~ method_url
75
+ payment_intent = assert_existence :payment_intent, $1, payment_intents[$1]
76
+
77
+ succeeded_payment_intent(payment_intent)
78
+ end
79
+
80
+ def confirm_payment_intent(route, method_url, params, headers)
81
+ route =~ method_url
82
+ payment_intent = assert_existence :payment_intent, $1, payment_intents[$1]
83
+
84
+ succeeded_payment_intent(payment_intent)
85
+ end
86
+
87
+ def cancel_payment_intent(route, method_url, params, headers)
88
+ route =~ method_url
89
+ payment_intent = assert_existence :payment_intent, $1, payment_intents[$1]
90
+
91
+ payment_intent[:status] = 'canceled'
92
+ payment_intent
93
+ end
94
+
95
+ private
96
+
97
+ def ensure_payment_intent_required_params(params)
98
+ if params[:amount].nil?
99
+ require_param(:amount)
100
+ elsif params[:currency].nil?
101
+ require_param(:currency)
102
+ elsif non_integer_charge_amount?(params)
103
+ raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', http_status: 400)
104
+ elsif non_positive_charge_amount?(params)
105
+ raise Stripe::InvalidRequestError.new('Invalid positive integer', 'amount', http_status: 400)
106
+ end
107
+ end
108
+
109
+ def non_integer_charge_amount?(params)
110
+ params[:amount] && !params[:amount].is_a?(Integer)
111
+ end
112
+
113
+ def non_positive_charge_amount?(params)
114
+ params[:amount] && params[:amount] < 1
115
+ end
116
+
117
+ def last_payment_error_generator(code: nil, message: nil, decline_code: nil)
118
+ {
119
+ code: code,
120
+ doc_url: "https://stripe.com/docs/error-codes/payment-intent-authentication-failure",
121
+ message: message,
122
+ decline_code: decline_code,
123
+ payment_method: {
124
+ id: "pm_1EwXFA2eZvKYlo2C0tlY091l",
125
+ object: "payment_method",
126
+ billing_details: {
127
+ address: {
128
+ city: nil,
129
+ country: nil,
130
+ line1: nil,
131
+ line2: nil,
132
+ postal_code: nil,
133
+ state: nil
134
+ },
135
+ email: nil,
136
+ name: "seller_08072019090000",
137
+ phone: nil
138
+ },
139
+ card: {
140
+ brand: "visa",
141
+ checks: {
142
+ address_line1_check: nil,
143
+ address_postal_code_check: nil,
144
+ cvc_check: "unchecked"
145
+ },
146
+ country: "US",
147
+ exp_month: 12,
148
+ exp_year: 2021,
149
+ fingerprint: "LQBhEmJnItuj3mxf",
150
+ funding: "credit",
151
+ generated_from: nil,
152
+ last4: "1629",
153
+ three_d_secure_usage: {
154
+ supported: true
155
+ },
156
+ wallet: nil
157
+ },
158
+ created: 1563208900,
159
+ customer: nil,
160
+ livemode: false,
161
+ metadata: {},
162
+ type: "card"
163
+ },
164
+ type: "invalid_request_error"
165
+ }
166
+ end
167
+
168
+ def succeeded_payment_intent(payment_intent)
169
+ payment_intent[:status] = 'succeeded'
170
+ btxn = new_balance_transaction('txn', { source: payment_intent[:id] })
171
+
172
+ payment_intent[:charges][:data] << Data.mock_charge(
173
+ balance_transaction: btxn,
174
+ amount: payment_intent[:amount],
175
+ currency: payment_intent[:currency]
176
+ )
177
+
178
+ payment_intent
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,120 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module PaymentMethods
4
+ ALLOWED_PARAMS = [:customer, :type]
5
+
6
+ def PaymentMethods.included(klass)
7
+ klass.add_handler 'post /v1/payment_methods', :new_payment_method
8
+ klass.add_handler 'get /v1/payment_methods/(.*)', :get_payment_method
9
+ klass.add_handler 'get /v1/payment_methods', :get_payment_methods
10
+ klass.add_handler 'post /v1/payment_methods/(.*)/attach', :attach_payment_method
11
+ klass.add_handler 'post /v1/payment_methods/(.*)/detach', :detach_payment_method
12
+ klass.add_handler 'post /v1/payment_methods/(.*)', :update_payment_method
13
+ end
14
+
15
+ # post /v1/payment_methods
16
+ def new_payment_method(route, method_url, params, headers)
17
+ id = new_id('pm')
18
+
19
+ ensure_payment_method_required_params(params)
20
+
21
+ payment_methods[id] = Data.mock_payment_method(
22
+ params.merge(
23
+ id: id
24
+ )
25
+ )
26
+
27
+ payment_methods[id].clone
28
+ end
29
+
30
+ #
31
+ # params: {:type=>"card", :customer=>"test_cus_3"}
32
+ #
33
+ # get /v1/payment_methods/:id
34
+ def get_payment_method(route, method_url, params, headers)
35
+ id = method_url.match(route)[1] || params[:payment_method]
36
+ payment_method = assert_existence :payment_method, id, payment_methods[id]
37
+
38
+ payment_method.clone
39
+ end
40
+
41
+ # get /v1/payment_methods
42
+ def get_payment_methods(route, method_url, params, headers)
43
+ params[:offset] ||= 0
44
+ params[:limit] ||= 10
45
+
46
+ clone = payment_methods.clone
47
+
48
+ if params[:customer]
49
+ clone.delete_if { |_k, v| v[:customer] != params[:customer] }
50
+ end
51
+
52
+ Data.mock_list_object(clone.values, params)
53
+ end
54
+
55
+ # post /v1/payment_methods/:id/attach
56
+ def attach_payment_method(route, method_url, params, headers)
57
+ stripe_account = headers && headers[:stripe_account] || Stripe.api_key
58
+ allowed_params = [:customer]
59
+
60
+ id = method_url.match(route)[1]
61
+
62
+ assert_existence :customer, params[:customer], customers[stripe_account][params[:customer]]
63
+
64
+ payment_method = assert_existence :payment_method, id, payment_methods[id]
65
+ payment_methods[id] = Util.rmerge(payment_method, params.select { |k, _v| allowed_params.include?(k) })
66
+ payment_methods[id].clone
67
+ end
68
+
69
+ # post /v1/payment_methods/:id/detach
70
+ def detach_payment_method(route, method_url, params, headers)
71
+ id = method_url.match(route)[1]
72
+
73
+ payment_method = assert_existence :payment_method, id, payment_methods[id]
74
+ payment_method[:customer] = nil
75
+
76
+ payment_method.clone
77
+ end
78
+
79
+ # post /v1/payment_methods/:id
80
+ def update_payment_method(route, method_url, params, headers)
81
+ allowed_params = [:billing_details, :card, :ideal, :sepa_debit, :metadata]
82
+
83
+ id = method_url.match(route)[1]
84
+
85
+ payment_method = assert_existence :payment_method, id, payment_methods[id]
86
+
87
+ if payment_method[:customer].nil?
88
+ raise Stripe::InvalidRequestError.new(
89
+ 'You must save this PaymentMethod to a customer before you can update it.',
90
+ nil,
91
+ http_status: 400
92
+ )
93
+ end
94
+
95
+ payment_methods[id] =
96
+ Util.rmerge(payment_method, params.select { |k, _v| allowed_params.include?(k)} )
97
+
98
+ payment_methods[id].clone
99
+ end
100
+
101
+ private
102
+
103
+ def ensure_payment_method_required_params(params)
104
+ require_param(:type) if params[:type].nil?
105
+
106
+ if invalid_type?(params[:type])
107
+ raise Stripe::InvalidRequestError.new(
108
+ 'Invalid type: must be one of card, ideal or sepa_debit',
109
+ nil,
110
+ http_status: 400
111
+ )
112
+ end
113
+ end
114
+
115
+ def invalid_type?(type)
116
+ !%w(card ideal sepa_debit).include?(type)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -34,7 +34,7 @@ module StripeMock
34
34
 
35
35
  def list_plans(route, method_url, params, headers)
36
36
  limit = params[:limit] ? params[:limit] : 10
37
- Data.mock_list_object(plans.values.first(limit), limit: limit)
37
+ Data.mock_list_object(plans.values.first(limit), params.merge!(limit: limit))
38
38
  end
39
39
 
40
40
  end
@@ -0,0 +1,44 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module Prices
4
+
5
+ def Prices.included(klass)
6
+ klass.add_handler 'post /v1/prices', :new_price
7
+ klass.add_handler 'post /v1/prices/(.*)', :update_price
8
+ klass.add_handler 'get /v1/prices/(.*)', :get_price
9
+ klass.add_handler 'get /v1/prices', :list_prices
10
+ end
11
+
12
+ def new_price(route, method_url, params, headers)
13
+ params[:id] ||= new_id('price')
14
+ validate_create_price_params(params)
15
+ prices[ params[:id] ] = Data.mock_price(params)
16
+ end
17
+
18
+ def update_price(route, method_url, params, headers)
19
+ route =~ method_url
20
+ assert_existence :price, $1, prices[$1]
21
+ prices[$1].merge!(params)
22
+ end
23
+
24
+ def get_price(route, method_url, params, headers)
25
+ route =~ method_url
26
+ assert_existence :price, $1, prices[$1]
27
+ end
28
+
29
+ def list_prices(route, method_url, params, headers)
30
+ limit = params[:limit] ? params[:limit] : 10
31
+ price_data = prices.values
32
+ validate_list_prices_params(params)
33
+
34
+ if params.key?(:lookup_keys)
35
+ price_data.select! do |price|
36
+ params[:lookup_keys].include?(price[:lookup_key])
37
+ end
38
+ end
39
+
40
+ Data.mock_list_object(price_data.first(limit), params.merge!(limit: limit))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -11,6 +11,7 @@ module StripeMock
11
11
 
12
12
  def create_product(_route, _method_url, params, _headers)
13
13
  params[:id] ||= new_id('prod')
14
+ validate_create_product_params(params)
14
15
  products[params[:id]] = Data.mock_product(params)
15
16
  end
16
17
 
@@ -0,0 +1,93 @@
1
+ module StripeMock
2
+ module RequestHandlers
3
+ module SetupIntents
4
+ ALLOWED_PARAMS = [
5
+ :confirm,
6
+ :customer,
7
+ :description,
8
+ :metadata,
9
+ :on_behalf_of,
10
+ :payment_method,
11
+ :payment_method_options,
12
+ :payment_method_types,
13
+ :return_url,
14
+ :usage
15
+ ]
16
+
17
+ def SetupIntents.included(klass)
18
+ klass.add_handler 'post /v1/setup_intents', :new_setup_intent
19
+ klass.add_handler 'get /v1/setup_intents', :get_setup_intents
20
+ klass.add_handler 'get /v1/setup_intents/(.*)', :get_setup_intent
21
+ klass.add_handler 'post /v1/setup_intents/(.*)/confirm', :confirm_setup_intent
22
+ klass.add_handler 'post /v1/setup_intents/(.*)/cancel', :cancel_setup_intent
23
+ klass.add_handler 'post /v1/setup_intents/(.*)', :update_setup_intent
24
+ end
25
+
26
+ def new_setup_intent(route, method_url, params, headers)
27
+ id = new_id('si')
28
+
29
+ setup_intents[id] = Data.mock_setup_intent(
30
+ params.merge(
31
+ id: id
32
+ )
33
+ )
34
+
35
+ setup_intents[id].clone
36
+ end
37
+
38
+ def update_setup_intent(route, method_url, params, headers)
39
+ route =~ method_url
40
+ id = $1
41
+
42
+ setup_intent = assert_existence :setup_intent, id, setup_intents[id]
43
+ setup_intents[id] = Util.rmerge(setup_intent, params.select{ |k,v| ALLOWED_PARAMS.include?(k)})
44
+ end
45
+
46
+ def get_setup_intents(route, method_url, params, headers)
47
+ params[:offset] ||= 0
48
+ params[:limit] ||= 10
49
+
50
+ clone = setup_intents.clone
51
+
52
+ if params[:customer]
53
+ clone.delete_if { |k,v| v[:customer] != params[:customer] }
54
+ end
55
+
56
+ Data.mock_list_object(clone.values, params)
57
+ end
58
+
59
+ def get_setup_intent(route, method_url, params, headers)
60
+ route =~ method_url
61
+ setup_intent_id = $1 || params[:setup_intent]
62
+ setup_intent = assert_existence :setup_intent, setup_intent_id, setup_intents[setup_intent_id]
63
+
64
+ setup_intent = setup_intent.clone
65
+ setup_intent
66
+ end
67
+
68
+ def capture_setup_intent(route, method_url, params, headers)
69
+ route =~ method_url
70
+ setup_intent = assert_existence :setup_intent, $1, setup_intents[$1]
71
+
72
+ setup_intent[:status] = 'succeeded'
73
+ setup_intent
74
+ end
75
+
76
+ def confirm_setup_intent(route, method_url, params, headers)
77
+ route =~ method_url
78
+ setup_intent = assert_existence :setup_intent, $1, setup_intents[$1]
79
+
80
+ setup_intent[:status] = 'succeeded'
81
+ setup_intent
82
+ end
83
+
84
+ def cancel_setup_intent(route, method_url, params, headers)
85
+ route =~ method_url
86
+ setup_intent = assert_existence :setup_intent, $1, setup_intents[$1]
87
+
88
+ setup_intent[:status] = 'canceled'
89
+ setup_intent
90
+ end
91
+ end
92
+ end
93
+ end