stripe-ruby-mock 3.1.0.rc3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec_tests.yml +38 -0
  3. data/.rspec +2 -1
  4. data/CHANGELOG.md +36 -0
  5. data/Gemfile +0 -5
  6. data/README.md +6 -4
  7. data/lib/stripe_mock/api/client.rb +1 -1
  8. data/lib/stripe_mock/api/webhooks.rb +65 -26
  9. data/lib/stripe_mock/data.rb +80 -11
  10. data/lib/stripe_mock/instance.rb +7 -3
  11. data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
  12. data/lib/stripe_mock/request_handlers/charges.rb +25 -1
  13. data/lib/stripe_mock/request_handlers/checkout_session.rb +158 -1
  14. data/lib/stripe_mock/request_handlers/customers.rb +12 -1
  15. data/lib/stripe_mock/request_handlers/events.rb +30 -3
  16. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
  17. data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
  18. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +28 -9
  19. data/lib/stripe_mock/request_handlers/invoices.rb +16 -2
  20. data/lib/stripe_mock/request_handlers/payment_intents.rb +23 -3
  21. data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
  22. data/lib/stripe_mock/request_handlers/prices.rb +31 -4
  23. data/lib/stripe_mock/request_handlers/products.rb +14 -5
  24. data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
  25. data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
  26. data/lib/stripe_mock/request_handlers/setup_intents.rb +16 -9
  27. data/lib/stripe_mock/request_handlers/subscriptions.rb +103 -5
  28. data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
  29. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -4
  30. data/lib/stripe_mock/test_strategies/base.rb +51 -24
  31. data/lib/stripe_mock/version.rb +1 -1
  32. data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
  33. data/lib/stripe_mock/webhook_fixtures/balance.available.json +26 -20
  34. data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
  35. data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
  36. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +49 -120
  37. data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
  38. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
  39. data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
  40. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
  41. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
  42. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
  43. data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -46
  44. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
  45. data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
  46. data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
  47. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
  48. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
  49. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
  50. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -47
  51. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
  52. data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
  53. data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
  54. data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
  55. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
  56. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
  57. data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
  58. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
  59. data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
  60. data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
  61. data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
  62. data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
  63. data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
  64. data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
  65. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +118 -79
  66. data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
  67. data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
  68. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +85 -53
  69. data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
  70. data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
  71. data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
  72. data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
  73. data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
  74. data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
  75. data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
  76. data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
  77. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
  78. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
  79. data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
  80. data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
  81. data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
  82. data/lib/stripe_mock/webhook_fixtures/product.created.json +19 -13
  83. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
  84. data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
  85. data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
  86. data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
  87. data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
  88. data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
  89. data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
  90. data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
  91. data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
  92. data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
  93. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
  94. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
  95. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
  96. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
  97. data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
  98. data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
  99. data/lib/stripe_mock.rb +4 -1
  100. data/spec/instance_spec.rb +3 -1
  101. data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
  102. data/spec/readme_spec.rb +1 -1
  103. data/spec/shared_stripe_examples/account_examples.rb +9 -1
  104. data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
  105. data/spec/shared_stripe_examples/charge_examples.rb +97 -0
  106. data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
  107. data/spec/shared_stripe_examples/customer_examples.rb +56 -0
  108. data/spec/shared_stripe_examples/invoice_examples.rb +107 -1
  109. data/spec/shared_stripe_examples/payment_intent_examples.rb +136 -0
  110. data/spec/shared_stripe_examples/payment_method_examples.rb +32 -27
  111. data/spec/shared_stripe_examples/price_examples.rb +111 -2
  112. data/spec/shared_stripe_examples/product_examples.rb +68 -0
  113. data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
  114. data/spec/shared_stripe_examples/refund_examples.rb +13 -0
  115. data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
  116. data/spec/shared_stripe_examples/subscription_examples.rb +276 -6
  117. data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
  118. data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
  119. data/spec/spec_helper.rb +1 -1
  120. data/spec/support/stripe_examples.rb +3 -1
  121. data/stripe-ruby-mock.gemspec +3 -4
  122. metadata +59 -29
  123. data/.travis.yml +0 -25
  124. data/lib/stripe_mock/request_handlers/checkout.rb +0 -15
  125. data/spec/shared_stripe_examples/checkout_examples.rb +0 -47
@@ -0,0 +1,111 @@
1
+ {
2
+ "id": "evt_000000000000000000000000",
3
+ "object": "event",
4
+ "api_version": "2020-08-27",
5
+ "created": 1648320106,
6
+ "data": {
7
+ "object": {
8
+ "id": "sub_sched_000000000000000000000000",
9
+ "object": "subscription_schedule",
10
+ "canceled_at": null,
11
+ "completed_at": null,
12
+ "created": 1648320105,
13
+ "current_phase": null,
14
+ "customer": "cus_00000000000000",
15
+ "default_settings": {
16
+ "application_fee_percent": null,
17
+ "automatic_tax": {
18
+ "enabled": false
19
+ },
20
+ "billing_cycle_anchor": "automatic",
21
+ "billing_thresholds": null,
22
+ "collection_method": "charge_automatically",
23
+ "default_payment_method": null,
24
+ "default_source": null,
25
+ "invoice_settings": null,
26
+ "transfer_data": null
27
+ },
28
+ "end_behavior": "release",
29
+ "livemode": false,
30
+ "metadata": {
31
+ },
32
+ "phases": [
33
+ {
34
+ "add_invoice_items": [
35
+
36
+ ],
37
+ "application_fee_percent": null,
38
+ "billing_cycle_anchor": null,
39
+ "billing_thresholds": null,
40
+ "collection_method": null,
41
+ "coupon": null,
42
+ "default_payment_method": null,
43
+ "default_tax_rates": [
44
+
45
+ ],
46
+ "end_date": 1650998505,
47
+ "invoice_settings": null,
48
+ "items": [
49
+ {
50
+ "billing_thresholds": null,
51
+ "plan": "price_000000000000000000000000",
52
+ "price": "price_000000000000000000000000",
53
+ "quantity": 1,
54
+ "tax_rates": [
55
+
56
+ ]
57
+ }
58
+ ],
59
+ "proration_behavior": "create_prorations",
60
+ "start_date": 1648320105,
61
+ "transfer_data": null,
62
+ "trial_end": null
63
+ },
64
+ {
65
+ "add_invoice_items": [
66
+
67
+ ],
68
+ "application_fee_percent": null,
69
+ "billing_cycle_anchor": null,
70
+ "billing_thresholds": null,
71
+ "collection_method": null,
72
+ "coupon": null,
73
+ "default_payment_method": null,
74
+ "default_tax_rates": [
75
+
76
+ ],
77
+ "end_date": 1653590505,
78
+ "invoice_settings": null,
79
+ "items": [
80
+ {
81
+ "billing_thresholds": null,
82
+ "plan": "price_000000000000000000000000",
83
+ "price": "price_000000000000000000000000",
84
+ "quantity": 2,
85
+ "tax_rates": [
86
+
87
+ ]
88
+ }
89
+ ],
90
+ "proration_behavior": "create_prorations",
91
+ "start_date": 1650998505,
92
+ "transfer_data": null,
93
+ "trial_end": null
94
+ }
95
+ ],
96
+ "released_at": 1648320106,
97
+ "released_subscription": "sub_000000000000000000000000",
98
+ "renewal_interval": null,
99
+ "status": "released",
100
+ "subscription": null,
101
+ "test_clock": null
102
+ }
103
+ },
104
+ "livemode": false,
105
+ "pending_webhooks": 2,
106
+ "request": {
107
+ "id": "req_00000000000000",
108
+ "idempotency_key": "fe5a111d-ed6f-4cb5-a33c-05b364afc565"
109
+ },
110
+ "type": "subscription_schedule.released"
111
+ }
@@ -0,0 +1,125 @@
1
+ {
2
+ "id": "evt_000000000000000000000000",
3
+ "object": "event",
4
+ "api_version": "2020-08-27",
5
+ "created": 1648320111,
6
+ "data": {
7
+ "object": {
8
+ "id": "sub_sched_000000000000000000000000",
9
+ "object": "subscription_schedule",
10
+ "canceled_at": null,
11
+ "completed_at": null,
12
+ "created": 1648320110,
13
+ "current_phase": {
14
+ "end_date": 1650998510,
15
+ "start_date": 1648320110
16
+ },
17
+ "customer": "cus_00000000000000",
18
+ "default_settings": {
19
+ "application_fee_percent": null,
20
+ "automatic_tax": {
21
+ "enabled": false
22
+ },
23
+ "billing_cycle_anchor": "automatic",
24
+ "billing_thresholds": null,
25
+ "collection_method": "charge_automatically",
26
+ "default_payment_method": null,
27
+ "default_source": null,
28
+ "invoice_settings": {
29
+ "days_until_due": null
30
+ },
31
+ "transfer_data": null
32
+ },
33
+ "end_behavior": "release",
34
+ "livemode": false,
35
+ "metadata": {
36
+ "foo": "bar"
37
+ },
38
+ "phases": [
39
+ {
40
+ "add_invoice_items": [
41
+
42
+ ],
43
+ "application_fee_percent": null,
44
+ "billing_cycle_anchor": null,
45
+ "billing_thresholds": null,
46
+ "collection_method": null,
47
+ "coupon": null,
48
+ "default_payment_method": null,
49
+ "default_tax_rates": [
50
+
51
+ ],
52
+ "end_date": 1650998510,
53
+ "invoice_settings": null,
54
+ "items": [
55
+ {
56
+ "billing_thresholds": null,
57
+ "plan": "price_000000000000000000000000",
58
+ "price": "price_000000000000000000000000",
59
+ "quantity": 1,
60
+ "tax_rates": [
61
+
62
+ ]
63
+ }
64
+ ],
65
+ "proration_behavior": "create_prorations",
66
+ "start_date": 1648320110,
67
+ "transfer_data": null,
68
+ "trial_end": null
69
+ },
70
+ {
71
+ "add_invoice_items": [
72
+
73
+ ],
74
+ "application_fee_percent": null,
75
+ "billing_cycle_anchor": null,
76
+ "billing_thresholds": null,
77
+ "collection_method": null,
78
+ "coupon": null,
79
+ "default_payment_method": null,
80
+ "default_tax_rates": [
81
+
82
+ ],
83
+ "end_date": 1653590510,
84
+ "invoice_settings": null,
85
+ "items": [
86
+ {
87
+ "billing_thresholds": null,
88
+ "plan": "price_000000000000000000000000",
89
+ "price": "price_000000000000000000000000",
90
+ "quantity": 2,
91
+ "tax_rates": [
92
+
93
+ ]
94
+ }
95
+ ],
96
+ "proration_behavior": "create_prorations",
97
+ "start_date": 1650998510,
98
+ "transfer_data": null,
99
+ "trial_end": null
100
+ }
101
+ ],
102
+ "released_at": null,
103
+ "released_subscription": null,
104
+ "renewal_interval": null,
105
+ "status": "active",
106
+ "subscription": "sub_000000000000000000000000",
107
+ "test_clock": null
108
+ },
109
+ "previous_attributes": {
110
+ "default_settings": {
111
+ "invoice_settings": null
112
+ },
113
+ "metadata": {
114
+ "foo": null
115
+ }
116
+ }
117
+ },
118
+ "livemode": false,
119
+ "pending_webhooks": 2,
120
+ "request": {
121
+ "id": "req_00000000000000",
122
+ "idempotency_key": "209a08f0-224b-410a-b659-a0a39a7c59b6"
123
+ },
124
+ "type": "subscription_schedule.updated"
125
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "id": "evt_000000000000000000000000",
3
+ "object": "event",
4
+ "api_version": "2020-08-27",
5
+ "created": 1700752531,
6
+ "data": {
7
+ "object": {
8
+ "id": "txr_00000000000000",
9
+ "object": "tax_rate",
10
+ "active": true,
11
+ "country": "DE",
12
+ "created": 1700750289,
13
+ "description": "VAT Germany",
14
+ "display_name": "VAT",
15
+ "effective_percentage": null,
16
+ "inclusive": false,
17
+ "jurisdiction": "DE",
18
+ "livemode": false,
19
+ "metadata": {},
20
+ "percentage": 16.0,
21
+ "state": null,
22
+ "tax_type": "vat"
23
+ }
24
+ },
25
+ "livemode": false,
26
+ "pending_webhooks": 2,
27
+ "request": {
28
+ "id": "req_00000000000000",
29
+ "idempotency_key": "cd3e4fc0-9d4c-42fd-a818-1b9789537ce9"
30
+ },
31
+ "type": "tax_rate.created"
32
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "id": "evt_000000000000000000000000",
3
+ "object": "event",
4
+ "api_version": "2020-08-27",
5
+ "created": 1700752371,
6
+ "data": {
7
+ "object": {
8
+ "id": "txr_00000000000000",
9
+ "object": "tax_rate",
10
+ "active": true,
11
+ "country": "DE",
12
+ "created": 1700750289,
13
+ "description": "VAT Germany",
14
+ "display_name": "VAT",
15
+ "effective_percentage": null,
16
+ "inclusive": false,
17
+ "jurisdiction": "DE",
18
+ "livemode": false,
19
+ "metadata": {},
20
+ "percentage": 16.0,
21
+ "state": null,
22
+ "tax_type": "vat"
23
+ },
24
+ "previous_attributes": {
25
+ "metadata": {
26
+ "foo": null
27
+ }
28
+ }
29
+ },
30
+ "livemode": false,
31
+ "pending_webhooks": 2,
32
+ "request": {
33
+ "id": "req_00000000000000",
34
+ "idempotency_key": "7eb234a6-64bc-4320-bc7f-780c546ab026"
35
+ },
36
+ "type": "tax_rate.updated"
37
+ }
data/lib/stripe_mock.rb CHANGED
@@ -42,6 +42,7 @@ require 'stripe_mock/request_handlers/helpers/external_account_helpers.rb'
42
42
  require 'stripe_mock/request_handlers/helpers/card_helpers.rb'
43
43
  require 'stripe_mock/request_handlers/helpers/charge_helpers.rb'
44
44
  require 'stripe_mock/request_handlers/helpers/coupon_helpers.rb'
45
+ require 'stripe_mock/request_handlers/helpers/search_helpers.rb'
45
46
  require 'stripe_mock/request_handlers/helpers/subscription_helpers.rb'
46
47
  require 'stripe_mock/request_handlers/helpers/token_helpers.rb'
47
48
 
@@ -65,6 +66,7 @@ require 'stripe_mock/request_handlers/invoice_items.rb'
65
66
  require 'stripe_mock/request_handlers/orders.rb'
66
67
  require 'stripe_mock/request_handlers/plans.rb'
67
68
  require 'stripe_mock/request_handlers/prices.rb'
69
+ require 'stripe_mock/request_handlers/promotion_codes.rb'
68
70
  require 'stripe_mock/request_handlers/recipients.rb'
69
71
  require 'stripe_mock/request_handlers/refunds.rb'
70
72
  require 'stripe_mock/request_handlers/transfers.rb'
@@ -79,7 +81,6 @@ require 'stripe_mock/request_handlers/country_spec.rb'
79
81
  require 'stripe_mock/request_handlers/ephemeral_key.rb'
80
82
  require 'stripe_mock/request_handlers/products.rb'
81
83
  require 'stripe_mock/request_handlers/tax_rates.rb'
82
- require 'stripe_mock/request_handlers/checkout.rb'
83
84
  require 'stripe_mock/request_handlers/checkout_session.rb'
84
85
  require 'stripe_mock/instance'
85
86
 
@@ -90,12 +91,14 @@ require 'stripe_mock/test_strategies/live.rb'
90
91
  module StripeMock
91
92
 
92
93
  @default_currency = 'usd'
94
+ @checkout_base = "https://checkout.stripe.com/pay/"
93
95
  lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
94
96
  @webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
95
97
  @webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
96
98
 
97
99
  class << self
98
100
  attr_accessor :default_currency
101
+ attr_accessor :checkout_base
99
102
  attr_accessor :webhook_fixture_path
100
103
  end
101
104
  end
@@ -6,7 +6,9 @@ describe StripeMock::Instance do
6
6
  let(:stripe_helper) { StripeMock.create_test_helper }
7
7
 
8
8
  it_behaves_like_stripe do
9
- def test_data_source(type); StripeMock.instance.send(type); end
9
+ def test_data_source(type)
10
+ StripeMock.instance.send(type)
11
+ end
10
12
  end
11
13
 
12
14
  before { StripeMock.start }
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples "Completing Checkout Sessions" do
4
+ let(:test_helper) { StripeMock.create_test_helper }
5
+ before { StripeMock.start }
6
+ after { StripeMock.stop }
7
+
8
+ it "can complete payment checkout sessions" do
9
+ session = test_helper.create_checkout_session(mode: "payment")
10
+ payment_method = Stripe::PaymentMethod.create(type: "card")
11
+
12
+ payment_intent = test_helper.complete_checkout_session(session, payment_method)
13
+
14
+ expect(payment_intent.id).to eq(session.payment_intent)
15
+ expect(payment_intent.payment_method).to eq(payment_method.id)
16
+ expect(payment_intent.status).to eq("succeeded")
17
+ end
18
+
19
+ it "can complete setup checkout sessions" do
20
+ session = test_helper.create_checkout_session(mode: "setup")
21
+ payment_method = Stripe::PaymentMethod.create(type: "card")
22
+
23
+ setup_intent = test_helper.complete_checkout_session(session, payment_method)
24
+
25
+ expect(setup_intent.id).to eq(session.setup_intent)
26
+ expect(setup_intent.payment_method).to eq(payment_method.id)
27
+ end
28
+
29
+ it "can complete subscription checkout sessions" do
30
+ session = test_helper.create_checkout_session(mode: "subscription")
31
+ payment_method = Stripe::PaymentMethod.create(type: "card")
32
+
33
+ subscription = test_helper.complete_checkout_session(session, payment_method)
34
+
35
+ expect(subscription.default_payment_method).to eq(payment_method.id)
36
+ end
37
+ end
data/spec/readme_spec.rb CHANGED
@@ -47,7 +47,7 @@ describe 'README examples' do
47
47
 
48
48
  customer_object = event.data.object
49
49
  expect(customer_object.id).to_not be_nil
50
- expect(customer_object.default_card).to_not be_nil
50
+ expect(customer_object.default_source).to_not be_nil
51
51
  # etc.
52
52
  end
53
53
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  shared_examples 'Account API' do
4
- describe 'retrive accounts' do
4
+ describe 'retrieve accounts' do
5
5
  it 'retrieves a stripe account', live: true do
6
6
  account = Stripe::Account.retrieve
7
7
 
@@ -86,6 +86,14 @@ shared_examples 'Account API' do
86
86
  end
87
87
  end
88
88
 
89
+ describe 'delete account' do
90
+ it 'deletes a stripe account' do
91
+ account = Stripe::Account.create(email: 'test@test.com')
92
+ account = account.delete
93
+ expect(account.deleted).to eq(true)
94
+ end
95
+ end
96
+
89
97
  it 'deauthorizes the stripe account', live: false do
90
98
  account = Stripe::Account.retrieve
91
99
  result = account.deauthorize('CLIENT_ID')
@@ -28,20 +28,19 @@ shared_examples 'Bank Account Token Mocking' do
28
28
  expect(bank_token).to match /^test_btok/
29
29
  end
30
30
 
31
- it "assigns the generated bank account to a new recipient" do
31
+ it "assigns the generated bank account to a new customer" do
32
32
  bank_token = StripeMock.generate_bank_token(
33
33
  :bank_name => "Bank Token Mocking",
34
34
  :last4 => "7777"
35
35
  )
36
36
 
37
- recipient = Stripe::Recipient.create({
37
+ customer = Stripe::Customer.create({
38
38
  name: "Fred Flinstone",
39
- type: "individual",
40
39
  email: 'blah@domain.co',
41
- bank_account: bank_token
40
+ source: bank_token
42
41
  })
43
- expect(recipient.active_account.last4).to eq("7777")
44
- expect(recipient.active_account.bank_name).to eq("Bank Token Mocking")
42
+ expect(customer.sources.first.last4).to eq("7777")
43
+ expect(customer.sources.first.bank_name).to eq("Bank Token Mocking")
45
44
  end
46
45
 
47
46
  it "retrieves a created token" do
@@ -55,5 +54,4 @@ shared_examples 'Bank Account Token Mocking' do
55
54
  expect(token.bank_account.last4).to eq("3939")
56
55
  expect(token.bank_account.bank_name).to eq("Cha-ching Banking")
57
56
  end
58
-
59
57
  end
@@ -494,4 +494,101 @@ shared_examples 'Charge API' do
494
494
  end
495
495
  end
496
496
 
497
+ context "search" do
498
+ # the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
499
+ it "searches charges for exact matches", :aggregate_failures do
500
+ response = Stripe::Charge.search({query: 'amount:100'}, stripe_version: '2020-08-27')
501
+ expect(response.data.size).to eq(0)
502
+
503
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
504
+ one = Stripe::Charge.create(
505
+ customer: customer.id,
506
+ amount: 100,
507
+ currency: "usd",
508
+ payment_method_details: {
509
+ card: StripeMock::Data.mock_charge[:payment_method_details][:card].merge(
510
+ brand: "mastercard",
511
+ exp_month: 1,
512
+ exp_year: 2111,
513
+ fingerprint: "un",
514
+ last4: "1111",
515
+ ),
516
+ },
517
+ status: "succeeded",
518
+ metadata: {key: 'uno'},
519
+ )
520
+ two = Stripe::Charge.create(
521
+ customer: customer.id,
522
+ amount: 200,
523
+ currency: "gbp",
524
+ payment_method_details: {
525
+ card: StripeMock::Data.mock_charge[:payment_method_details][:card].merge(
526
+ brand: "visa",
527
+ exp_month: 2,
528
+ exp_year: 2222,
529
+ fingerprint: "deux",
530
+ last4: "2222",
531
+ ),
532
+ },
533
+ status: "pending",
534
+ metadata: {key: 'dos'},
535
+ )
536
+
537
+ response = Stripe::Charge.search({query: 'amount:100'}, stripe_version: '2020-08-27')
538
+ expect(response.data.map(&:id)).to match_array([one.id])
539
+
540
+ response = Stripe::Charge.search({query: 'currency:"gbp"'}, stripe_version: '2020-08-27')
541
+ expect(response.data.map(&:id)).to match_array([two.id])
542
+
543
+ response = Stripe::Charge.search({query: %(customer:"#{customer.id}")}, stripe_version: '2020-08-27')
544
+ expect(response.data.map(&:id)).to match_array([one.id, two.id])
545
+
546
+ response = Stripe::Charge.search({query: 'payment_method_details.card.brand:mastercard'}, stripe_version: '2020-08-27')
547
+ expect(response.data.map(&:id)).to match_array([one.id])
548
+
549
+ response = Stripe::Charge.search({query: 'payment_method_details.card.exp_month:2'}, stripe_version: '2020-08-27')
550
+ expect(response.data.map(&:id)).to match_array([two.id])
551
+
552
+ response = Stripe::Charge.search({query: 'payment_method_details.card.exp_year:2111'}, stripe_version: '2020-08-27')
553
+ expect(response.data.map(&:id)).to match_array([one.id])
554
+
555
+ response = Stripe::Charge.search({query: 'payment_method_details.card.fingerprint:un'}, stripe_version: '2020-08-27')
556
+ expect(response.data.map(&:id)).to match_array([one.id])
557
+
558
+ response = Stripe::Charge.search({query: 'payment_method_details.card.last4:2222'}, stripe_version: '2020-08-27')
559
+ expect(response.data.map(&:id)).to match_array([two.id])
560
+
561
+ response = Stripe::Charge.search({query: 'status:"succeeded"'}, stripe_version: '2020-08-27')
562
+ expect(response.data.map(&:id)).to match_array([one.id])
563
+
564
+ response = Stripe::Charge.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
565
+ expect(response.data.map(&:id)).to match_array([one.id])
566
+ end
567
+
568
+ it "respects limit", :aggregate_failures do
569
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
570
+ 11.times do
571
+ Stripe::Charge.create(customer: customer.id, amount: 100, currency: "usd")
572
+ end
573
+
574
+ response = Stripe::Charge.search({query: %(customer:"#{customer.id}")}, stripe_version: '2020-08-27')
575
+ expect(response.data.size).to eq(10)
576
+ response = Stripe::Charge.search({query: %(customer:"#{customer.id}"), limit: 1}, stripe_version: '2020-08-27')
577
+ expect(response.data.size).to eq(1)
578
+ end
579
+
580
+ it "reports search errors", :aggregate_failures do
581
+ expect {
582
+ Stripe::Charge.search({limit: 1}, stripe_version: '2020-08-27')
583
+ }.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
584
+
585
+ expect {
586
+ Stripe::Charge.search({query: 'asdf'}, stripe_version: '2020-08-27')
587
+ }.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
588
+
589
+ expect {
590
+ Stripe::Charge.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
591
+ }.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `charges`./)
592
+ end
593
+ end
497
594
  end
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ shared_examples "Checkout Session API" do
4
+ it "creates PaymentIntent with payment mode" do
5
+ line_items = [{
6
+ name: "T-shirt",
7
+ quantity: 2,
8
+ amount: 500,
9
+ currency: "usd",
10
+ }]
11
+ session = Stripe::Checkout::Session.create(
12
+ payment_method_types: ["card"],
13
+ line_items: line_items,
14
+ cancel_url: "https://example.com/cancel",
15
+ success_url: "https://example.com/success"
16
+ )
17
+
18
+ expect(session.payment_intent).to_not be_empty
19
+ payment_intent = Stripe::PaymentIntent.retrieve(session.payment_intent)
20
+ expect(payment_intent.amount).to eq(1000)
21
+ expect(payment_intent.currency).to eq("usd")
22
+ expect(payment_intent.customer).to eq(session.customer)
23
+ end
24
+
25
+ context "when creating a payment" do
26
+ it "requires line_items" do
27
+ expect do
28
+ session = Stripe::Checkout::Session.create(
29
+ customer: "customer_id",
30
+ success_url: "localhost/nada",
31
+ cancel_url: "localhost/nada",
32
+ payment_method_types: ["card"],
33
+ )
34
+ end.to raise_error(Stripe::InvalidRequestError, /line_items/i)
35
+
36
+ end
37
+ end
38
+
39
+ it "creates SetupIntent with setup mode" do
40
+ session = Stripe::Checkout::Session.create(
41
+ mode: "setup",
42
+ payment_method_types: ["card"],
43
+ cancel_url: "https://example.com/cancel",
44
+ success_url: "https://example.com/success"
45
+ )
46
+
47
+ expect(session.setup_intent).to_not be_empty
48
+ setup_intent = Stripe::SetupIntent.retrieve(session.setup_intent)
49
+ expect(setup_intent.payment_method_types).to eq(["card"])
50
+ end
51
+
52
+ context "when creating a subscription" do
53
+ it "requires line_items" do
54
+ expect do
55
+ session = Stripe::Checkout::Session.create(
56
+ customer: "customer_id",
57
+ success_url: "localhost/nada",
58
+ cancel_url: "localhost/nada",
59
+ payment_method_types: ["card"],
60
+ mode: "subscription",
61
+ )
62
+ end.to raise_error(Stripe::InvalidRequestError, /line_items/i)
63
+
64
+ end
65
+ end
66
+
67
+ context "retrieve a checkout session" do
68
+ let(:checkout_session1) { stripe_helper.create_checkout_session }
69
+
70
+ it "can be retrieved by id" do
71
+ checkout_session1
72
+
73
+ checkout_session = Stripe::Checkout::Session.retrieve(checkout_session1.id)
74
+
75
+ expect(checkout_session.id).to eq(checkout_session1.id)
76
+ end
77
+
78
+ it "cannot retrieve a checkout session that doesn't exist" do
79
+ expect { Stripe::Checkout::Session.retrieve("nope") }.to raise_error { |e|
80
+ expect(e).to be_a Stripe::InvalidRequestError
81
+ expect(e.param).to eq("checkout_session")
82
+ expect(e.http_status).to eq(404)
83
+ }
84
+ end
85
+
86
+ it "can expand setup_intent" do
87
+ initial_session = Stripe::Checkout::Session.create(
88
+ mode: "setup",
89
+ cancel_url: "https://example.com",
90
+ success_url: "https://example.com",
91
+ payment_method_types: ["card"]
92
+ )
93
+
94
+ checkout_session = Stripe::Checkout::Session.retrieve(id: initial_session.id, expand: ["setup_intent"])
95
+
96
+ expect(checkout_session.setup_intent).to be_a_kind_of(Stripe::SetupIntent)
97
+ end
98
+ end
99
+ end