stripe-ruby-mock 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +10 -4
- data/lib/stripe_mock.rb +1 -0
- data/lib/stripe_mock/api/errors.rb +3 -0
- data/lib/stripe_mock/data.rb +43 -3
- data/lib/stripe_mock/data/list.rb +11 -3
- data/lib/stripe_mock/instance.rb +3 -1
- data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
- data/lib/stripe_mock/request_handlers/customers.rb +15 -7
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +5 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/payment_intents.rb +8 -1
- data/lib/stripe_mock/request_handlers/payment_methods.rb +0 -21
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/subscriptions.rb +1 -1
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/list_spec.rb +15 -0
- data/spec/shared_stripe_examples/checkout_examples.rb +19 -0
- data/spec/shared_stripe_examples/customer_examples.rb +38 -10
- data/spec/shared_stripe_examples/payment_intent_examples.rb +10 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +34 -0
- data/spec/support/stripe_examples.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7918d71c6145222a77feaeea20d2e5c211ce53c4
|
4
|
+
data.tar.gz: 1aa548101a97a4fb5d5afe9294928b65fe0491d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d83ccd0ba75faea9acce0f2f978099f215e22cd60563e80375a8e6f40ba3879e9b3d00b4a467f23797a80320e641629a60c20ebc675c2b7bfc92fedc055bc0d2
|
7
|
+
data.tar.gz: 2e84b51981c315096a514e6d0e6caf8085d239a800e6dd47590d323bedd492d9c79250c448caa70c7a9ac8ae2f7d62b55d5928b2d489ff379b35e448d90584e0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
### 3.0.2 (Next)
|
2
|
+
|
3
|
+
* Your contribution here.
|
4
|
+
|
5
|
+
### 3.0.1 (TBD)
|
6
|
+
* Added Changelog file
|
7
|
+
* [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
|
8
|
+
* [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
|
9
|
+
* [#682](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/682): Prevent customer metadata from being overwritten with each update - [@sethkrasnianski](https://github.com/sethkrasnianski).
|
10
|
+
* [#679](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/679): Fix for [#678](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/678) Add active filter to Data::List - [@rnmp](https://github.com/rnmp).
|
11
|
+
* [#668](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/668): Fix for [#665](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/665) Allow to remove discount from customer - [@mnin](https://github.com/mnin).
|
12
|
+
* [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
|
13
|
+
Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
|
14
|
+
* [#664](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/664): Bugfix: pass through PaymentIntent amount to mocked Charge - [@typeoneerror](https://github.com/typeoneerror).
|
15
|
+
* [#654](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/654): fix for [#626](https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues/626) Added missing decline codes - [@iCreateJB](https://github.com/iCreateJB).
|
16
|
+
* [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
|
17
|
+
* [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).
|
18
|
+
|
19
|
+
### 3.0.0 (2019-12-17)
|
20
|
+
|
21
|
+
##### the main thing is:
|
22
|
+
- [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# stripe-ruby-mock [![Build Status](https://travis-ci.org/
|
1
|
+
# stripe-ruby-mock [![Build Status](https://travis-ci.org/stripe-ruby-mock/stripe-ruby-mock.png?branch=master)](https://travis-ci.org/stripe-ruby-mock/stripe-ruby-mock) [![Gitter chat](https://badges.gitter.im/rebelidealist/stripe-ruby-mock.png)](https://gitter.im/rebelidealist/stripe-ruby-mock)
|
2
2
|
|
3
|
-
* Homepage: https://github.com/
|
4
|
-
* Issues: https://github.com/
|
3
|
+
* Homepage: https://github.com/stripe-ruby-mock/stripe-ruby-mock
|
4
|
+
* Issues: https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues
|
5
5
|
* **CHAT**: https://gitter.im/rebelidealist/stripe-ruby-mock
|
6
6
|
|
7
7
|
# REQUEST: Looking for More Core Contributors
|
@@ -12,7 +12,13 @@ This gem has unexpectedly grown in popularity and I've gotten pretty busy, so I'
|
|
12
12
|
|
13
13
|
In your gemfile:
|
14
14
|
|
15
|
-
gem 'stripe-ruby-mock', '~> 3.0.
|
15
|
+
gem 'stripe-ruby-mock', '~> 3.0.1', :require => 'stripe_mock'
|
16
|
+
|
17
|
+
## !!! Important
|
18
|
+
|
19
|
+
We have [changelog](https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md). It's first attempt. Feel free to update it and suggest to a new format of it.
|
20
|
+
|
21
|
+
version `3.0.0` has [breaking changes](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) - we support stripe > 5 and < 6 for now and try to follow the newest API version. But if you still use older versions please [read](https://github.com/stripe-ruby-mock/stripe-ruby-mock#specifications).
|
16
22
|
|
17
23
|
## Features
|
18
24
|
|
data/lib/stripe_mock.rb
CHANGED
@@ -76,6 +76,7 @@ require 'stripe_mock/request_handlers/country_spec.rb'
|
|
76
76
|
require 'stripe_mock/request_handlers/ephemeral_key.rb'
|
77
77
|
require 'stripe_mock/request_handlers/products.rb'
|
78
78
|
require 'stripe_mock/request_handlers/tax_rates.rb'
|
79
|
+
require 'stripe_mock/request_handlers/checkout.rb'
|
79
80
|
require 'stripe_mock/instance'
|
80
81
|
|
81
82
|
require 'stripe_mock/test_strategies/base.rb'
|
@@ -37,6 +37,9 @@ module StripeMock
|
|
37
37
|
when :processing_error then build_card_error('An error occurred while processing the card', nil, code: 'processing_error', http_status: 402)
|
38
38
|
when :card_error then build_card_error('The card number is not a valid credit card number.', 'number', code: 'invalid_number', http_status: 402)
|
39
39
|
when :incorrect_zip then build_card_error('The zip code you supplied failed validation.', 'address_zip', code: 'incorrect_zip', http_status: 402)
|
40
|
+
when :insufficient_funds then build_card_error('The card has insufficient funds to complete the purchase.', nil, code: 'insufficient_funds', http_status: 402)
|
41
|
+
when :lost_card then build_card_error('The payment has been declined because the card is reported lost.', nil, code: 'lost_card', http_status: 402)
|
42
|
+
when :stolen_card then build_card_error('The payment has been declined because the card is reported stolen.', nil, code: 'stolen_card', http_status: 402)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
data/lib/stripe_mock/data.rb
CHANGED
@@ -349,7 +349,9 @@ module StripeMock
|
|
349
349
|
tax_percent: nil,
|
350
350
|
discount: nil,
|
351
351
|
metadata: {},
|
352
|
-
default_tax_rates: nil
|
352
|
+
default_tax_rates: nil,
|
353
|
+
pending_invoice_item_interval: nil,
|
354
|
+
next_pending_invoice_item_invoice: nil
|
353
355
|
}, params)
|
354
356
|
end
|
355
357
|
|
@@ -1184,7 +1186,7 @@ module StripeMock
|
|
1184
1186
|
},
|
1185
1187
|
customer: params[:customer] || nil,
|
1186
1188
|
metadata: {
|
1187
|
-
|
1189
|
+
order_id: "123456789"
|
1188
1190
|
}
|
1189
1191
|
|
1190
1192
|
}.merge(params)
|
@@ -1208,12 +1210,50 @@ module StripeMock
|
|
1208
1210
|
:on_behalf_of => nil,
|
1209
1211
|
:payment_method => nil,
|
1210
1212
|
:payment_method_options => {
|
1211
|
-
|
1213
|
+
card: {request_three_d_secure: "automatic"}
|
1212
1214
|
},
|
1213
1215
|
:payment_method_types => ["card"],
|
1214
1216
|
:status => "requires_payment_method",
|
1215
1217
|
:usage => "off_session"
|
1216
1218
|
}.merge(params)
|
1217
1219
|
end
|
1220
|
+
|
1221
|
+
def self.mock_checkout_session(params = {})
|
1222
|
+
cs_id = params[:id] || "test_cs_default"
|
1223
|
+
currency = params[:currency] || StripeMock.default_currency
|
1224
|
+
{
|
1225
|
+
id: cs_id,
|
1226
|
+
object: 'checkout.session',
|
1227
|
+
billing_address_collection: nil,
|
1228
|
+
cancel_url: 'https://example.com/cancel',
|
1229
|
+
client_reference_id: nil,
|
1230
|
+
customer: nil,
|
1231
|
+
customer_email: nil,
|
1232
|
+
display_items: [
|
1233
|
+
{
|
1234
|
+
amount: 1500,
|
1235
|
+
currency: currency,
|
1236
|
+
custom: {
|
1237
|
+
description: 'Comfortable cotton t-shirt',
|
1238
|
+
images: nil,
|
1239
|
+
name: 'T-shirt'
|
1240
|
+
},
|
1241
|
+
quantity: 2,
|
1242
|
+
type: 'custom'
|
1243
|
+
}
|
1244
|
+
],
|
1245
|
+
livemode: false,
|
1246
|
+
locale: nil,
|
1247
|
+
mode: nil,
|
1248
|
+
payment_intent: mock_payment_intent[:id],
|
1249
|
+
payment_method_types: [
|
1250
|
+
'card'
|
1251
|
+
],
|
1252
|
+
setup_intent: nil,
|
1253
|
+
submit_type: nil,
|
1254
|
+
subscription: nil,
|
1255
|
+
success_url: 'https://example.com/success'
|
1256
|
+
}.merge(params)
|
1257
|
+
end
|
1218
1258
|
end
|
1219
1259
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module StripeMock
|
2
2
|
module Data
|
3
3
|
class List
|
4
|
-
attr_reader :data, :limit, :offset, :starting_after, :ending_before
|
4
|
+
attr_reader :data, :limit, :offset, :starting_after, :ending_before, :active
|
5
5
|
|
6
6
|
def initialize(data, options = {})
|
7
7
|
@data = Array(data.clone)
|
8
8
|
@limit = [[options[:limit] || 10, 100].min, 1].max # restrict @limit to 1..100
|
9
9
|
@starting_after = options[:starting_after]
|
10
10
|
@ending_before = options[:ending_before]
|
11
|
+
@active = options[:active]
|
11
12
|
if @data.first.is_a?(Hash) && @data.first[:created]
|
12
13
|
@data.sort_by! { |x| x[:created] }
|
13
14
|
@data.reverse!
|
@@ -53,14 +54,21 @@ module StripeMock
|
|
53
54
|
(index || raise("No such object id: #{starting_after}")) + 1
|
54
55
|
when ending_before
|
55
56
|
index = data.index { |datum| datum[:id] == ending_before }
|
56
|
-
(index || raise("No such object id: #{ending_before}")) - 1
|
57
|
+
(index || raise("No such object id: #{ending_before}")) - 1
|
57
58
|
else
|
58
59
|
0
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
63
|
def data_page
|
63
|
-
|
64
|
+
filtered_data[offset, limit]
|
65
|
+
end
|
66
|
+
|
67
|
+
def filtered_data
|
68
|
+
filtered_data = data
|
69
|
+
filtered_data = filtered_data.select { |d| d[:active] == active } unless active.nil?
|
70
|
+
|
71
|
+
filtered_data
|
64
72
|
end
|
65
73
|
|
66
74
|
def object_types
|
data/lib/stripe_mock/instance.rb
CHANGED
@@ -49,11 +49,12 @@ module StripeMock
|
|
49
49
|
include StripeMock::RequestHandlers::Payouts
|
50
50
|
include StripeMock::RequestHandlers::EphemeralKey
|
51
51
|
include StripeMock::RequestHandlers::TaxRates
|
52
|
+
include StripeMock::RequestHandlers::Checkout
|
52
53
|
|
53
54
|
attr_reader :accounts, :balance, :balance_transactions, :bank_tokens, :charges, :coupons, :customers,
|
54
55
|
:disputes, :events, :invoices, :invoice_items, :orders, :payment_intents, :payment_methods,
|
55
56
|
:setup_intents, :plans, :recipients, :refunds, :transfers, :payouts, :subscriptions, :country_spec,
|
56
|
-
:subscriptions_items, :products, :tax_rates
|
57
|
+
:subscriptions_items, :products, :tax_rates, :checkout_sessions
|
57
58
|
|
58
59
|
attr_accessor :error_queue, :debug, :conversion_rate, :account_balance
|
59
60
|
|
@@ -85,6 +86,7 @@ module StripeMock
|
|
85
86
|
@subscriptions_items = {}
|
86
87
|
@country_spec = {}
|
87
88
|
@tax_rates = {}
|
89
|
+
@checkout_sessions = {}
|
88
90
|
|
89
91
|
@debug = false
|
90
92
|
@error_queue = ErrorQueue.new
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StripeMock
|
2
|
+
module RequestHandlers
|
3
|
+
module Checkout
|
4
|
+
def Checkout.included(klass)
|
5
|
+
klass.add_handler 'post /v1/checkout/sessions', :new_session
|
6
|
+
end
|
7
|
+
|
8
|
+
def new_session(route, method_url, params, headers)
|
9
|
+
params[:id] ||= new_id('cs')
|
10
|
+
|
11
|
+
checkout_sessions[params[:id]] = Data.mock_checkout_session(params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -29,7 +29,7 @@ module StripeMock
|
|
29
29
|
params[:default_source] = sources.first[:id]
|
30
30
|
end
|
31
31
|
|
32
|
-
customers[
|
32
|
+
customers[params[:id]] = Data.mock_customer(sources, params)
|
33
33
|
|
34
34
|
if params[:plan]
|
35
35
|
plan_id = params[:plan].to_s
|
@@ -48,19 +48,22 @@ module StripeMock
|
|
48
48
|
end
|
49
49
|
|
50
50
|
if params[:coupon]
|
51
|
-
coupon = coupons[
|
51
|
+
coupon = coupons[params[:coupon]]
|
52
52
|
assert_existence :coupon, params[:coupon], coupon
|
53
|
-
|
54
53
|
add_coupon_to_object(customers[params[:id]], coupon)
|
55
54
|
end
|
56
55
|
|
57
|
-
customers[
|
56
|
+
customers[params[:id]]
|
58
57
|
end
|
59
58
|
|
60
59
|
def update_customer(route, method_url, params, headers)
|
61
60
|
route =~ method_url
|
62
61
|
cus = assert_existence :customer, $1, customers[$1]
|
63
62
|
|
63
|
+
# get existing and pending metadata
|
64
|
+
metadata = cus.delete(:metadata) || {}
|
65
|
+
metadata_updates = params.delete(:metadata) || {}
|
66
|
+
|
64
67
|
# Delete those params if their value is nil. Workaround of the problematic way Stripe serialize objects
|
65
68
|
params.delete(:sources) if params[:sources] && params[:sources][:data].nil?
|
66
69
|
params.delete(:subscriptions) if params[:subscriptions] && params[:subscriptions][:data].nil?
|
@@ -72,6 +75,7 @@ module StripeMock
|
|
72
75
|
params.delete(:subscriptions) unless params[:subscriptions][:data].any?{ |v| !!v[:type]}
|
73
76
|
end
|
74
77
|
cus.merge!(params)
|
78
|
+
cus[:metadata] = {**metadata, **metadata_updates}
|
75
79
|
|
76
80
|
if params[:source]
|
77
81
|
if params[:source].is_a?(String)
|
@@ -87,10 +91,14 @@ module StripeMock
|
|
87
91
|
end
|
88
92
|
|
89
93
|
if params[:coupon]
|
90
|
-
|
91
|
-
|
94
|
+
if params[:coupon] == ''
|
95
|
+
delete_coupon_from_object(cus)
|
96
|
+
else
|
97
|
+
coupon = coupons[params[:coupon]]
|
98
|
+
assert_existence :coupon, params[:coupon], coupon
|
92
99
|
|
93
|
-
|
100
|
+
add_coupon_to_object(cus, coupon)
|
101
|
+
end
|
94
102
|
end
|
95
103
|
|
96
104
|
cus
|
@@ -32,7 +32,7 @@ module StripeMock
|
|
32
32
|
start_time = options[:current_period_start] || now
|
33
33
|
params = { customer: cus[:id], current_period_start: start_time, created: created_time }
|
34
34
|
params.merge!({ :plan => (plans.size == 1 ? plans.first : nil) })
|
35
|
-
keys_to_merge = /application_fee_percent|quantity|metadata|tax_percent|billing|days_until_due|default_tax_rates/
|
35
|
+
keys_to_merge = /application_fee_percent|quantity|metadata|tax_percent|billing|days_until_due|default_tax_rates|pending_invoice_item_interval/
|
36
36
|
params.merge! options.select {|k,v| k =~ keys_to_merge}
|
37
37
|
|
38
38
|
if options[:cancel_at_period_end] == true
|
@@ -20,6 +20,7 @@ module StripeMock
|
|
20
20
|
status = case params[:amount]
|
21
21
|
when 3184 then 'requires_action'
|
22
22
|
when 3178 then 'requires_payment_method'
|
23
|
+
when 3055 then 'requires_capture'
|
23
24
|
else
|
24
25
|
'succeeded'
|
25
26
|
end
|
@@ -167,7 +168,13 @@ module StripeMock
|
|
167
168
|
def succeeded_payment_intent(payment_intent)
|
168
169
|
payment_intent[:status] = 'succeeded'
|
169
170
|
btxn = new_balance_transaction('txn', { source: payment_intent[:id] })
|
170
|
-
|
171
|
+
|
172
|
+
payment_intent[:charges][:data] << Data.mock_charge(
|
173
|
+
balance_transaction: btxn,
|
174
|
+
amount: payment_intent[:amount],
|
175
|
+
currency: payment_intent[:currency]
|
176
|
+
)
|
177
|
+
|
171
178
|
payment_intent
|
172
179
|
end
|
173
180
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module StripeMock
|
2
2
|
module RequestHandlers
|
3
3
|
module PaymentMethods
|
4
|
-
|
5
4
|
ALLOWED_PARAMS = [:customer, :type]
|
6
5
|
|
7
6
|
def PaymentMethods.included(klass)
|
@@ -52,26 +51,6 @@ module StripeMock
|
|
52
51
|
|
53
52
|
Data.mock_list_object(clone.values, params)
|
54
53
|
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# params: {:customer=>"test_cus_3"}
|
58
|
-
#
|
59
|
-
def attach_payment_method(route, method_url, params, headers)
|
60
|
-
route =~ method_url
|
61
|
-
id = $1
|
62
|
-
payment_methods[id].merge!(params)
|
63
|
-
payment_methods[id].clone
|
64
|
-
end
|
65
|
-
|
66
|
-
def detach_payment_method(route, method_url, params, headers)
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
def get_payment_method(route, method_url, params, headers)
|
71
|
-
route =~ method_url
|
72
|
-
id = $1
|
73
|
-
assert_existence(:payment_method, $1, payment_methods[id])
|
74
|
-
end
|
75
54
|
|
76
55
|
# post /v1/payment_methods/:id/attach
|
77
56
|
def attach_payment_method(route, method_url, params, headers)
|
@@ -34,7 +34,7 @@ module StripeMock
|
|
34
34
|
|
35
35
|
def list_plans(route, method_url, params, headers)
|
36
36
|
limit = params[:limit] ? params[:limit] : 10
|
37
|
-
Data.mock_list_object(plans.values.first(limit), limit: limit)
|
37
|
+
Data.mock_list_object(plans.values.first(limit), params.merge!(limit: limit))
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -102,7 +102,7 @@ module StripeMock
|
|
102
102
|
customer[:default_source] = new_card[:id]
|
103
103
|
end
|
104
104
|
|
105
|
-
allowed_params = %w(customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates)
|
105
|
+
allowed_params = %w(customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior pending_invoice_item_interval)
|
106
106
|
unknown_params = params.keys - allowed_params.map(&:to_sym)
|
107
107
|
if unknown_params.length > 0
|
108
108
|
raise Stripe::InvalidRequestError.new("Received unknown parameter: #{unknown_params.join}", unknown_params.first.to_s, http_status: 400)
|
data/lib/stripe_mock/version.rb
CHANGED
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(
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Checkout API' do
|
4
|
+
|
5
|
+
it "creates a stripe checkout session" do
|
6
|
+
session = Stripe::Checkout::Session.create({
|
7
|
+
payment_method_types: ['card'],
|
8
|
+
line_items: [{
|
9
|
+
name: 'T-shirt',
|
10
|
+
quantity: 1,
|
11
|
+
amount: 500,
|
12
|
+
currency: 'usd',
|
13
|
+
}],
|
14
|
+
})
|
15
|
+
expect(session.id).to match(/^test_cs/)
|
16
|
+
expect(session.line_items.count).to eq(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -114,7 +114,7 @@ shared_examples 'Customer API' do
|
|
114
114
|
expect(customer.subscriptions.first.customer).to eq(customer.id)
|
115
115
|
end
|
116
116
|
|
117
|
-
it
|
117
|
+
it 'creates a customer with a plan (string/symbol agnostic)' do
|
118
118
|
stripe_helper.create_plan(id: 'silver', product: product.id)
|
119
119
|
|
120
120
|
Stripe::Customer.create(id: 'cust_SLV1', source: gen_card_tk, :plan => 'silver')
|
@@ -135,7 +135,6 @@ shared_examples 'Customer API' do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
context "create customer" do
|
138
|
-
|
139
138
|
it "with a trial when trial_end is set" do
|
140
139
|
plan = stripe_helper.create_plan(id: 'no_trial', product: product.id, amount: 999)
|
141
140
|
trial_end = Time.now.utc.to_i + 3600
|
@@ -195,7 +194,7 @@ shared_examples 'Customer API' do
|
|
195
194
|
expect(customer.subscriptions.first.trial_end).to be_nil
|
196
195
|
end
|
197
196
|
|
198
|
-
it
|
197
|
+
it 'returns an error if trial_end is set to a past time' do
|
199
198
|
plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
|
200
199
|
expect {
|
201
200
|
Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: Time.now.utc.to_i - 3600)
|
@@ -205,7 +204,7 @@ shared_examples 'Customer API' do
|
|
205
204
|
}
|
206
205
|
end
|
207
206
|
|
208
|
-
it
|
207
|
+
it 'returns an error if trial_end is set without a plan' do
|
209
208
|
expect {
|
210
209
|
Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, trial_end: "now")
|
211
210
|
}.to raise_error {|e|
|
@@ -218,7 +217,7 @@ shared_examples 'Customer API' do
|
|
218
217
|
|
219
218
|
it 'cannot create a customer with a plan that does not exist' do
|
220
219
|
expect {
|
221
|
-
|
220
|
+
Stripe::Customer.create(id: 'test_cus_no_plan', source: gen_card_tk, :plan => 'non-existant')
|
222
221
|
}.to raise_error {|e|
|
223
222
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
224
223
|
expect(e.message).to eq('No such plan: non-existant')
|
@@ -228,7 +227,7 @@ shared_examples 'Customer API' do
|
|
228
227
|
it 'cannot create a customer with an existing plan, but no card token' do
|
229
228
|
plan = stripe_helper.create_plan(id: 'p', product: product.id)
|
230
229
|
expect {
|
231
|
-
|
230
|
+
Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
|
232
231
|
}.to raise_error {|e|
|
233
232
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
234
233
|
expect(e.message).to eq('You must supply a valid card')
|
@@ -236,10 +235,9 @@ shared_examples 'Customer API' do
|
|
236
235
|
end
|
237
236
|
|
238
237
|
it 'creates a customer with a coupon discount' do
|
239
|
-
coupon = Stripe::Coupon.create(id:
|
238
|
+
coupon = Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
|
240
239
|
|
241
|
-
|
242
|
-
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
|
240
|
+
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
|
243
241
|
|
244
242
|
customer = Stripe::Customer.retrieve('test_cus_coupon')
|
245
243
|
expect(customer.discount).to_not be_nil
|
@@ -251,25 +249,46 @@ shared_examples 'Customer API' do
|
|
251
249
|
describe 'repeating coupon with duration limit', live: true do
|
252
250
|
let!(:coupon) { stripe_helper.create_coupon(id: '10OFF', amount_off: 1000, currency: 'usd', duration: 'repeating', duration_in_months: 12) }
|
253
251
|
let!(:customer) { Stripe::Customer.create(coupon: coupon.id) }
|
252
|
+
|
254
253
|
it 'creates the discount with the end date', live: true do
|
255
254
|
discount = Stripe::Customer.retrieve(customer.id).discount
|
256
255
|
expect(discount).to_not be_nil
|
257
256
|
expect(discount.coupon).to_not be_nil
|
258
257
|
expect(discount.end).to be_within(10).of (DateTime.now >> 12).to_time.to_i
|
259
258
|
end
|
259
|
+
|
260
260
|
after { Stripe::Coupon.retrieve(coupon.id).delete }
|
261
261
|
after { Stripe::Customer.retrieve(customer.id).delete }
|
262
262
|
end
|
263
263
|
|
264
264
|
it 'cannot create a customer with a coupon that does not exist' do
|
265
265
|
expect{
|
266
|
-
|
266
|
+
Stripe::Customer.create(id: 'test_cus_no_coupon', coupon: '5OFF')
|
267
267
|
}.to raise_error {|e|
|
268
268
|
expect(e).to be_a(Stripe::InvalidRequestError)
|
269
269
|
expect(e.message).to eq('No such coupon: 5OFF')
|
270
270
|
}
|
271
271
|
end
|
272
272
|
|
273
|
+
context 'with coupon on customer' do
|
274
|
+
before do
|
275
|
+
Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
|
276
|
+
Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'remove the coupon from customer' do
|
280
|
+
customer = Stripe::Customer.retrieve('test_cus_coupon')
|
281
|
+
expect(customer.discount).to_not be_nil
|
282
|
+
expect(customer.discount.coupon).to_not be_nil
|
283
|
+
expect(customer.discount.customer).to eq customer.id
|
284
|
+
expect(customer.discount.start).to be_within(1).of Time.now.to_i
|
285
|
+
|
286
|
+
Stripe::Customer.update('test_cus_coupon', coupon: '')
|
287
|
+
customer = Stripe::Customer.retrieve('test_cus_coupon')
|
288
|
+
expect(customer.discount).to be_nil
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
273
292
|
it "stores a created stripe customer in memory" do
|
274
293
|
customer = Stripe::Customer.create({
|
275
294
|
email: 'johnny@appleseed.com',
|
@@ -353,6 +372,15 @@ shared_examples 'Customer API' do
|
|
353
372
|
expect(customer.discount.coupon).to be_a Stripe::Coupon
|
354
373
|
end
|
355
374
|
|
375
|
+
it "preserves stripe customer metadata" do
|
376
|
+
metadata = {user_id: "38"}
|
377
|
+
customer = Stripe::Customer.create(metadata: metadata)
|
378
|
+
expect(customer.metadata.to_h).to eq(metadata)
|
379
|
+
|
380
|
+
updated = Stripe::Customer.update(customer.id, metadata: {fruit: "apples"})
|
381
|
+
expect(updated.metadata.to_h).to eq(metadata.merge(fruit: "apples"))
|
382
|
+
end
|
383
|
+
|
356
384
|
it "retrieves the customer's default source after it was updated" do
|
357
385
|
customer = Stripe::Customer.create()
|
358
386
|
customer.source = gen_card_tk
|
@@ -36,6 +36,16 @@ shared_examples 'PaymentIntent API' do
|
|
36
36
|
expect(payment_intent.last_payment_error.message).to eq('Not enough funds.')
|
37
37
|
end
|
38
38
|
|
39
|
+
it "creates a requires_payment_method stripe payment_intent when amount matches 3055" do
|
40
|
+
payment_intent = Stripe::PaymentIntent.create(amount: 3055, currency: "usd")
|
41
|
+
|
42
|
+
expect(payment_intent.id).to match(/^test_pi/)
|
43
|
+
expect(payment_intent.amount).to eq(3055)
|
44
|
+
expect(payment_intent.currency).to eq('usd')
|
45
|
+
expect(payment_intent.metadata.to_hash).to eq({})
|
46
|
+
expect(payment_intent.status).to eq('requires_capture')
|
47
|
+
end
|
48
|
+
|
39
49
|
describe "listing payment_intent" do
|
40
50
|
before do
|
41
51
|
3.times do
|
@@ -183,6 +183,20 @@ shared_examples 'Customer Subscriptions' do
|
|
183
183
|
expect(subscription.tax_percent).to eq(20)
|
184
184
|
end
|
185
185
|
|
186
|
+
it "correctly sets pending invoice item interval" do
|
187
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)
|
188
|
+
|
189
|
+
subscription = Stripe::Subscription.create({
|
190
|
+
plan: plan.id,
|
191
|
+
customer: customer.id,
|
192
|
+
quantity: 2,
|
193
|
+
pending_invoice_item_interval: { interval: 'month', interval_count: 1 }
|
194
|
+
})
|
195
|
+
|
196
|
+
expect(subscription.pending_invoice_item_interval.interval).to eq 'month'
|
197
|
+
expect(subscription.pending_invoice_item_interval.interval_count).to eq 1
|
198
|
+
end
|
199
|
+
|
186
200
|
it "correctly sets created when it's not provided as a parameter", live: true do
|
187
201
|
customer = Stripe::Customer.create(source: gen_card_tk)
|
188
202
|
subscription = Stripe::Subscription.create({ plan: plan.id, customer: customer.id })
|
@@ -720,6 +734,26 @@ shared_examples 'Customer Subscriptions' do
|
|
720
734
|
expect(sub.canceled_at).to be_falsey
|
721
735
|
end
|
722
736
|
|
737
|
+
it "updates a subscription's pending invoice item interval" do
|
738
|
+
customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)
|
739
|
+
|
740
|
+
subscription = Stripe::Subscription.create({
|
741
|
+
plan: plan.id,
|
742
|
+
customer: customer.id,
|
743
|
+
quantity: 2,
|
744
|
+
pending_invoice_item_interval: { interval: 'month', interval_count: 1 }
|
745
|
+
})
|
746
|
+
|
747
|
+
expect(subscription.pending_invoice_item_interval.interval).to eq 'month'
|
748
|
+
expect(subscription.pending_invoice_item_interval.interval_count).to eq 1
|
749
|
+
|
750
|
+
subscription.pending_invoice_item_interval = { interval: 'week', interval_count: 3 }
|
751
|
+
subscription.save
|
752
|
+
|
753
|
+
expect(subscription.pending_invoice_item_interval.interval).to eq 'week'
|
754
|
+
expect(subscription.pending_invoice_item_interval.interval_count).to eq 3
|
755
|
+
end
|
756
|
+
|
723
757
|
it 'when adds coupon', live: true do
|
724
758
|
coupon = stripe_helper.create_coupon
|
725
759
|
customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
|
@@ -35,6 +35,7 @@ def it_behaves_like_stripe(&block)
|
|
35
35
|
it_behaves_like 'Country Spec API', &block
|
36
36
|
it_behaves_like 'EphemeralKey API', &block
|
37
37
|
it_behaves_like 'TaxRate API', &block
|
38
|
+
it_behaves_like 'Checkout API', &block
|
38
39
|
|
39
40
|
# Integration tests
|
40
41
|
it_behaves_like 'Multiple Customer Cards'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-ruby-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stripe
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- ".gitignore"
|
112
112
|
- ".rspec"
|
113
113
|
- ".travis.yml"
|
114
|
+
- CHANGELOG.md
|
114
115
|
- Gemfile
|
115
116
|
- LICENSE.txt
|
116
117
|
- README.md
|
@@ -146,6 +147,7 @@ files:
|
|
146
147
|
- lib/stripe_mock/request_handlers/balance_transactions.rb
|
147
148
|
- lib/stripe_mock/request_handlers/cards.rb
|
148
149
|
- lib/stripe_mock/request_handlers/charges.rb
|
150
|
+
- lib/stripe_mock/request_handlers/checkout.rb
|
149
151
|
- lib/stripe_mock/request_handlers/country_spec.rb
|
150
152
|
- lib/stripe_mock/request_handlers/coupons.rb
|
151
153
|
- lib/stripe_mock/request_handlers/customers.rb
|
@@ -252,6 +254,7 @@ files:
|
|
252
254
|
- spec/shared_stripe_examples/card_examples.rb
|
253
255
|
- spec/shared_stripe_examples/card_token_examples.rb
|
254
256
|
- spec/shared_stripe_examples/charge_examples.rb
|
257
|
+
- spec/shared_stripe_examples/checkout_examples.rb
|
255
258
|
- spec/shared_stripe_examples/country_specs_examples.rb
|
256
259
|
- spec/shared_stripe_examples/coupon_examples.rb
|
257
260
|
- spec/shared_stripe_examples/customer_examples.rb
|
@@ -327,6 +330,7 @@ test_files:
|
|
327
330
|
- spec/shared_stripe_examples/card_examples.rb
|
328
331
|
- spec/shared_stripe_examples/card_token_examples.rb
|
329
332
|
- spec/shared_stripe_examples/charge_examples.rb
|
333
|
+
- spec/shared_stripe_examples/checkout_examples.rb
|
330
334
|
- spec/shared_stripe_examples/country_specs_examples.rb
|
331
335
|
- spec/shared_stripe_examples/coupon_examples.rb
|
332
336
|
- spec/shared_stripe_examples/customer_examples.rb
|