Skip to content

Commit 0803694

Browse files
authored
Merge pull request #17 from ConvertKit/merge-upstream
Merge upstream/master
2 parents 2052d89 + 501da9e commit 0803694

File tree

115 files changed

+6473
-1421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+6473
-1421
lines changed

.rspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
--colour --format documentation
1+
--colour
2+
--format progress

CHANGELOG.md

+40-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
1-
### 3.0.2 (Next)
1+
### Unreleased
22

3-
* Your contribution here.
4-
* [#715](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/715): Added application_fee_amount to mock charge object - [@espen](https://github.com/espen)
3+
- [#806](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/806) - Remove `payment_method_types` from required arguments for `Stripe::Checkout::Session`
4+
- [#806](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/806) - Raise more helpful exception when Stripe::Price cannot be found within a `Stripe::Checkout::Session` `line_items` argument.
5+
6+
7+
### 3.1.0.rc3 (pre-release 2021-07-14)
8+
9+
- [#785](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/785): `Stripe::Product` no longer requires `type`. [@TastyPi](https://github.com/TastyPi)
10+
- [#784](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/784): Fix "Wrong number of arguments" error in tests. [@TastyPi](https://github.com/TastyPi)
11+
- [#782](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/782): Support expanding `setup_intent` in `Stripe::Checkout::Session`. [@TastyPi](https://github.com/TastyPi)
12+
13+
### 3.1.0.rc2 (pre-release 2021-03-03)
14+
15+
- [#767](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/767): Fixes tests and more [@lpsBetty](https://github.com/lpsBetty)
16+
17+
### 3.1.0.rc1 (pre-release 2021-02-17)
18+
19+
- [#765](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/765): Properly set the status of a trialing subscription. [@csalvato](https://github.com/csalvato)
20+
- [#764](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/764): Fixes erroneous error message when fetching upcoming invoices. [@csalvato](https://github.com/csalvato)
21+
- [#762](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/762): Support Stripe Connect with Customers by adding stripe_account header namespace for customer object [@csalvato](https://github.com/csalvato)
22+
- [#755](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/755): Add allowed params to subscriptions [@dominikdarnel ](https://github.com/dominikdarnel)
23+
- [#748](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/758): Support Prices - [@hidenba](https://github.com/hidenba) and [@jamesprior](https://github.com/jamesprior).
24+
- [#747](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/747/files): Fix ruby 2.7 deprecation warnings. Adds Ruby 3.0.0 compatibility. [@coding-chimp](https://github.com/coding-chimp)
25+
- [#715](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/715): Added application_fee_amount to mock charge object - [@espen](https://github.com/espen)
26+
- [#709](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/709): Remove unnecessary check on customer's currency - [@coorasse](https://github.com/coorasse)
527

628
### 3.0.1 (TBD)
7-
* Added Changelog file
8-
* [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
9-
* [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
10-
* [#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).
11-
* [#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).
12-
* [#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).
13-
* [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
14-
Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
15-
* [#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).
16-
* [#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).
17-
* [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
18-
* [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).
29+
30+
- Added Changelog file
31+
- [#640](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/640): Support Payment Intent status requires_capture - [@theodorton](https://github.com/theodorton).
32+
- [#685](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/685): Adds support for pending_invoice_item_interval - [@joshcass](https://github.com/joshcass).
33+
- [#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).
34+
- [#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).
35+
- [#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).
36+
- [#667](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/667):
37+
Remove empty and duplicated methods from payment methods - [@mnin](https://github.com/mnin).
38+
- [#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).
39+
- [#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).
40+
- [#648](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/648): Initial implementation of checkout session API - [@fauxparse](https://github.com/fauxparse).
41+
- [#644](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/644): Allow payment_behavior attribute on subscription create - [@j15e](https://github.com/j15e).
1942

2043
### 3.0.0 (2019-12-17)
2144

2245
##### the main thing is:
23-
- [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5
46+
47+
- [#658](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/658) Make the gem compatible with Stripe Gem v.5

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ end
88
group :test do
99
gem 'rake'
1010
gem 'pry'
11+
gem 'dotenv'
1112
end
1213

1314
gemspec

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ Patches are welcome and greatly appreciated! If you're contributing to fix a pro
406406
be sure to write tests that illustrate the problem being fixed.
407407
This will help ensure that the problem remains fixed in future updates.
408408

409+
Note: You may need to `ulimit -n 4048` before running the test suite to get all tests to pass.
410+
409411
## Copyright
410412

411413
Copyright (c) 2013 Gilbert

lib/stripe_mock.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
require 'stripe_mock/request_handlers/ephemeral_key.rb'
8080
require 'stripe_mock/request_handlers/products.rb'
8181
require 'stripe_mock/request_handlers/tax_rates.rb'
82-
require 'stripe_mock/request_handlers/checkout.rb'
8382
require 'stripe_mock/request_handlers/checkout_session.rb'
8483
require 'stripe_mock/instance'
8584

@@ -90,12 +89,14 @@
9089
module StripeMock
9190

9291
@default_currency = 'usd'
92+
@checkout_base = "https://checkout.stripe.com/pay/"
9393
lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
9494
@webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
9595
@webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
9696

9797
class << self
9898
attr_accessor :default_currency
99+
attr_accessor :checkout_base
99100
attr_accessor :webhook_fixture_path
100101
end
101102
end

lib/stripe_mock/api/client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def self.start_client(port=4999)
88
return false if @state == 'live'
99
return @client unless @client.nil?
1010

11-
Stripe::StripeClient.send(:define_method, :execute_request) { |*args| StripeMock.redirect_to_mock_server(*args) }
11+
Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| StripeMock.redirect_to_mock_server(*args, **keyword_args) }
1212
@client = StripeMock::Client.new(port)
1313
@state = 'remote'
1414
@client

lib/stripe_mock/api/instance.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module StripeMock
77
def self.start
88
return false if @state == 'live'
99
@instance = instance = Instance.new
10-
Stripe::StripeClient.send(:define_method, :execute_request) { |*args| instance.mock_request(*args) }
10+
Stripe::StripeClient.send(:define_method, :execute_request) { |*args, **keyword_args| instance.mock_request(*args, **keyword_args) }
1111
@state = 'local'
1212
end
1313

lib/stripe_mock/api/webhooks.rb

+62-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def self.mock_webhook_payload(type, params = {})
44

55
fixture_file = File.join(@webhook_fixture_path, "#{type}.json")
66

7-
unless File.exists?(fixture_file)
7+
unless File.exist?(fixture_file)
88
unless Webhooks.event_list.include?(type)
99
raise UnsupportedRequestError.new "Unsupported webhook event `#{type}` (Searched in #{@webhook_fixture_path})"
1010
end
@@ -37,55 +37,91 @@ def self.mock_webhook_event(type, params={})
3737
module Webhooks
3838
def self.event_list
3939
@__list = [
40-
'account.updated',
4140
'account.application.deauthorized',
4241
'account.external_account.created',
43-
'account.external_account.updated',
4442
'account.external_account.deleted',
43+
'account.external_account.updated',
44+
'account.updated',
4545
'balance.available',
46-
'charge.succeeded',
47-
'charge.updated',
48-
'charge.failed',
49-
'charge.refunded',
50-
'charge.dispute.created',
51-
'charge.dispute.updated',
46+
'charge.captured',
5247
'charge.dispute.closed',
48+
'charge.dispute.created',
5349
'charge.dispute.funds_reinstated',
5450
'charge.dispute.funds_withdrawn',
51+
'charge.dispute.updated',
52+
'charge.failed',
53+
'charge.refund.updated',
54+
'charge.refunded',
55+
'charge.succeeded',
56+
'charge.updated',
57+
'checkout.session.completed',
58+
'checkout.session.completed.payment_mode',
59+
'checkout.session.completed.setup_mode',
60+
'coupon.created',
61+
'coupon.deleted',
62+
'customer.created',
63+
'customer.deleted',
64+
'customer.discount.created',
65+
'customer.discount.deleted',
66+
'customer.discount.updated',
5567
'customer.source.created',
5668
'customer.source.deleted',
5769
'customer.source.updated',
58-
'customer.created',
59-
'customer.updated',
60-
'customer.deleted',
6170
'customer.subscription.created',
62-
'customer.subscription.updated',
6371
'customer.subscription.deleted',
6472
'customer.subscription.trial_will_end',
65-
'customer.discount.created',
66-
'customer.discount.updated',
67-
'customer.discount.deleted',
73+
'customer.subscription.updated',
74+
'customer.updated',
6875
'invoice.created',
69-
'invoice.updated',
70-
'invoice.payment_succeeded',
76+
'invoice.finalized',
77+
'invoice.paid',
78+
'invoice.payment_action_required',
7179
'invoice.payment_failed',
80+
'invoice.payment_succeeded',
81+
'invoice.upcoming',
82+
'invoice.updated',
7283
'invoiceitem.created',
73-
'invoiceitem.updated',
7484
'invoiceitem.deleted',
75-
'payment_intent.succeeded',
85+
'invoiceitem.updated',
86+
'mandate.updated',
87+
'payment_intent.amount_capturable_updated',
88+
'payment_intent.canceled',
89+
'payment_intent.created',
7690
'payment_intent.payment_failed',
91+
'payment_intent.processing',
92+
'payment_intent.requires_action',
93+
'payment_intent.succeeded',
94+
'payment_link.created',
95+
'payment_link.updated',
96+
'payment_method.attached',
97+
'payout.created',
98+
'payout.paid',
99+
'payout.updated',
77100
'plan.created',
78-
'plan.updated',
79101
'plan.deleted',
102+
'plan.updated',
103+
'price.created',
104+
'price.deleted',
105+
'price.updated',
80106
'product.created',
81-
'product.updated',
82107
'product.deleted',
83-
'coupon.created',
84-
'coupon.deleted',
108+
'product.updated',
109+
'quote.accepted',
110+
'quote.canceled',
111+
'quote.created',
112+
'quote.finalized',
113+
'setup_intent.canceled',
114+
'setup_intent.created',
115+
'setup_intent.setup_failed',
116+
'setup_intent.succeeded',
117+
'subscription_schedule.canceled',
118+
'subscription_schedule.created',
119+
'subscription_schedule.released',
120+
'subscription_schedule.updated',
85121
'transfer.created',
122+
'transfer.failed',
86123
'transfer.paid',
87-
'transfer.updated',
88-
'transfer.failed'
124+
'transfer.updated'
89125
]
90126
end
91127
end

lib/stripe_mock/client.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def mock_request(method, url, api_key: nil, params: {}, headers: {})
1818
@pipe.mock_request(method, url, api_key: api_key, params: params, headers: headers).tap {|result|
1919
response, api_key = result
2020
if response.is_a?(Hash) && response[:error_raised] == 'invalid_request'
21-
raise Stripe::InvalidRequestError.new(*response[:error_params])
21+
args, keyword_args = response[:error_params].first(2), response[:error_params].last
22+
raise Stripe::InvalidRequestError.new(*args, **keyword_args)
2223
end
2324
}
2425
end

lib/stripe_mock/data.rb

+41-12
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def self.mock_tax_rate(params)
140140

141141
def self.mock_customer(sources, params)
142142
cus_id = params[:id] || "test_cus_default"
143-
currency = params[:currency] || StripeMock.default_currency
143+
currency = params[:currency]
144144
sources.each {|source| source[:customer] = cus_id}
145145
{
146146
@@ -193,8 +193,30 @@ def self.mock_charge(params={})
193193
currency: currency,
194194
destination: nil,
195195
fraud_details: {},
196+
payment_method_details: {
197+
card: {
198+
brand: "visa",
199+
checks: {
200+
address_line1_check: nil,
201+
address_postal_code_check: nil,
202+
cvc_check: "pass"
203+
},
204+
country: "US",
205+
exp_month: 12,
206+
exp_year: 2013,
207+
fingerprint: "3TQGpK9JoY1GgXPw",
208+
funding: "credit",
209+
installments: nil,
210+
last4: "4242",
211+
network: "visa",
212+
three_d_secure: nil,
213+
wallet: nil
214+
},
215+
type: "card"
216+
},
196217
receipt_email: nil,
197218
receipt_number: nil,
219+
receipt_url: nil,
198220
refunded: false,
199221
shipping: {},
200222
statement_descriptor: "Charge #{charge_id}",
@@ -255,7 +277,8 @@ def self.mock_refund(params={})
255277
charge: "ch_4fWhYjzQ23UFWT",
256278
receipt_number: nil,
257279
status: "succeeded",
258-
reason: "requested_by_customer"
280+
reason: "requested_by_customer",
281+
receipt_url: nil
259282
}.merge(params)
260283
end
261284

@@ -365,7 +388,7 @@ def self.mock_subscription(params={})
365388
canceled_at: nil,
366389
collection_method: 'charge_automatically',
367390
ended_at: nil,
368-
start: 1308595038,
391+
start_date: 1308595038,
369392
object: 'subscription',
370393
trial_start: 1308595038,
371394
trial_end: 1308681468,
@@ -1147,13 +1170,12 @@ def self.mock_balance_transaction(params = {})
11471170
end
11481171

11491172
def self.mock_subscription_item(params = {})
1150-
id = params[:id] || 'test_txn_default'
1173+
id = params[:id] || 'test_si_default'
11511174
{
11521175
id: id,
11531176
object: 'subscription_item',
11541177
created: 1504716183,
1155-
metadata: {
1156-
},
1178+
metadata: {},
11571179
plan: {
11581180
id: 'PER_USER_PLAN1',
11591181
object: 'plan',
@@ -1247,19 +1269,26 @@ def self.mock_payment_method(params = {})
12471269
type = params[:type].to_sym
12481270
data = {
12491271
card: {
1250-
brand: 'visa',
1272+
brand: case params.dig(:card, :number)&.to_s
1273+
when /^4/, nil
1274+
'visa'
1275+
when /^5[1-5]/
1276+
'mastercard'
1277+
else
1278+
'unknown'
1279+
end,
12511280
checks: {
12521281
address_line1_check: nil,
12531282
address_postal_code_check: nil,
12541283
cvc_check: 'pass'
12551284
},
12561285
country: 'FR',
1257-
exp_month: 2,
1258-
exp_year: 2022,
1286+
exp_month: params.dig(:card, :exp_month) || 2,
1287+
exp_year: params.dig(:card, :exp_year) || 2022,
12591288
fingerprint: 'Hr3Ly5z5IYxsokWA',
12601289
funding: 'credit',
12611290
generated_from: nil,
1262-
last4: '3155',
1291+
last4: params.dig(:card, :number)&.[](-4..) || '3155',
12631292
three_d_secure_usage: { supported: true },
12641293
wallet: nil
12651294
},
@@ -1274,7 +1303,7 @@ def self.mock_payment_method(params = {})
12741303
branch_code: '',
12751304
country: 'DE',
12761305
fingerprint: 'FD81kbVPe7M05BMj',
1277-
last4: '3000'
1306+
last4: params.dig(:sepa_debit, :iban)&.[](-4..) || '3000'
12781307
}
12791308
}
12801309

@@ -1299,7 +1328,7 @@ def self.mock_payment_method(params = {})
12991328
metadata: {
13001329
order_id: '123456789'
13011330
}
1302-
}.merge(type => data[type]).merge(params)
1331+
}.merge(params).merge(type => data[type])
13031332
end
13041333

13051334
def self.mock_setup_intent(params = {})

0 commit comments

Comments
 (0)