stripe-ruby-mock 3.0.1 → 3.1.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -5
  3. data/CHANGELOG.md +28 -15
  4. data/Gemfile +1 -0
  5. data/lib/stripe_mock.rb +4 -0
  6. data/lib/stripe_mock/api/client.rb +1 -1
  7. data/lib/stripe_mock/api/instance.rb +1 -1
  8. data/lib/stripe_mock/api/webhooks.rb +2 -0
  9. data/lib/stripe_mock/client.rb +2 -1
  10. data/lib/stripe_mock/data.rb +127 -25
  11. data/lib/stripe_mock/data/list.rb +31 -6
  12. data/lib/stripe_mock/instance.rb +7 -2
  13. data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
  14. data/lib/stripe_mock/request_handlers/charges.rb +6 -4
  15. data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -0
  16. data/lib/stripe_mock/request_handlers/customers.rb +22 -13
  17. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
  18. data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
  19. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +12 -7
  20. data/lib/stripe_mock/request_handlers/invoices.rb +4 -3
  21. data/lib/stripe_mock/request_handlers/payment_methods.rb +8 -5
  22. data/lib/stripe_mock/request_handlers/prices.rb +44 -0
  23. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  24. data/lib/stripe_mock/request_handlers/subscriptions.rb +29 -19
  25. data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
  26. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +32 -0
  27. data/lib/stripe_mock/test_strategies/base.rb +26 -0
  28. data/lib/stripe_mock/version.rb +1 -1
  29. data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
  30. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
  31. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
  32. data/spec/instance_spec.rb +4 -6
  33. data/spec/list_spec.rb +23 -0
  34. data/spec/server_spec.rb +4 -2
  35. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  36. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  37. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  38. data/spec/shared_stripe_examples/checkout_examples.rb +20 -1
  39. data/spec/shared_stripe_examples/customer_examples.rb +11 -13
  40. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  41. data/spec/shared_stripe_examples/invoice_examples.rb +8 -8
  42. data/spec/shared_stripe_examples/payment_method_examples.rb +332 -68
  43. data/spec/shared_stripe_examples/price_examples.rb +183 -0
  44. data/spec/shared_stripe_examples/subscription_examples.rb +115 -8
  45. data/spec/spec_helper.rb +4 -0
  46. data/spec/stripe_mock_spec.rb +2 -2
  47. data/spec/support/stripe_examples.rb +5 -1
  48. data/stripe-ruby-mock.gemspec +6 -1
  49. metadata +25 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7918d71c6145222a77feaeea20d2e5c211ce53c4
4
- data.tar.gz: 1aa548101a97a4fb5d5afe9294928b65fe0491d4
2
+ SHA256:
3
+ metadata.gz: e44063ad0593364e5b9a85f514113c0dd8222e95440410ff9989545e2b947f08
4
+ data.tar.gz: 3bb136ecba532f8e6e8078b5eba0c8877876d6cf9a0f9c66cb311fd8271e9242
5
5
  SHA512:
6
- metadata.gz: d83ccd0ba75faea9acce0f2f978099f215e22cd60563e80375a8e6f40ba3879e9b3d00b4a467f23797a80320e641629a60c20ebc675c2b7bfc92fedc055bc0d2
7
- data.tar.gz: 2e84b51981c315096a514e6d0e6caf8085d239a800e6dd47590d323bedd492d9c79250c448caa70c7a9ac8ae2f7d62b55d5928b2d489ff379b35e448d90584e0
6
+ metadata.gz: 36e31f008894062f3678c14158436b50a72699977d14c9419e36b53ca4c22d68d3f2bc5f72fac39abb0adcd01121ae3223b43cc71bc79c54159fcba343131d3e
7
+ data.tar.gz: a49ae0d98ffa6560dac087acfeff75ea041c8d63a1703b7e72214321362208ef4b38ef9411f5698022c2fdc1003345e21f1c10e02309a93ce624fbb67f7108e6
data/.travis.yml CHANGED
@@ -1,13 +1,11 @@
1
- dist: trusty
2
- group: deprecated-2017Q2
3
1
  sudo: required
4
2
  language: ruby
5
3
  rvm:
6
4
  - 2.4.6
7
5
  - 2.5.5
8
6
  - 2.6.3
7
+ - 2.7.0
9
8
  before_install:
10
- - rvm 2.1.10 do gem install mime-types -v 2.6.2
11
9
  - gem install bundler -v '< 2'
12
10
  before_script:
13
11
  - "sudo touch /var/log/stripe-mock-server.log"
@@ -16,7 +14,7 @@ script: "bundle exec rspec && bundle exec rspec -t live"
16
14
 
17
15
  env:
18
16
  global:
19
- - IS_TRAVIS=true STRIPE_TEST_SECRET_KEY_A=sk_test_BsztzqQjzd7lqkgo1LjEG5DF00KzH7tWKF STRIPE_TEST_SECRET_KEY_B=sk_test_rKCEu0x8jzg6cKPqoey8kUPQ00usQO3KYE STRIPE_TEST_SECRET_KEY_C=sk_test_qeaB7R6Ywp8sC9pzd1ZIABH700YLC7nhmZ
17
+ - IS_TRAVIS=true STRIPE_TEST_SECRET_KEY_A=sk_test_BsztzqQjzd7lqkgo1LjEG5DF00KzH7tWKF STRIPE_TEST_SECRET_KEY_B=sk_test_rKCEu0x8jzg6cKPqoey8kUPQ00usQO3KYE STRIPE_TEST_SECRET_KEY_C=sk_test_qeaB7R6Ywp8sC9pzd1ZIABH700YLC7nhmZ STRIPE_TEST_SECRET_KEY_D=sk_test_r1NwHkUW7UyoozyP4aEBD6cs00CI5uDiGq
20
18
 
21
19
  notifications:
22
20
  webhooks:
@@ -25,4 +23,3 @@ notifications:
25
23
  on_success: change # options: [always|never|change] default: always
26
24
  on_failure: always # options: [always|never|change] default: always
27
25
  on_start: false # default: false
28
-
data/CHANGELOG.md CHANGED
@@ -1,22 +1,35 @@
1
- ### 3.0.2 (Next)
1
+ ### 3.1.0.rc2 (pre-release 2021-03-03)
2
2
 
3
- * Your contribution here.
3
+ - [#767](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/767): Fixes tests and more [@lpsBetty](https://github.com/lpsBetty)
4
+
5
+ ### 3.1.0.rc1 (pre-release 2021-02-17)
6
+
7
+ - [#765](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/765): Properly set the status of a trialing subscription. [@csalvato](https://github.com/csalvato)
8
+ - [#764](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/764): Fixes erroneous error message when fetching upcoming invoices. [@csalvato](https://github.com/csalvato)
9
+ - [#762](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/762): Support Stripe Connect with Customers by adding stripe_account header namespace for customer object [@csalvato](https://github.com/csalvato)
10
+ - [#755](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/755): Add allowed params to subscriptions [@dominikdarnel ](https://github.com/dominikdarnel)
11
+ - [#748](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/758): Support Prices - [@hidenba](https://github.com/hidenba) and [@jamesprior](https://github.com/jamesprior).
12
+ - [#747](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/747/files): Fix ruby 2.7 deprecation warnings. Adds Ruby 3.0.0 compatibility. [@coding-chimp](https://github.com/coding-chimp)
13
+ - [#715](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/715): Added application_fee_amount to mock charge object - [@espen](https://github.com/espen)
14
+ - [#709](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/709): Remove unnecessary check on customer's currency - [@coorasse](https://github.com/coorasse)
4
15
 
5
16
  ### 3.0.1 (TBD)
6
- * Added Changelog file
7
- * [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
8
- * [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
9
- * [#682](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/682): Prevent customer metadata from being overwritten with each update - [@sethkrasnianski](https://github.com/sethkrasnianski).
10
- * [#679](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/679): Fix for [#678](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/678) Add active filter to Data::List - [@rnmp](https://github.com/rnmp).
11
- * [#668](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/668): Fix for [#665](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/665) Allow to remove discount from customer - [@mnin](https://github.com/mnin).
12
- * [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
13
- Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
14
- * [#664](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/664): Bugfix: pass through PaymentIntent amount to mocked Charge - [@typeoneerror](https://github.com/typeoneerror).
15
- * [#654](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/654): fix for [#626](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/626) Added missing decline codes - [@iCreateJB](https://github.com/iCreateJB).
16
- * [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
17
- * [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).
17
+
18
+ - Added Changelog file
19
+ - [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
20
+ - [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
21
+ - [#682](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/682): Prevent customer metadata from being overwritten with each update - [@sethkrasnianski](https://github.com/sethkrasnianski).
22
+ - [#679](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/679): Fix for [#678](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/678) Add active filter to Data::List - [@rnmp](https://github.com/rnmp).
23
+ - [#668](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/668): Fix for [#665](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/665) Allow to remove discount from customer - [@mnin](https://github.com/mnin).
24
+ - [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
25
+ Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
26
+ - [#664](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/664): Bugfix: pass through PaymentIntent amount to mocked Charge - [@typeoneerror](https://github.com/typeoneerror).
27
+ - [#654](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/654): fix for [#626](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/626) Added missing decline codes - [@iCreateJB](https://github.com/iCreateJB).
28
+ - [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
29
+ - [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).
18
30
 
19
31
  ### 3.0.0 (2019-12-17)
20
32
 
21
33
  ##### the main thing is:
22
- - [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5
34
+
35
+ - [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  group :test do
9
9
  gem 'rake'
10
+ gem 'dotenv'
10
11
  end
11
12
 
12
13
  gemspec
data/lib/stripe_mock.rb CHANGED
@@ -47,6 +47,8 @@ require 'stripe_mock/request_handlers/helpers/token_helpers.rb'
47
47
 
48
48
  require 'stripe_mock/request_handlers/validators/param_validators.rb'
49
49
 
50
+ require 'stripe_mock/request_handlers/account_links.rb'
51
+ require 'stripe_mock/request_handlers/express_login_links.rb'
50
52
  require 'stripe_mock/request_handlers/accounts.rb'
51
53
  require 'stripe_mock/request_handlers/external_accounts.rb'
52
54
  require 'stripe_mock/request_handlers/balance.rb'
@@ -62,6 +64,7 @@ require 'stripe_mock/request_handlers/invoices.rb'
62
64
  require 'stripe_mock/request_handlers/invoice_items.rb'
63
65
  require 'stripe_mock/request_handlers/orders.rb'
64
66
  require 'stripe_mock/request_handlers/plans.rb'
67
+ require 'stripe_mock/request_handlers/prices.rb'
65
68
  require 'stripe_mock/request_handlers/recipients.rb'
66
69
  require 'stripe_mock/request_handlers/refunds.rb'
67
70
  require 'stripe_mock/request_handlers/transfers.rb'
@@ -77,6 +80,7 @@ require 'stripe_mock/request_handlers/ephemeral_key.rb'
77
80
  require 'stripe_mock/request_handlers/products.rb'
78
81
  require 'stripe_mock/request_handlers/tax_rates.rb'
79
82
  require 'stripe_mock/request_handlers/checkout.rb'
83
+ require 'stripe_mock/request_handlers/checkout_session.rb'
80
84
  require 'stripe_mock/instance'
81
85
 
82
86
  require 'stripe_mock/test_strategies/base.rb'
@@ -8,7 +8,7 @@ module StripeMock
8
8
  return false if @state == 'live'
9
9
  return @client unless @client.nil?
10
10
 
11
- Stripe::StripeClient.send(:define_method, :execute_request) { |*args| StripeMock.redirect_to_mock_server(*args) }
11
+ Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| StripeMock.redirect_to_mock_server(*args, **keyword_args) }
12
12
  @client = StripeMock::Client.new(port)
13
13
  @state = 'remote'
14
14
  @client
@@ -7,7 +7,7 @@ module StripeMock
7
7
  def self.start
8
8
  return false if @state == 'live'
9
9
  @instance = instance = Instance.new
10
- Stripe::StripeClient.send(:define_method, :execute_request) { |*args| instance.mock_request(*args) }
10
+ Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| instance.mock_request(*args, **keyword_args) }
11
11
  @state = 'local'
12
12
  end
13
13
 
@@ -72,6 +72,8 @@ module StripeMock
72
72
  'invoiceitem.created',
73
73
  'invoiceitem.updated',
74
74
  'invoiceitem.deleted',
75
+ 'payment_intent.succeeded',
76
+ 'payment_intent.payment_failed',
75
77
  'plan.created',
76
78
  'plan.updated',
77
79
  'plan.deleted',
@@ -18,7 +18,8 @@ module StripeMock
18
18
  @pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
19
19
  response, api_key = result
20
20
  if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
21
- raise Stripe::InvalidRequestError.new(*response[:error_params])
21
+ args, keyword_args = response[:error_params].first(2), response[:error_params].last
22
+ raise Stripe::InvalidRequestError.new(*args, **keyword_args)
22
23
  end
23
24
  }
24
25
  end
@@ -101,6 +101,27 @@ module StripeMock
101
101
  }.merge(params)
102
102
  end
103
103
 
104
+ def self.mock_account_link(params = {})
105
+ now = Time.now.to_i
106
+ {
107
+ object: 'account_link',
108
+ created: now,
109
+ expires_at: now + 300,
110
+ url: 'https://connect.stripe.com/setup/c/iB0ph1cPnRLY',
111
+ data: {}
112
+ }.merge(params)
113
+ end
114
+
115
+ def self.mock_express_login_link(params = {})
116
+ now = Time.now.to_i
117
+ {
118
+ object: 'login_link',
119
+ created: now,
120
+ url: 'https://connect.stripe.com/express/Ln7FfnNpUcCU',
121
+ data: {}
122
+ }.merge(params)
123
+ end
124
+
104
125
  def self.mock_tax_rate(params)
105
126
  {
106
127
  id: 'test_cus_default',
@@ -119,7 +140,7 @@ module StripeMock
119
140
 
120
141
  def self.mock_customer(sources, params)
121
142
  cus_id = params[:id] || "test_cus_default"
122
- currency = params[:currency] || StripeMock.default_currency
143
+ currency = params[:currency]
123
144
  sources.each {|source| source[:customer] = cus_id}
124
145
  {
125
146
  email: 'stripe_mock@example.com',
@@ -142,12 +163,14 @@ module StripeMock
142
163
  sources: {
143
164
  object: "list",
144
165
  total_count: sources.size,
166
+ has_more: false,
145
167
  url: "/v1/customers/#{cus_id}/sources",
146
168
  data: sources
147
169
  },
148
170
  subscriptions: {
149
171
  object: "list",
150
172
  total_count: 0,
173
+ has_more: false,
151
174
  url: "/v1/customers/#{cus_id}/subscriptions",
152
175
  data: []
153
176
  },
@@ -166,6 +189,7 @@ module StripeMock
166
189
  paid: true,
167
190
  amount: 0,
168
191
  application_fee: nil,
192
+ application_fee_amount: nil,
169
193
  currency: currency,
170
194
  destination: nil,
171
195
  fraud_details: {},
@@ -339,6 +363,7 @@ module StripeMock
339
363
  },
340
364
  cancel_at_period_end: false,
341
365
  canceled_at: nil,
366
+ collection_method: 'charge_automatically',
342
367
  ended_at: nil,
343
368
  start: 1308595038,
344
369
  object: 'subscription',
@@ -350,8 +375,10 @@ module StripeMock
350
375
  discount: nil,
351
376
  metadata: {},
352
377
  default_tax_rates: nil,
378
+ default_payment_method: nil,
353
379
  pending_invoice_item_interval: nil,
354
- next_pending_invoice_item_invoice: nil
380
+ next_pending_invoice_item_invoice: nil,
381
+ latest_invoice: nil
355
382
  }, params)
356
383
  end
357
384
 
@@ -371,6 +398,7 @@ module StripeMock
371
398
  lines: {
372
399
  object: "list",
373
400
  total_count: lines.count,
401
+ has_more: false,
374
402
  url: "/v1/invoices/#{in_id}/lines",
375
403
  data: lines
376
404
  },
@@ -554,6 +582,34 @@ module StripeMock
554
582
  }.merge(params)
555
583
  end
556
584
 
585
+ def self.mock_price(params={})
586
+ currency = params[:currency] || StripeMock.default_currency
587
+ {
588
+ id: "mock_price_123",
589
+ object: "price",
590
+ active: true,
591
+ billing_scheme: "per_unit",
592
+ created: 1593044959,
593
+ currency: currency,
594
+ livemode: false,
595
+ lookup_key: nil,
596
+ metadata: {},
597
+ nickname: 'My Mock Price',
598
+ product: "mock_prod_NONEXIST", # override this with your own existing product id
599
+ recurring: {
600
+ aggregate_usage: nil,
601
+ interval: "month",
602
+ interval_count: 1,
603
+ usage_type: "licensed"
604
+ },
605
+ tiers_mode: nil,
606
+ transform_quantity: nil,
607
+ type: "recurring",
608
+ unit_amount: 2000,
609
+ unit_amount_decimal: "2000"
610
+ }.merge(params)
611
+ end
612
+
557
613
  def self.mock_product(params={})
558
614
  {
559
615
  id: "mock_prod_abc123",
@@ -601,6 +657,7 @@ module StripeMock
601
657
  object: "list",
602
658
  url: "/v1/recipients/#{rp_id}/cards",
603
659
  data: cards,
660
+ has_more: false,
604
661
  total_count: cards.count
605
662
  },
606
663
  default_card: nil
@@ -1008,6 +1065,16 @@ module StripeMock
1008
1065
  bitcoin_receiver: 1545182
1009
1066
  }
1010
1067
  }],
1068
+ instant_available: [
1069
+ {
1070
+ currency: "usd",
1071
+ amount: usd_balance,
1072
+ source_types: {
1073
+ card: 25907032203,
1074
+ bank_account: 108476658,
1075
+ bitcoin_receiver: 1545182
1076
+ }
1077
+ }],
1011
1078
  connect_reserved: [
1012
1079
  {
1013
1080
  currency: "usd",
@@ -1072,9 +1139,9 @@ module StripeMock
1072
1139
  end
1073
1140
 
1074
1141
  def self.mock_subscription_item(params = {})
1075
- iid = params[:id] || 'test_txn_default'
1142
+ id = params[:id] || 'test_si_default'
1076
1143
  {
1077
- id: iid,
1144
+ id: id,
1078
1145
  object: 'subscription_item',
1079
1146
  created: 1504716183,
1080
1147
  metadata: {
@@ -1167,29 +1234,64 @@ module StripeMock
1167
1234
  end
1168
1235
 
1169
1236
  def self.mock_payment_method(params = {})
1170
- payment_method_id = params[:id] || "pm_1ExEuFL2DI6wht39WNJgbybl"
1171
- {
1172
- id: payment_method_id,
1173
- object: "payment_method",
1174
- type: "card",
1175
- billing_details: {},
1176
- card: {
1177
- brand: "visa",
1178
- checks: { address_line1_check: nil, address_postal_code_check: nil, cvc_check: "pass" },
1179
- country: "FR",
1180
- exp_month: 2,
1181
- exp_year: 2022,
1182
- fingerprint: "Hr3Ly5z5IYxsokWA",
1183
- funding: "credit",
1184
- last4: "3155",
1185
- three_d_secure_usage: { supported: true }
1237
+ payment_method_id = params[:id] || 'pm_1ExEuFL2DI6wht39WNJgbybl'
1238
+
1239
+ type = params[:type].to_sym
1240
+ data = {
1241
+ card: {
1242
+ brand: 'visa',
1243
+ checks: {
1244
+ address_line1_check: nil,
1245
+ address_postal_code_check: nil,
1246
+ cvc_check: 'pass'
1186
1247
  },
1187
- customer: params[:customer] || nil,
1188
- metadata: {
1189
- order_id: "123456789"
1190
- }
1248
+ country: 'FR',
1249
+ exp_month: 2,
1250
+ exp_year: 2022,
1251
+ fingerprint: 'Hr3Ly5z5IYxsokWA',
1252
+ funding: 'credit',
1253
+ generated_from: nil,
1254
+ last4: '3155',
1255
+ three_d_secure_usage: { supported: true },
1256
+ wallet: nil
1257
+ },
1258
+ ideal: {
1259
+ bank: 'ing',
1260
+ bic: 'INGBNL2A',
1261
+ iban_last4: '****',
1262
+ verified_name: 'JENNY ROSEN'
1263
+ },
1264
+ sepa_debit: {
1265
+ bank_code: '37040044',
1266
+ branch_code: '',
1267
+ country: 'DE',
1268
+ fingerprint: 'FD81kbVPe7M05BMj',
1269
+ last4: '3000'
1270
+ }
1271
+ }
1191
1272
 
1192
- }.merge(params)
1273
+ {
1274
+ id: payment_method_id,
1275
+ object: 'payment_method',
1276
+ type: params[:type],
1277
+ billing_details: {
1278
+ address: {
1279
+ city: 'New Orleans',
1280
+ country: 'US',
1281
+ line1: 'Bourbon Street 23',
1282
+ line2: nil,
1283
+ postal_code: '10000',
1284
+ state: nil
1285
+ },
1286
+ email: 'foo@bar.com',
1287
+ name: 'John Dolton',
1288
+ phone: nil
1289
+ },
1290
+ customer: params[:customer] || nil,
1291
+ metadata: {
1292
+ order_id: '123456789'
1293
+ }
1294
+ }.merge(type => data[type]).merge(params)
1193
1295
  end
1194
1296
 
1195
1297
  def self.mock_setup_intent(params = {})
@@ -9,12 +9,9 @@ module StripeMock
9
9
  @starting_after = options[:starting_after]
10
10
  @ending_before = options[:ending_before]
11
11
  @active = options[:active]
12
- if @data.first.is_a?(Hash) && @data.first[:created]
13
- @data.sort_by! { |x| x[:created] }
14
- @data.reverse!
15
- elsif @data.first.respond_to?(:created)
16
- @data.sort_by { |x| x.created }
17
- @data.reverse!
12
+ if contains_stripe_objects?
13
+ prune_deleted_data
14
+ sort_data
18
15
  end
19
16
  end
20
17
 
@@ -76,6 +73,34 @@ module StripeMock
76
73
  "#{first_object.class.to_s.split('::')[-1].downcase}s"
77
74
  end
78
75
  end
76
+
77
+ def contains_stripe_objects?
78
+ return false if data.empty?
79
+
80
+ object = data.first
81
+ object.is_a?(Stripe::StripeObject) || (
82
+ object.is_a?(Hash) && [:created, :deleted].any? { |k| object.key?(k) }
83
+ )
84
+ end
85
+
86
+ def prune_deleted_data
87
+ data.reject! do |object|
88
+ (object.is_a?(Hash) && object[:deleted]) ||
89
+ (object.is_a?(Stripe::StripeObject) && object.deleted?)
90
+ end
91
+ end
92
+
93
+ def sort_data
94
+ # Reverse must follow sort to preserve existing test dependencies. The
95
+ # alternative would be to simply reverse lhs and rhs in the comparison,
96
+ # however, being a stable sort this breaks the existing dependency when
97
+ # more than one record share the same `created` value.
98
+ @data = data.sort { |lhs, rhs| sort_val(lhs) <=> sort_val(rhs) }.reverse
99
+ end
100
+
101
+ def sort_val(object)
102
+ object.is_a?(Stripe::StripeObject) ? object.created : object[:created]
103
+ end
79
104
  end
80
105
  end
81
106
  end