stripe-ruby-mock 2.5.8 → 4.0.0
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.
- checksums.yaml +5 -5
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.gitignore +1 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +77 -0
- data/Gemfile +1 -5
- data/README.md +19 -11
- data/lib/stripe_mock/api/client.rb +2 -2
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +68 -24
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +359 -21
- data/lib/stripe_mock/instance.rb +23 -5
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +31 -5
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +47 -19
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -0
- data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +26 -6
- data/lib/stripe_mock/request_handlers/payment_intents.rb +202 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +124 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +71 -0
- data/lib/stripe_mock/request_handlers/products.rb +15 -5
- data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
- data/lib/stripe_mock/request_handlers/setup_intents.rb +100 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +146 -25
- data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +124 -9
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +98 -12
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -2
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +27 -15
- data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +101 -44
- data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -45
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -46
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
- data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
- data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
- data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +225 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +196 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
- data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
- data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
- data/lib/stripe_mock.rb +11 -0
- data/spec/instance_spec.rb +13 -13
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/list_spec.rb +38 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/server_spec.rb +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +10 -2
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +106 -22
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +149 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +148 -40
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +283 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +454 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -92
- data/spec/shared_stripe_examples/price_examples.rb +292 -0
- data/spec/shared_stripe_examples/product_examples.rb +215 -0
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +38 -21
- data/spec/shared_stripe_examples/setup_intent_examples.rb +85 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +706 -324
- data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +16 -7
- data/spec/shared_stripe_examples/webhook_event_examples.rb +62 -16
- data/spec/spec_helper.rb +8 -5
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +11 -1
- data/stripe-ruby-mock.gemspec +9 -5
- metadata +115 -47
- data/.travis.yml +0 -28
- data/spec/shared_stripe_examples/product_example.rb +0 -65
@@ -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,11 +42,14 @@ 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
|
|
48
49
|
require 'stripe_mock/request_handlers/validators/param_validators.rb'
|
49
50
|
|
51
|
+
require 'stripe_mock/request_handlers/account_links.rb'
|
52
|
+
require 'stripe_mock/request_handlers/express_login_links.rb'
|
50
53
|
require 'stripe_mock/request_handlers/accounts.rb'
|
51
54
|
require 'stripe_mock/request_handlers/external_accounts.rb'
|
52
55
|
require 'stripe_mock/request_handlers/balance.rb'
|
@@ -62,9 +65,14 @@ require 'stripe_mock/request_handlers/invoices.rb'
|
|
62
65
|
require 'stripe_mock/request_handlers/invoice_items.rb'
|
63
66
|
require 'stripe_mock/request_handlers/orders.rb'
|
64
67
|
require 'stripe_mock/request_handlers/plans.rb'
|
68
|
+
require 'stripe_mock/request_handlers/prices.rb'
|
69
|
+
require 'stripe_mock/request_handlers/promotion_codes.rb'
|
65
70
|
require 'stripe_mock/request_handlers/recipients.rb'
|
66
71
|
require 'stripe_mock/request_handlers/refunds.rb'
|
67
72
|
require 'stripe_mock/request_handlers/transfers.rb'
|
73
|
+
require 'stripe_mock/request_handlers/payment_intents.rb'
|
74
|
+
require 'stripe_mock/request_handlers/payment_methods.rb'
|
75
|
+
require 'stripe_mock/request_handlers/setup_intents.rb'
|
68
76
|
require 'stripe_mock/request_handlers/payouts.rb'
|
69
77
|
require 'stripe_mock/request_handlers/subscriptions.rb'
|
70
78
|
require 'stripe_mock/request_handlers/subscription_items.rb'
|
@@ -73,6 +81,7 @@ require 'stripe_mock/request_handlers/country_spec.rb'
|
|
73
81
|
require 'stripe_mock/request_handlers/ephemeral_key.rb'
|
74
82
|
require 'stripe_mock/request_handlers/products.rb'
|
75
83
|
require 'stripe_mock/request_handlers/tax_rates.rb'
|
84
|
+
require 'stripe_mock/request_handlers/checkout_session.rb'
|
76
85
|
require 'stripe_mock/instance'
|
77
86
|
|
78
87
|
require 'stripe_mock/test_strategies/base.rb'
|
@@ -82,12 +91,14 @@ require 'stripe_mock/test_strategies/live.rb'
|
|
82
91
|
module StripeMock
|
83
92
|
|
84
93
|
@default_currency = 'usd'
|
94
|
+
@checkout_base = "https://checkout.stripe.com/pay/"
|
85
95
|
lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
|
86
96
|
@webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
|
87
97
|
@webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
|
88
98
|
|
89
99
|
class << self
|
90
100
|
attr_accessor :default_currency
|
101
|
+
attr_accessor :checkout_base
|
91
102
|
attr_accessor :webhook_fixture_path
|
92
103
|
end
|
93
104
|
end
|
data/spec/instance_spec.rb
CHANGED
@@ -6,20 +6,22 @@ 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)
|
9
|
+
def test_data_source(type)
|
10
|
+
StripeMock.instance.send(type)
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
14
|
before { StripeMock.start }
|
13
15
|
after { StripeMock.stop }
|
14
16
|
|
15
17
|
it "handles both string and symbol hash keys" do
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
symbol_params = stripe_helper.create_product_params(
|
19
|
+
:name => "Symbol Product",
|
20
|
+
"type" => "service"
|
19
21
|
)
|
20
|
-
res, api_key = StripeMock.instance.mock_request('post', '/v1/
|
21
|
-
expect(res.data[:
|
22
|
-
expect(res.data[:
|
22
|
+
res, api_key = StripeMock.instance.mock_request('post', '/v1/products', api_key: 'api_key', params: symbol_params)
|
23
|
+
expect(res.data[:name]).to eq('Symbol Product')
|
24
|
+
expect(res.data[:type]).to eq('service')
|
23
25
|
end
|
24
26
|
|
25
27
|
it "exits gracefully on an unrecognized handler url" do
|
@@ -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
|
-
|
61
|
+
plan = begin
|
59
62
|
StripeMock.default_currency = "jpy"
|
60
|
-
Stripe::
|
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(
|
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
@@ -109,6 +109,21 @@ describe StripeMock::Data::List do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
context "active filter" do
|
113
|
+
it "accepts an active param which filters out data accordingly" do
|
114
|
+
product = Stripe::Product.create(id: "prod_123", name: "My Beautiful Product", type: "service")
|
115
|
+
|
116
|
+
plan_attributes = { product: product.id, interval: "month", currency: "usd", amount: 500 }
|
117
|
+
plan_a = Stripe::Plan.create(plan_attributes)
|
118
|
+
plan_b = Stripe::Plan.create(**plan_attributes, active: false)
|
119
|
+
|
120
|
+
list = StripeMock::Data::List.new([plan_a, plan_b], active: true)
|
121
|
+
|
122
|
+
expect(list.active).to eq(true)
|
123
|
+
expect(list.to_h[:data].count).to eq(1)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
112
127
|
context "pagination" do
|
113
128
|
it "has a has_more field when it has more" do
|
114
129
|
list = StripeMock::Data::List.new(
|
@@ -137,4 +152,27 @@ describe StripeMock::Data::List do
|
|
137
152
|
expect { list.to_h }.to raise_error
|
138
153
|
end
|
139
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
|
140
178
|
end
|
data/spec/readme_spec.rb
CHANGED
data/spec/server_spec.rb
CHANGED
@@ -19,6 +19,7 @@ describe 'StripeMock Server', :mock_server => true do
|
|
19
19
|
|
20
20
|
after { StripeMock.stop_client(:clear_server_data => true) }
|
21
21
|
|
22
|
+
let(:product) { stripe_helper.create_product }
|
22
23
|
|
23
24
|
it "uses an RPC client for mock requests" do
|
24
25
|
charge = Stripe::Charge.create(
|
@@ -37,21 +38,23 @@ describe 'StripeMock Server', :mock_server => true do
|
|
37
38
|
customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
|
38
39
|
expect(customer.email).to eq('johnny@appleseed.com')
|
39
40
|
|
40
|
-
server_customer_data = StripeMock.client.get_server_data(:customers)
|
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]
|
41
43
|
expect(server_customer_data).to_not be_nil
|
42
44
|
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
43
45
|
|
44
46
|
StripeMock.stop_client
|
45
47
|
StripeMock.start_client
|
46
48
|
|
47
|
-
server_customer_data = StripeMock.client.get_server_data(:customers)
|
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]
|
48
51
|
expect(server_customer_data).to_not be_nil
|
49
52
|
expect(server_customer_data[:email]).to eq('johnny@appleseed.com')
|
50
53
|
end
|
51
54
|
|
52
55
|
|
53
56
|
it "returns a response with symbolized hash keys" do
|
54
|
-
stripe_helper.create_plan(id: 'x')
|
57
|
+
stripe_helper.create_plan(id: 'x', product: product.id)
|
55
58
|
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
|
56
59
|
response.data.keys.each {|k| expect(k).to be_a(Symbol) }
|
57
60
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples 'Account API' do
|
4
|
-
describe '
|
4
|
+
describe 'retrieve accounts' do
|
5
5
|
it 'retrieves a stripe account', live: true do
|
6
6
|
account = Stripe::Account.retrieve
|
7
7
|
|
@@ -15,7 +15,7 @@ shared_examples 'Account API' do
|
|
15
15
|
expect(account.id).to match /acct\_/
|
16
16
|
end
|
17
17
|
it 'retrieves all' do
|
18
|
-
accounts = Stripe::Account.
|
18
|
+
accounts = Stripe::Account.list
|
19
19
|
|
20
20
|
expect(accounts).to be_a Stripe::ListObject
|
21
21
|
expect(accounts.data.count).to satisfy { |n| n >= 1 }
|
@@ -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
|
@@ -26,7 +26,7 @@ shared_examples 'Balance Transaction API' do
|
|
26
26
|
describe "listing balance transactions" do
|
27
27
|
|
28
28
|
it "retrieves all balance transactions" do
|
29
|
-
disputes = Stripe::BalanceTransaction.
|
29
|
+
disputes = Stripe::BalanceTransaction.list
|
30
30
|
|
31
31
|
expect(disputes.count).to eq(10)
|
32
32
|
expect(disputes.map &:id).to include('txn_05RsQX2eZvKYlo2C0FRTGSSA','txn_15RsQX2eZvKYlo2C0ERTYUIA', 'txn_25RsQX2eZvKYlo2C0ZXCVBNM', 'txn_35RsQX2eZvKYlo2C0QAZXSWE', 'txn_45RsQX2eZvKYlo2C0EDCVFRT', 'txn_55RsQX2eZvKYlo2C0OIKLJUY', 'txn_65RsQX2eZvKYlo2C0ASDFGHJ', 'txn_75RsQX2eZvKYlo2C0EDCXSWQ', 'txn_85RsQX2eZvKYlo2C0UJMCDET', 'txn_95RsQX2eZvKYlo2C0EDFRYUI')
|
@@ -38,7 +38,7 @@ shared_examples 'Balance Transaction API' do
|
|
38
38
|
transfer_id = Stripe::Transfer.create({ amount: 2730, currency: "usd" })
|
39
39
|
|
40
40
|
# verify transfer currently has no balance transactions
|
41
|
-
transfer_transactions = Stripe::BalanceTransaction.
|
41
|
+
transfer_transactions = Stripe::BalanceTransaction.list({transfer: transfer_id})
|
42
42
|
expect(transfer_transactions.count).to eq(0)
|
43
43
|
|
44
44
|
# verify we can create a new balance transaction associated with the transfer
|
@@ -55,7 +55,7 @@ shared_examples 'Balance Transaction API' do
|
|
55
55
|
stripe_helper.upsert_stripe_object(:balance_transaction, {id: existing_txn_id, transfer: transfer_id})
|
56
56
|
|
57
57
|
# now verify that only these balance transactions are retrieved with the transfer
|
58
|
-
transfer_transactions = Stripe::BalanceTransaction.
|
58
|
+
transfer_transactions = Stripe::BalanceTransaction.list({transfer: transfer_id})
|
59
59
|
expect(transfer_transactions.count).to eq(2)
|
60
60
|
expect(transfer_transactions.map &:id).to include(new_txn_id, existing_txn_id)
|
61
61
|
end
|
@@ -77,7 +77,7 @@ shared_examples 'Bank API' do
|
|
77
77
|
let!(:bank) { customer.sources.create(source: bank_token) }
|
78
78
|
|
79
79
|
it "can retrieve all customer's banks" do
|
80
|
-
retrieved = customer.sources.
|
80
|
+
retrieved = customer.sources.list
|
81
81
|
expect(retrieved.count).to eq(1)
|
82
82
|
end
|
83
83
|
|
@@ -174,7 +174,7 @@ shared_examples 'Bank API' do
|
|
174
174
|
|
175
175
|
customer = Stripe::Customer.retrieve('test_customer_bank')
|
176
176
|
|
177
|
-
list = customer.sources.
|
177
|
+
list = customer.sources.list
|
178
178
|
|
179
179
|
expect(list.object).to eq("list")
|
180
180
|
expect(list.count).to eq(2)
|
@@ -191,7 +191,7 @@ shared_examples 'Bank API' do
|
|
191
191
|
Stripe::Customer.create(id: 'no_banks')
|
192
192
|
customer = Stripe::Customer.retrieve('no_banks')
|
193
193
|
|
194
|
-
list = customer.sources.
|
194
|
+
list = customer.sources.list
|
195
195
|
|
196
196
|
expect(list.object).to eq("list")
|
197
197
|
expect(list.count).to eq(0)
|
@@ -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
|
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
|
-
|
37
|
+
customer = Stripe::Customer.create({
|
38
38
|
name: "Fred Flinstone",
|
39
|
-
type: "individual",
|
40
39
|
email: 'blah@domain.co',
|
41
|
-
|
40
|
+
source: bank_token
|
42
41
|
})
|
43
|
-
expect(
|
44
|
-
expect(
|
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
|
@@ -134,7 +134,7 @@ shared_examples 'Card API' do
|
|
134
134
|
let!(:card) { customer.sources.create(source: card_token) }
|
135
135
|
|
136
136
|
it "can retrieve all customer's cards" do
|
137
|
-
retrieved = customer.sources.
|
137
|
+
retrieved = customer.sources.list
|
138
138
|
expect(retrieved.count).to eq(1)
|
139
139
|
end
|
140
140
|
|
@@ -198,7 +198,7 @@ shared_examples 'Card API' do
|
|
198
198
|
let!(:card) { recipient.cards.create(card: card_token) }
|
199
199
|
|
200
200
|
it "can retrieve all recipient's cards" do
|
201
|
-
retrieved = recipient.cards.
|
201
|
+
retrieved = recipient.cards.list
|
202
202
|
expect(retrieved.count).to eq(1)
|
203
203
|
end
|
204
204
|
|
@@ -279,7 +279,7 @@ shared_examples 'Card API' do
|
|
279
279
|
|
280
280
|
customer = Stripe::Customer.retrieve('test_customer_card')
|
281
281
|
|
282
|
-
list = customer.sources.
|
282
|
+
list = customer.sources.list
|
283
283
|
|
284
284
|
expect(list.object).to eq("list")
|
285
285
|
expect(list.count).to eq(2)
|
@@ -296,7 +296,7 @@ shared_examples 'Card API' do
|
|
296
296
|
Stripe::Customer.create(id: 'no_cards')
|
297
297
|
customer = Stripe::Customer.retrieve('no_cards')
|
298
298
|
|
299
|
-
list = customer.sources.
|
299
|
+
list = customer.sources.list
|
300
300
|
|
301
301
|
expect(list.object).to eq("list")
|
302
302
|
expect(list.count).to eq(0)
|
@@ -145,34 +145,30 @@ shared_examples 'Card Token Mocking' do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'generates a card token from another card', oauth: true do
|
148
|
-
token =
|
149
|
-
card: {
|
150
|
-
exp_month: 10,
|
151
|
-
exp_year: 2016,
|
152
|
-
number: '4242424242424242'
|
153
|
-
}
|
154
|
-
)
|
148
|
+
token = StripeMock.generate_card_token(last4: "2244", exp_month: 33, exp_year: 2255)
|
155
149
|
|
156
|
-
cus1 = Stripe::Customer.create(
|
150
|
+
cus1 = Stripe::Customer.create()
|
151
|
+
cus1.source = token
|
152
|
+
cus1.save
|
157
153
|
|
158
154
|
card1 = cus1.sources.data.first
|
159
|
-
expect(card1.last4).to eq(
|
160
|
-
expect(card1.exp_month).to eq(
|
161
|
-
expect(card1.exp_year).to eq(
|
155
|
+
expect(card1.last4).to eq("2244")
|
156
|
+
expect(card1.exp_month).to eq(33)
|
157
|
+
expect(card1.exp_year).to eq(2255)
|
162
158
|
|
163
|
-
card_token = Stripe::Token.create(
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
},
|
168
|
-
ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
159
|
+
card_token = Stripe::Token.create({
|
160
|
+
customer: cus1.id,
|
161
|
+
card: card1.id
|
162
|
+
})
|
169
163
|
|
170
|
-
cus2 = Stripe::Customer.create({
|
164
|
+
cus2 = Stripe::Customer.create({}, ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN'])
|
165
|
+
cus2.source = card_token.id
|
166
|
+
cus2.save
|
171
167
|
|
172
168
|
card2 = cus2.sources.data.first
|
173
|
-
expect(card2.last4).to eq(
|
174
|
-
expect(card2.exp_month).to eq(
|
175
|
-
expect(card2.exp_year).to eq(
|
169
|
+
expect(card2.last4).to eq("2244")
|
170
|
+
expect(card2.exp_month).to eq(33)
|
171
|
+
expect(card2.exp_year).to eq(2255)
|
176
172
|
end
|
177
173
|
|
178
174
|
it "throws an error if neither card nor customer are provided", :live => true do
|