stripe-ruby-mock 3.0.1 → 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 +62 -15
  5. data/Gemfile +1 -0
  6. data/README.md +5 -3
  7. data/lib/stripe_mock/api/client.rb +1 -1
  8. data/lib/stripe_mock/api/instance.rb +1 -1
  9. data/lib/stripe_mock/api/webhooks.rb +66 -25
  10. data/lib/stripe_mock/client.rb +2 -1
  11. data/lib/stripe_mock/data/list.rb +31 -6
  12. data/lib/stripe_mock/data.rb +201 -30
  13. data/lib/stripe_mock/instance.rb +12 -3
  14. data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
  15. data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
  16. data/lib/stripe_mock/request_handlers/charges.rb +11 -4
  17. data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
  18. data/lib/stripe_mock/request_handlers/customers.rb +22 -13
  19. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
  20. data/lib/stripe_mock/request_handlers/events.rb +30 -3
  21. data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
  22. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
  23. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
  24. data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
  25. data/lib/stripe_mock/request_handlers/payment_intents.rb +13 -2
  26. data/lib/stripe_mock/request_handlers/payment_methods.rb +11 -4
  27. data/lib/stripe_mock/request_handlers/prices.rb +62 -0
  28. data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
  29. data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
  30. data/lib/stripe_mock/request_handlers/setup_intents.rb +16 -9
  31. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  32. data/lib/stripe_mock/request_handlers/subscriptions.rb +120 -21
  33. data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
  34. data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
  35. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +33 -4
  36. data/lib/stripe_mock/server.rb +2 -2
  37. data/lib/stripe_mock/test_strategies/base.rb +62 -10
  38. data/lib/stripe_mock/version.rb +1 -1
  39. data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
  40. data/lib/stripe_mock/webhook_fixtures/balance.available.json +27 -15
  41. data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
  42. data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
  43. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +49 -120
  44. data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
  45. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
  46. data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
  47. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
  48. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
  49. data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
  50. data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -46
  51. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
  52. data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
  53. data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
  54. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
  55. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
  56. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
  57. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -47
  58. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
  59. data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
  60. data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
  61. data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
  62. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
  63. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
  64. data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
  65. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
  66. data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
  67. data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
  68. data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
  69. data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
  70. data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
  71. data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
  72. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +225 -0
  73. data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
  74. data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
  75. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +196 -0
  76. data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
  77. data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
  78. data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
  79. data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
  80. data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
  81. data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
  82. data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
  83. data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
  84. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
  85. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
  86. data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
  87. data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
  88. data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
  89. data/lib/stripe_mock/webhook_fixtures/product.created.json +19 -13
  90. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
  91. data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
  92. data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
  93. data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
  94. data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
  95. data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
  96. data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
  97. data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
  98. data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
  99. data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
  100. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
  101. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
  102. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
  103. data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
  104. data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
  105. data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
  106. data/lib/stripe_mock.rb +7 -1
  107. data/spec/instance_spec.rb +7 -7
  108. data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
  109. data/spec/list_spec.rb +23 -0
  110. data/spec/readme_spec.rb +1 -1
  111. data/spec/server_spec.rb +4 -2
  112. data/spec/shared_stripe_examples/account_examples.rb +9 -1
  113. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  114. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  115. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  116. data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
  117. data/spec/shared_stripe_examples/customer_examples.rb +11 -13
  118. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  119. data/spec/shared_stripe_examples/invoice_examples.rb +29 -8
  120. data/spec/shared_stripe_examples/payment_intent_examples.rb +74 -0
  121. data/spec/shared_stripe_examples/payment_method_examples.rb +336 -67
  122. data/spec/shared_stripe_examples/price_examples.rb +223 -0
  123. data/spec/shared_stripe_examples/product_examples.rb +1 -9
  124. data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
  125. data/spec/shared_stripe_examples/refund_examples.rb +13 -0
  126. data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
  127. data/spec/shared_stripe_examples/subscription_examples.rb +327 -9
  128. data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
  129. data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
  130. data/spec/spec_helper.rb +4 -0
  131. data/spec/stripe_mock_spec.rb +2 -2
  132. data/spec/support/stripe_examples.rb +8 -2
  133. data/stripe-ruby-mock.gemspec +7 -2
  134. metadata +72 -15
  135. data/.travis.yml +0 -28
  136. data/lib/stripe_mock/request_handlers/checkout.rb +0 -15
  137. data/spec/shared_stripe_examples/checkout_examples.rb +0 -19
@@ -0,0 +1,114 @@
1
+ {
2
+ "id": "evt_000000000000000000000000",
3
+ "object": "event",
4
+ "api_version": "2020-08-27",
5
+ "created": 1648320110,
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": null,
29
+ "transfer_data": null
30
+ },
31
+ "end_behavior": "release",
32
+ "livemode": false,
33
+ "metadata": {
34
+ },
35
+ "phases": [
36
+ {
37
+ "add_invoice_items": [
38
+
39
+ ],
40
+ "application_fee_percent": null,
41
+ "billing_cycle_anchor": null,
42
+ "billing_thresholds": null,
43
+ "collection_method": null,
44
+ "coupon": null,
45
+ "default_payment_method": null,
46
+ "default_tax_rates": [
47
+
48
+ ],
49
+ "end_date": 1650998510,
50
+ "invoice_settings": null,
51
+ "items": [
52
+ {
53
+ "billing_thresholds": null,
54
+ "plan": "price_000000000000000000000000",
55
+ "price": "price_000000000000000000000000",
56
+ "quantity": 1,
57
+ "tax_rates": [
58
+
59
+ ]
60
+ }
61
+ ],
62
+ "proration_behavior": "create_prorations",
63
+ "start_date": 1648320110,
64
+ "transfer_data": null,
65
+ "trial_end": null
66
+ },
67
+ {
68
+ "add_invoice_items": [
69
+
70
+ ],
71
+ "application_fee_percent": null,
72
+ "billing_cycle_anchor": null,
73
+ "billing_thresholds": null,
74
+ "collection_method": null,
75
+ "coupon": null,
76
+ "default_payment_method": null,
77
+ "default_tax_rates": [
78
+
79
+ ],
80
+ "end_date": 1653590510,
81
+ "invoice_settings": null,
82
+ "items": [
83
+ {
84
+ "billing_thresholds": null,
85
+ "plan": "price_000000000000000000000000",
86
+ "price": "price_000000000000000000000000",
87
+ "quantity": 2,
88
+ "tax_rates": [
89
+
90
+ ]
91
+ }
92
+ ],
93
+ "proration_behavior": "create_prorations",
94
+ "start_date": 1650998510,
95
+ "transfer_data": null,
96
+ "trial_end": null
97
+ }
98
+ ],
99
+ "released_at": null,
100
+ "released_subscription": null,
101
+ "renewal_interval": null,
102
+ "status": "active",
103
+ "subscription": "sub_000000000000000000000000",
104
+ "test_clock": null
105
+ }
106
+ },
107
+ "livemode": false,
108
+ "pending_webhooks": 2,
109
+ "request": {
110
+ "id": "req_00000000000000",
111
+ "idempotency_key": "af06a7d9-5408-4f65-8379-59a93874d04c"
112
+ },
113
+ "type": "subscription_schedule.created"
114
+ }
@@ -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
@@ -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,8 @@ 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'
68
+ require 'stripe_mock/request_handlers/promotion_codes.rb'
65
69
  require 'stripe_mock/request_handlers/recipients.rb'
66
70
  require 'stripe_mock/request_handlers/refunds.rb'
67
71
  require 'stripe_mock/request_handlers/transfers.rb'
@@ -76,7 +80,7 @@ require 'stripe_mock/request_handlers/country_spec.rb'
76
80
  require 'stripe_mock/request_handlers/ephemeral_key.rb'
77
81
  require 'stripe_mock/request_handlers/products.rb'
78
82
  require 'stripe_mock/request_handlers/tax_rates.rb'
79
- 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'
@@ -86,12 +90,14 @@ require 'stripe_mock/test_strategies/live.rb'
86
90
  module StripeMock
87
91
 
88
92
  @default_currency = 'usd'
93
+ @checkout_base = "https://checkout.stripe.com/pay/"
89
94
  lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
90
95
  @webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
91
96
  @webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
92
97
 
93
98
  class << self
94
99
  attr_accessor :default_currency
100
+ attr_accessor :checkout_base
95
101
  attr_accessor :webhook_fixture_path
96
102
  end
97
103
  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 }
@@ -54,17 +56,15 @@ describe StripeMock::Instance do
54
56
  end
55
57
 
56
58
  it "allows non-usd default currency" do
59
+ pending("Stripe::Plan requires currency param - how can we test this?")
57
60
  old_default_currency = StripeMock.default_currency
58
- customer = begin
61
+ plan = begin
59
62
  StripeMock.default_currency = "jpy"
60
- Stripe::Customer.create({
61
- email: 'johnny@appleseed.com',
62
- source: stripe_helper.generate_card_token
63
- })
63
+ Stripe::Plan.create(interval: 'month')
64
64
  ensure
65
65
  StripeMock.default_currency = old_default_currency
66
66
  end
67
- expect(customer.currency).to eq("jpy")
67
+ expect(plan.currency).to eq("jpy")
68
68
  end
69
69
 
70
70
  context 'when creating sources with metadata' do
@@ -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/list_spec.rb CHANGED
@@ -152,4 +152,27 @@ describe StripeMock::Data::List do
152
152
  expect { list.to_h }.to raise_error
153
153
  end
154
154
  end
155
+
156
+ context "with data containing records marked 'deleted'" do
157
+ let(:customer_data) { StripeMock.instance.customers.values }
158
+ let(:customers) do
159
+ customer_data.map { |datum| Stripe::Util.convert_to_stripe_object(datum) }
160
+ end
161
+
162
+ before do
163
+ StripeMock.instance.customers.clear
164
+ Stripe::Customer.create
165
+ Stripe::Customer.delete(Stripe::Customer.create.id)
166
+ end
167
+
168
+ it "does not raise error on initialization" do
169
+ expect { StripeMock::Data::List.new(customer_data) }.to_not raise_error
170
+ expect { StripeMock::Data::List.new(customers) }.to_not raise_error
171
+ end
172
+
173
+ it "omits records marked 'deleted'" do
174
+ expect(StripeMock::Data::List.new(customer_data).data.size).to eq(1)
175
+ expect(StripeMock::Data::List.new(customers).data.size).to eq(1)
176
+ end
177
+ end
155
178
  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
 
data/spec/server_spec.rb CHANGED
@@ -38,14 +38,16 @@ describe 'StripeMock Server', :mock_server => true do
38
38
  customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
39
39
  expect(customer.email).to eq('johnny@appleseed.com')
40
40
 
41
- server_customer_data = StripeMock.client.get_server_data(:customers)[customer.id]
41
+ server_customer_data = StripeMock.client.get_server_data(:customers)
42
+ server_customer_data = server_customer_data[server_customer_data.keys.first][customer.id.to_sym]
42
43
  expect(server_customer_data).to_not be_nil
43
44
  expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
44
45
 
45
46
  StripeMock.stop_client
46
47
  StripeMock.start_client
47
48
 
48
- server_customer_data = StripeMock.client.get_server_data(:customers)[customer.id]
49
+ server_customer_data = StripeMock.client.get_server_data(:customers)
50
+ server_customer_data = server_customer_data[server_customer_data.keys.first][customer.id.to_sym]
49
51
  expect(server_customer_data).to_not be_nil
50
52
  expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
51
53
  end
@@ -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')
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Account Link API' do
4
+ describe 'create account link' do
5
+ it 'creates an account link' do
6
+ account_link = Stripe::AccountLink.create(
7
+ type: 'onboarding',
8
+ account: 'acct_103ED82ePvKYlo2C',
9
+ failure_url: 'https://stripe.com',
10
+ success_url: 'https://stripe.com'
11
+ )
12
+
13
+ expect(account_link).to be_a Stripe::AccountLink
14
+ end
15
+ end
16
+ end
@@ -8,4 +8,10 @@ shared_examples 'Balance API' do
8
8
  expect(balance.available[0].amount).to eq(2000)
9
9
  end
10
10
 
11
+ it "retrieves a stripe instant balance" do
12
+ StripeMock.set_account_balance(2000)
13
+ balance = Stripe::Balance.retrieve()
14
+ expect(balance.instant_available[0].amount).to eq(2000)
15
+ end
16
+
11
17
  end