stripe-ruby-mock 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rspec_tests.yml +38 -0
  3. data/.rspec +2 -1
  4. data/CHANGELOG.md +69 -0
  5. data/Gemfile +1 -0
  6. data/README.md +13 -5
  7. data/lib/stripe_mock/api/client.rb +1 -1
  8. data/lib/stripe_mock/api/errors.rb +3 -0
  9. data/lib/stripe_mock/api/instance.rb +1 -1
  10. data/lib/stripe_mock/api/webhooks.rb +66 -25
  11. data/lib/stripe_mock/client.rb +2 -1
  12. data/lib/stripe_mock/data/list.rb +42 -9
  13. data/lib/stripe_mock/data.rb +242 -31
  14. data/lib/stripe_mock/instance.rb +14 -3
  15. data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
  16. data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
  17. data/lib/stripe_mock/request_handlers/charges.rb +11 -4
  18. data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
  19. data/lib/stripe_mock/request_handlers/customers.rb +35 -18
  20. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
  21. data/lib/stripe_mock/request_handlers/events.rb +30 -3
  22. data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
  23. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -0
  24. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
  25. data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
  26. data/lib/stripe_mock/request_handlers/payment_intents.rb +19 -1
  27. data/lib/stripe_mock/request_handlers/payment_methods.rb +10 -24
  28. data/lib/stripe_mock/request_handlers/plans.rb +1 -1
  29. data/lib/stripe_mock/request_handlers/prices.rb +62 -0
  30. data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
  31. data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
  32. data/lib/stripe_mock/request_handlers/setup_intents.rb +16 -9
  33. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  34. data/lib/stripe_mock/request_handlers/subscriptions.rb +120 -21
  35. data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
  36. data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
  37. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +33 -4
  38. data/lib/stripe_mock/server.rb +2 -2
  39. data/lib/stripe_mock/test_strategies/base.rb +62 -10
  40. data/lib/stripe_mock/version.rb +1 -1
  41. data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
  42. data/lib/stripe_mock/webhook_fixtures/balance.available.json +27 -15
  43. data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
  44. data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
  45. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +49 -120
  46. data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
  47. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
  48. data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
  49. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
  50. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
  51. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
  52. data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -46
  53. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
  54. data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
  55. data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
  56. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
  57. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
  58. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
  59. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -47
  60. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
  61. data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
  62. data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
  63. data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
  64. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
  65. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
  66. data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
  67. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
  68. data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
  69. data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
  70. data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
  71. data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
  72. data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
  73. data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
  74. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +225 -0
  75. data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
  76. data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
  77. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +196 -0
  78. data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
  79. data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
  80. data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
  81. data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
  82. data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
  83. data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
  84. data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
  85. data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
  86. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
  87. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
  88. data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
  89. data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
  90. data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
  91. data/lib/stripe_mock/webhook_fixtures/product.created.json +19 -13
  92. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
  93. data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
  94. data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
  95. data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
  96. data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
  97. data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
  98. data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
  99. data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
  100. data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
  101. data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
  102. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
  103. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
  104. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
  105. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
  106. data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
  107. data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
  108. data/lib/stripe_mock.rb +7 -0
  109. data/spec/instance_spec.rb +7 -7
  110. data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
  111. data/spec/list_spec.rb +38 -0
  112. data/spec/readme_spec.rb +1 -1
  113. data/spec/server_spec.rb +4 -2
  114. data/spec/shared_stripe_examples/account_examples.rb +9 -1
  115. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  116. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  117. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  118. data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
  119. data/spec/shared_stripe_examples/customer_examples.rb +49 -23
  120. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  121. data/spec/shared_stripe_examples/invoice_examples.rb +29 -8
  122. data/spec/shared_stripe_examples/payment_intent_examples.rb +84 -0
  123. data/spec/shared_stripe_examples/payment_method_examples.rb +336 -67
  124. data/spec/shared_stripe_examples/price_examples.rb +223 -0
  125. data/spec/shared_stripe_examples/product_examples.rb +1 -9
  126. data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
  127. data/spec/shared_stripe_examples/refund_examples.rb +13 -0
  128. data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
  129. data/spec/shared_stripe_examples/subscription_examples.rb +361 -9
  130. data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
  131. data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
  132. data/spec/spec_helper.rb +4 -0
  133. data/spec/stripe_mock_spec.rb +2 -2
  134. data/spec/support/stripe_examples.rb +8 -1
  135. data/stripe-ruby-mock.gemspec +7 -2
  136. metadata +73 -12
  137. data/.travis.yml +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 83e0a13431e08fd71904300dbc7717e48deead7f
4
- data.tar.gz: 481c5c3a5d1643107ddf35fbaf14e0f8bdd36f72
2
+ SHA256:
3
+ metadata.gz: 7b5b1b83df91e8e6fd700456710804749b9b1008e572fd8c74eec4f1519e8a49
4
+ data.tar.gz: bf362cf2fe9aa556e155df2b61076248335e3b2a43f69e0e6fc046406d65da57
5
5
  SHA512:
6
- metadata.gz: 46c6533cfb41b36eaa7be7ac93a54e2d7f3f5c74eb2e48c1473c21f88c49b65011153719c2b9f62cf5f1157a6e7938ea3a84ff133c363445a5212e9dc6a59682
7
- data.tar.gz: 1d09905741e5fa10537abfedb94db03b5c9475db967476b5c8e87c460ae46821e07d89455f008ba7c902b61adcf751b16ed812c9fd5bf949c5f4de3336b32491
6
+ metadata.gz: a397bf1b196f62bb7c8d76f79e2582f6d6594d20ddb9473b8dd5e7680c1844620a29456cddd8be8c5d9b785f4317ea1b092b340f841ccdbef92d849c6bb116e7
7
+ data.tar.gz: 90f97fe65c4dcd10eaa853aec740bce21c56b8df57bc1a589acc6f13ebf1b65943731b50f820d9f8eaa77954673f78b34bb62b326cbb7c71f5692a0b74a347c0
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Tests
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.6', '2.7', '3.0']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rspec
data/.rspec CHANGED
@@ -1 +1,2 @@
1
- --colour --format documentation
1
+ --colour
2
+ --format progress
data/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ ### Unreleased
2
+
3
+ - [#693](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/693) gemspec: add change,issue,source_code URL by [@mtmail](https://github.com/mtmail)
4
+ - [#700](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/700) update the balance API to respond with instant_available by [@iamnader](https://github.com/iamnader)
5
+ - [#687](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/687) Add PaymentIntent Webhooks by [@klaustopher](https://github.com/klaustopher)
6
+ - [#708](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/708) Implement Stripe::Checkout::Session.retrieve by [@coorasse](https://github.com/coorasse)
7
+ - [#711](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/711) Adding account link mock by [@amenon](https://github.com/amenon)
8
+ - [#715](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/715) Added application_fee_amount to mock charge object by [@espen](https://github.com/espen)
9
+ - [#694](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/694) Introduce ideal and sepa_debit types for PaymentMethod by [@mnin](https://github.com/mnin)
10
+ - [#720](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/720) Add additional parameters by [@rpietraszko](https://github.com/rpietraszko)
11
+ - [#695](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/695) Add `has_more` attribute to all ListObject instances by [@gbp](https://github.com/gbp)
12
+ - [#727](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/727) Fix List initialize error with deleted records by [@jmulieri](https://github.com/jmulieri)
13
+ - [#739](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/739) Add data to account links by [@dudyn5ky1](https://github.com/dudyn5ky1)
14
+ - [#756](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/756) Added #715 PR to changelog by [@espen](https://github.com/espen)
15
+ - [#759](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/759) Adding express dashboard login link mock by [@rohitbegani](https://github.com/rohitbegani)
16
+ - [#747](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/747) Fix ruby 2.7 deprecation warnings by [@coding-chimp](https://github.com/coding-chimp)
17
+ - [#762](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/762) Support Stripe Connect by adding stripe_account header namespace for customers by [@csalvato](https://github.com/csalvato)
18
+ - [#758](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/758) Create price by [@jamesprior](https://github.com/jamesprior)
19
+ - [#730](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/730) support on price api by [@hidenba](https://github.com/hidenba)
20
+ - [#764](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/764) Fixes erroneous error message when fetching upcoming invoices. by [@csalvato](https://github.com/csalvato)
21
+ - [#765](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/765) Properly set the status of a trialing subscription by [@csalvato](https://github.com/csalvato)
22
+ - [#755](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/755) Add allowed params to subscriptions by [@dominikdarnel](https://github.com/dominikdarnel)
23
+ - [#709](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/709) Remove unnecessary check on customer's currency by [@coorasse](https://github.com/coorasse)
24
+
25
+ - [#806](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/806) - Remove `payment_method_types` from required arguments for `Stripe::Checkout::Session`
26
+ - [#806](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/806) - Raise more helpful exception when Stripe::Price cannot be found within a `Stripe::Checkout::Session` `line_items` argument.
27
+
28
+
29
+ ### 3.1.0.rc3 (pre-release 2021-07-14)
30
+
31
+ - [#785](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/785): `Stripe::Product` no longer requires `type`. [@TastyPi](https://github.com/TastyPi)
32
+ - [#784](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/784): Fix "Wrong number of arguments" error in tests. [@TastyPi](https://github.com/TastyPi)
33
+ - [#782](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/782): Support expanding `setup_intent` in `Stripe::Checkout::Session`. [@TastyPi](https://github.com/TastyPi)
34
+
35
+ ### 3.1.0.rc2 (pre-release 2021-03-03)
36
+
37
+ - [#767](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/767): Fixes tests and more [@lpsBetty](https://github.com/lpsBetty)
38
+
39
+ ### 3.1.0.rc1 (pre-release 2021-02-17)
40
+
41
+ - [#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)
42
+ - [#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)
43
+ - [#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)
44
+ - [#755](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/755): Add allowed params to subscriptions [@dominikdarnel ](https://github.com/dominikdarnel)
45
+ - [#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).
46
+ - [#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)
47
+ - [#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)
48
+ - [#709](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/709): Remove unnecessary check on customer's currency - [@coorasse](https://github.com/coorasse)
49
+
50
+ ### 3.0.1 (TBD)
51
+
52
+ - Added Changelog file
53
+ - [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
54
+ - [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
55
+ - [#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).
56
+ - [#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).
57
+ - [#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).
58
+ - [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
59
+ Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
60
+ - [#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).
61
+ - [#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).
62
+ - [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
63
+ - [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).
64
+
65
+ ### 3.0.0 (2019-12-17)
66
+
67
+ ##### the main thing is:
68
+
69
+ - [#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/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # stripe-ruby-mock [![Build Status](https://travis-ci.org/rebelidealist/stripe-ruby-mock.png?branch=master)](https://travis-ci.org/rebelidealist/stripe-ruby-mock) [![Gitter chat](https://badges.gitter.im/rebelidealist/stripe-ruby-mock.png)](https://gitter.im/rebelidealist/stripe-ruby-mock)
1
+ # stripe-ruby-mock [![Tests](https://github.com/stripe-ruby-mock/stripe-ruby-mock/actions/workflows/rspec_tests.yml/badge.svg)](https://github.com/stripe-ruby-mock/stripe-ruby-mock/actions/workflows/rspec_tests.yml)
2
2
 
3
- * Homepage: https://github.com/rebelidealist/stripe-ruby-mock
4
- * Issues: https://github.com/rebelidealist/stripe-ruby-mock/issues
3
+ * Homepage: https://github.com/stripe-ruby-mock/stripe-ruby-mock
4
+ * Issues: https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues
5
5
  * **CHAT**: https://gitter.im/rebelidealist/stripe-ruby-mock
6
6
 
7
7
  # REQUEST: Looking for More Core Contributors
@@ -12,7 +12,13 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
12
12
 
13
13
  In your gemfile:
14
14
 
15
- gem 'stripe-ruby-mock', '~> 3.0.0', :require => 'stripe_mock'
15
+ gem 'stripe-ruby-mock', '~> 3.1.0', :require => 'stripe_mock'
16
+
17
+ ## !!! Important
18
+
19
+ We have [changelog](https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md). It's first attempt. Feel free to update it and suggest to a new format of it.
20
+
21
+ version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) - we support stripe > 5 and < 6 for now and try to follow the newest API version. But if you still use older versions please [read](https://github.com/stripe-ruby-mock/stripe-ruby-mock#specifications).
16
22
 
17
23
  ## Features
18
24
 
@@ -23,7 +29,7 @@ In your gemfile:
23
29
 
24
30
  ### Requirements
25
31
 
26
- * ruby >= 2.4.0
32
+ * ruby >= 2.6.0
27
33
  * stripe >= 5.0.0
28
34
 
29
35
  ### Specifications
@@ -400,6 +406,8 @@ Patches are welcome and greatly appreciated! If you're contributing to fix a pro
400
406
  be sure to write tests that illustrate the problem being fixed.
401
407
  This will help ensure that the problem remains fixed in future updates.
402
408
 
409
+ Note: You may need to `ulimit -n 4048` before running the test suite to get all tests to pass.
410
+
403
411
  ## Copyright
404
412
 
405
413
  Copyright (c) 2013 Gilbert
@@ -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
@@ -37,6 +37,9 @@ module StripeMock
37
37
  when :processing_error then build_card_error('An error occurred while processing the card', nil, code: 'processing_error', http_status: 402)
38
38
  when :card_error then build_card_error('The card number is not a valid credit card number.', 'number', code: 'invalid_number', http_status: 402)
39
39
  when :incorrect_zip then build_card_error('The zip code you supplied failed validation.', 'address_zip', code: 'incorrect_zip', http_status: 402)
40
+ when :insufficient_funds then build_card_error('The card has insufficient funds to complete the purchase.', nil, code: 'insufficient_funds', http_status: 402)
41
+ when :lost_card then build_card_error('The payment has been declined because the card is reported lost.', nil, code: 'lost_card', http_status: 402)
42
+ when :stolen_card then build_card_error('The payment has been declined because the card is reported stolen.', nil, code: 'stolen_card', http_status: 402)
40
43
  end
41
44
  end
42
45
 
@@ -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
 
@@ -4,7 +4,7 @@ module StripeMock
4
4
 
5
5
  fixture_file = File.join(@webhook_fixture_path, "#{type}.json")
6
6
 
7
- unless File.exists?(fixture_file)
7
+ unless File.exist?(fixture_file)
8
8
  unless Webhooks.event_list.include?(type)
9
9
  raise UnsupportedRequestError.new "Unsupported webhook event `#{type}` (Searched in #{@webhook_fixture_path})"
10
10
  end
@@ -37,53 +37,94 @@ module StripeMock
37
37
  module Webhooks
38
38
  def self.event_list
39
39
  @__list = [
40
- 'account.updated',
41
40
  'account.application.deauthorized',
42
41
  'account.external_account.created',
43
- 'account.external_account.updated',
44
42
  'account.external_account.deleted',
43
+ 'account.external_account.updated',
44
+ 'account.updated',
45
45
  'balance.available',
46
- 'charge.succeeded',
47
- 'charge.updated',
48
- 'charge.failed',
49
- 'charge.refunded',
50
- 'charge.dispute.created',
51
- 'charge.dispute.updated',
46
+ 'charge.captured',
52
47
  'charge.dispute.closed',
48
+ 'charge.dispute.created',
53
49
  'charge.dispute.funds_reinstated',
54
50
  'charge.dispute.funds_withdrawn',
51
+ 'charge.dispute.updated',
52
+ 'charge.failed',
53
+ 'charge.refund.updated',
54
+ 'charge.refunded',
55
+ 'charge.succeeded',
56
+ 'charge.updated',
57
+ 'checkout.session.completed',
58
+ 'checkout.session.completed.payment_mode',
59
+ 'checkout.session.completed.setup_mode',
60
+ 'coupon.created',
61
+ 'coupon.deleted',
62
+ 'customer.created',
63
+ 'customer.deleted',
64
+ 'customer.discount.created',
65
+ 'customer.discount.deleted',
66
+ 'customer.discount.updated',
55
67
  'customer.source.created',
56
68
  'customer.source.deleted',
57
69
  'customer.source.updated',
58
- 'customer.created',
59
- 'customer.updated',
60
- 'customer.deleted',
61
70
  'customer.subscription.created',
62
- 'customer.subscription.updated',
63
71
  'customer.subscription.deleted',
64
72
  'customer.subscription.trial_will_end',
65
- 'customer.discount.created',
66
- 'customer.discount.updated',
67
- 'customer.discount.deleted',
73
+ 'customer.subscription.updated',
74
+ 'customer.updated',
68
75
  'invoice.created',
69
- 'invoice.updated',
70
- 'invoice.payment_succeeded',
76
+ 'invoice.finalized',
77
+ 'invoice.paid',
78
+ 'invoice.payment_action_required',
71
79
  'invoice.payment_failed',
80
+ 'invoice.payment_succeeded',
81
+ 'invoice.upcoming',
82
+ 'invoice.updated',
72
83
  'invoiceitem.created',
73
- 'invoiceitem.updated',
74
84
  'invoiceitem.deleted',
85
+ 'invoiceitem.updated',
86
+ 'mandate.updated',
87
+ 'payment_intent.amount_capturable_updated',
88
+ 'payment_intent.canceled',
89
+ 'payment_intent.created',
90
+ 'payment_intent.payment_failed',
91
+ 'payment_intent.processing',
92
+ 'payment_intent.requires_action',
93
+ 'payment_intent.succeeded',
94
+ 'payment_link.created',
95
+ 'payment_link.updated',
96
+ 'payment_method.attached',
97
+ 'payment_method.detached',
98
+ 'payout.created',
99
+ 'payout.paid',
100
+ 'payout.updated',
75
101
  'plan.created',
76
- 'plan.updated',
77
102
  'plan.deleted',
103
+ 'plan.updated',
104
+ 'price.created',
105
+ 'price.deleted',
106
+ 'price.updated',
78
107
  'product.created',
79
- 'product.updated',
80
108
  'product.deleted',
81
- 'coupon.created',
82
- 'coupon.deleted',
109
+ 'product.updated',
110
+ 'quote.accepted',
111
+ 'quote.canceled',
112
+ 'quote.created',
113
+ 'quote.finalized',
114
+ 'setup_intent.canceled',
115
+ 'setup_intent.created',
116
+ 'setup_intent.setup_failed',
117
+ 'setup_intent.succeeded',
118
+ 'subscription_schedule.canceled',
119
+ 'subscription_schedule.created',
120
+ 'subscription_schedule.released',
121
+ 'subscription_schedule.updated',
122
+ 'tax_rate.created',
123
+ 'tax_rate.updated',
83
124
  'transfer.created',
125
+ 'transfer.failed',
84
126
  'transfer.paid',
85
- 'transfer.updated',
86
- 'transfer.failed'
127
+ 'transfer.updated'
87
128
  ]
88
129
  end
89
130
  end
@@ -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
@@ -1,19 +1,17 @@
1
1
  module StripeMock
2
2
  module Data
3
3
  class List
4
- attr_reader :data, :limit, :offset, :starting_after, :ending_before
4
+ attr_reader :data, :limit, :offset, :starting_after, :ending_before, :active
5
5
 
6
6
  def initialize(data, options = {})
7
7
  @data = Array(data.clone)
8
8
  @limit = [[options[:limit] || 10, 100].min, 1].max # restrict @limit to 1..100
9
9
  @starting_after = options[:starting_after]
10
10
  @ending_before = options[:ending_before]
11
- if @data.first.is_a?(Hash) && @data.first[:created]
12
- @data.sort_by! { |x| x[:created] }
13
- @data.reverse!
14
- elsif @data.first.respond_to?(:created)
15
- @data.sort_by { |x| x.created }
16
- @data.reverse!
11
+ @active = options[:active]
12
+ if contains_stripe_objects?
13
+ prune_deleted_data
14
+ sort_data
17
15
  end
18
16
  end
19
17
 
@@ -53,14 +51,21 @@ module StripeMock
53
51
  (index || raise("No such object id: #{starting_after}")) + 1
54
52
  when ending_before
55
53
  index = data.index { |datum| datum[:id] == ending_before }
56
- (index || raise("No such object id: #{ending_before}")) - 1
54
+ (index || raise("No such object id: #{ending_before}")) - 1
57
55
  else
58
56
  0
59
57
  end
60
58
  end
61
59
 
62
60
  def data_page
63
- data[offset, limit]
61
+ filtered_data[offset, limit]
62
+ end
63
+
64
+ def filtered_data
65
+ filtered_data = data
66
+ filtered_data = filtered_data.select { |d| d[:active] == active } unless active.nil?
67
+
68
+ filtered_data
64
69
  end
65
70
 
66
71
  def object_types
@@ -68,6 +73,34 @@ module StripeMock
68
73
  "#{first_object.class.to_s.split('::')[-1].downcase}s"
69
74
  end
70
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
71
104
  end
72
105
  end
73
106
  end