stripe-ruby-mock 3.1.0.rc2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.rspec +2 -1
- data/CHANGELOG.md +34 -0
- data/README.md +5 -3
- data/lib/stripe_mock/api/webhooks.rb +65 -26
- data/lib/stripe_mock/data.rb +80 -11
- data/lib/stripe_mock/instance.rb +6 -2
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/charges.rb +5 -0
- data/lib/stripe_mock/request_handlers/checkout_session.rb +165 -2
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +28 -9
- data/lib/stripe_mock/request_handlers/invoices.rb +6 -1
- data/lib/stripe_mock/request_handlers/payment_intents.rb +13 -2
- data/lib/stripe_mock/request_handlers/payment_methods.rb +5 -1
- data/lib/stripe_mock/request_handlers/prices.rb +18 -0
- 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 +16 -9
- data/lib/stripe_mock/request_handlers/subscriptions.rb +93 -4
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -8
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +51 -25
- 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 +26 -20
- 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 +49 -120
- 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 -46
- 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 -47
- 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 +118 -79
- 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 +85 -53
- 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 +19 -13
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
- 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 +3 -1
- data/spec/instance_spec.rb +3 -1
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/shared_stripe_examples/account_examples.rb +9 -1
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +21 -0
- data/spec/shared_stripe_examples/payment_intent_examples.rb +74 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +32 -27
- data/spec/shared_stripe_examples/price_examples.rb +42 -2
- data/spec/shared_stripe_examples/product_examples.rb +1 -9
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +13 -0
- data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +213 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
- data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
- data/spec/support/stripe_examples.rb +3 -1
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +54 -11
- data/.travis.yml +0 -25
- data/lib/stripe_mock/request_handlers/checkout.rb +0 -15
- data/spec/shared_stripe_examples/checkout_examples.rb +0 -38
@@ -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
@@ -65,6 +65,7 @@ require 'stripe_mock/request_handlers/invoice_items.rb'
|
|
65
65
|
require 'stripe_mock/request_handlers/orders.rb'
|
66
66
|
require 'stripe_mock/request_handlers/plans.rb'
|
67
67
|
require 'stripe_mock/request_handlers/prices.rb'
|
68
|
+
require 'stripe_mock/request_handlers/promotion_codes.rb'
|
68
69
|
require 'stripe_mock/request_handlers/recipients.rb'
|
69
70
|
require 'stripe_mock/request_handlers/refunds.rb'
|
70
71
|
require 'stripe_mock/request_handlers/transfers.rb'
|
@@ -79,7 +80,6 @@ require 'stripe_mock/request_handlers/country_spec.rb'
|
|
79
80
|
require 'stripe_mock/request_handlers/ephemeral_key.rb'
|
80
81
|
require 'stripe_mock/request_handlers/products.rb'
|
81
82
|
require 'stripe_mock/request_handlers/tax_rates.rb'
|
82
|
-
require 'stripe_mock/request_handlers/checkout.rb'
|
83
83
|
require 'stripe_mock/request_handlers/checkout_session.rb'
|
84
84
|
require 'stripe_mock/instance'
|
85
85
|
|
@@ -90,12 +90,14 @@ require 'stripe_mock/test_strategies/live.rb'
|
|
90
90
|
module StripeMock
|
91
91
|
|
92
92
|
@default_currency = 'usd'
|
93
|
+
@checkout_base = "https://checkout.stripe.com/pay/"
|
93
94
|
lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
|
94
95
|
@webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
|
95
96
|
@webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
|
96
97
|
|
97
98
|
class << self
|
98
99
|
attr_accessor :default_currency
|
100
|
+
attr_accessor :checkout_base
|
99
101
|
attr_accessor :webhook_fixture_path
|
100
102
|
end
|
101
103
|
end
|
data/spec/instance_spec.rb
CHANGED
@@ -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)
|
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
@@ -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
|
|
@@ -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,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
|
@@ -14,6 +14,11 @@ shared_examples 'Invoice API' do
|
|
14
14
|
expect(data[invoice.id]).to_not be_nil
|
15
15
|
expect(data[invoice.id][:id]).to eq(invoice.id)
|
16
16
|
end
|
17
|
+
|
18
|
+
it "supports invoice number" do
|
19
|
+
original = Stripe::Invoice.create
|
20
|
+
expect(original.number).to be
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
context "retrieving an invoice" do
|
@@ -83,12 +88,28 @@ shared_examples 'Invoice API' do
|
|
83
88
|
@invoice = @invoice.pay
|
84
89
|
expect(@invoice.attempted).to eq(true)
|
85
90
|
expect(@invoice.paid).to eq(true)
|
91
|
+
expect(@invoice.status).to eq("paid")
|
86
92
|
end
|
87
93
|
|
88
94
|
it 'creates a new charge object' do
|
89
95
|
expect{ @invoice.pay }.to change { Stripe::Charge.list.data.count }.by 1
|
90
96
|
end
|
91
97
|
|
98
|
+
it 'should work with Stripe::Invoice.pay(invoice_id)' do
|
99
|
+
expect(@invoice.paid).to_not eq(true)
|
100
|
+
|
101
|
+
expect {
|
102
|
+
Stripe::Invoice.pay(@invoice.id)
|
103
|
+
}.to change { Stripe::Charge.list.data.count }.by 1
|
104
|
+
|
105
|
+
@invoice = Stripe::Invoice.retrieve(id: @invoice.id)
|
106
|
+
expect(@invoice).to_not be_nil
|
107
|
+
|
108
|
+
expect(@invoice.attempted).to eq(true)
|
109
|
+
expect(@invoice.paid).to eq(true)
|
110
|
+
expect(@invoice.status).to eq("paid")
|
111
|
+
end
|
112
|
+
|
92
113
|
it 'sets the charge attribute' do
|
93
114
|
@invoice = @invoice.pay
|
94
115
|
expect(@invoice.charge).to be_a String
|
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'PaymentIntent API' do
|
4
4
|
|
5
|
+
let(:customer) do
|
6
|
+
token = Stripe::Token.retrieve(stripe_helper.generate_card_token(number: '4242424242424242'))
|
7
|
+
Stripe::Customer.create(email: 'alice@bob.com', source: token.id)
|
8
|
+
end
|
9
|
+
|
5
10
|
it "creates a succeeded stripe payment_intent" do
|
6
11
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
7
12
|
|
@@ -92,6 +97,35 @@ shared_examples 'PaymentIntent API' do
|
|
92
97
|
expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
|
93
98
|
end
|
94
99
|
|
100
|
+
it 'creates a charge for a stripe payment_intent with confirm flag to true' do
|
101
|
+
payment_intent = Stripe::PaymentIntent.create amount: 100,
|
102
|
+
currency: 'usd',
|
103
|
+
confirm: true,
|
104
|
+
customer: customer,
|
105
|
+
payment_method: customer.sources.first
|
106
|
+
|
107
|
+
charge = payment_intent.charges.data.first
|
108
|
+
expect(charge.amount).to eq(payment_intent.amount)
|
109
|
+
expect(charge.payment_intent).to eq(payment_intent.id)
|
110
|
+
expect(charge.description).to be_nil
|
111
|
+
|
112
|
+
charge.description = 'Updated description'
|
113
|
+
charge.save
|
114
|
+
|
115
|
+
updated = Stripe::Charge.retrieve(charge.id)
|
116
|
+
expect(updated.description).to eq('Updated description')
|
117
|
+
end
|
118
|
+
|
119
|
+
it "includes the payment_method on charges" do
|
120
|
+
payment_intent = Stripe::PaymentIntent.create(
|
121
|
+
amount: 100, currency: "usd", confirm: true, payment_method: "test_pm_1"
|
122
|
+
)
|
123
|
+
expect(payment_intent.status).to eq("succeeded")
|
124
|
+
expect(payment_intent.charges.data.size).to eq(1)
|
125
|
+
expect(payment_intent.charges.data.first.object).to eq("charge")
|
126
|
+
expect(payment_intent.charges.data.first.payment_method).to eq("test_pm_1")
|
127
|
+
end
|
128
|
+
|
95
129
|
it "confirms a stripe payment_intent" do
|
96
130
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
97
131
|
confirmed_payment_intent = payment_intent.confirm()
|
@@ -100,6 +134,25 @@ shared_examples 'PaymentIntent API' do
|
|
100
134
|
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
101
135
|
end
|
102
136
|
|
137
|
+
it 'creates a charge for a confirmed stripe payment_intent' do
|
138
|
+
payment_intent = Stripe::PaymentIntent.create amount: 100,
|
139
|
+
currency: 'usd',
|
140
|
+
customer: customer,
|
141
|
+
payment_method: customer.sources.first
|
142
|
+
|
143
|
+
confirmed_payment_intent = payment_intent.confirm
|
144
|
+
charge = confirmed_payment_intent.charges.data.first
|
145
|
+
expect(charge.amount).to eq(confirmed_payment_intent.amount)
|
146
|
+
expect(charge.payment_intent).to eq(confirmed_payment_intent.id)
|
147
|
+
expect(charge.description).to be_nil
|
148
|
+
|
149
|
+
charge.description = 'Updated description'
|
150
|
+
charge.save
|
151
|
+
|
152
|
+
updated = Stripe::Charge.retrieve(charge.id)
|
153
|
+
expect(updated.description).to eq('Updated description')
|
154
|
+
end
|
155
|
+
|
103
156
|
it "captures a stripe payment_intent" do
|
104
157
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
105
158
|
confirmed_payment_intent = payment_intent.capture()
|
@@ -108,6 +161,27 @@ shared_examples 'PaymentIntent API' do
|
|
108
161
|
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
|
109
162
|
end
|
110
163
|
|
164
|
+
it 'creates a charge for a captured stripe payment_intent' do
|
165
|
+
payment_intent = Stripe::PaymentIntent.create amount: 3055,
|
166
|
+
currency: 'usd',
|
167
|
+
customer: customer,
|
168
|
+
payment_method: customer.sources.first,
|
169
|
+
confirm: true,
|
170
|
+
capture_method: 'manual'
|
171
|
+
|
172
|
+
captured_payment_intent = payment_intent.capture
|
173
|
+
charge = captured_payment_intent.charges.data.first
|
174
|
+
expect(charge.amount).to eq(captured_payment_intent.amount)
|
175
|
+
expect(charge.payment_intent).to eq(captured_payment_intent.id)
|
176
|
+
expect(charge.description).to be_nil
|
177
|
+
|
178
|
+
charge.description = 'Updated description'
|
179
|
+
charge.save
|
180
|
+
|
181
|
+
updated = Stripe::Charge.retrieve(charge.id)
|
182
|
+
expect(updated.description).to eq('Updated description')
|
183
|
+
end
|
184
|
+
|
111
185
|
it "cancels a stripe payment_intent" do
|
112
186
|
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
|
113
187
|
confirmed_payment_intent = payment_intent.cancel()
|