Skip to content

Commit 67a2d2a

Browse files
committed
Improve checkout_session
1 parent 1f8362e commit 67a2d2a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Unreleased
2+
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+
17
### 3.1.0.rc3 (pre-release 2021-07-14)
28

39
- [#785](https://github.com/stripe-ruby-mock/stripe-ruby-mock/pull/785): `Stripe::Product` no longer requires `type`. [@TastyPi](https://github.com/TastyPi)

lib/stripe_mock/request_handlers/checkout_session.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def Session.included(klass)
1212
def new_session(route, method_url, params, headers)
1313
id = params[:id] || new_id('cs')
1414

15-
[:cancel_url, :payment_method_types, :success_url].each do |p|
15+
[:cancel_url, :success_url].each do |p|
1616
require_param(p) if params[p].nil? || params[p].empty?
1717
end
1818

@@ -46,7 +46,18 @@ def new_session(route, method_url, params, headers)
4646
amount = nil
4747
currency = nil
4848
if line_items
49-
amount = line_items.map { |line_item| prices[line_item[:price]][:unit_amount] * line_item[:quantity] }.sum
49+
amount = 0
50+
51+
line_items.each do |line_item|
52+
price = prices[line_item[:price]]
53+
54+
if price.nil?
55+
raise StripeMock::StripeMockError.new("Price not found for ID: #{line_item[:price]}")
56+
end
57+
58+
amount += (price[:unit_amount] * line_item[:quantity])
59+
end
60+
5061
currency = prices[line_items.first[:price]][:currency]
5162
end
5263

@@ -143,6 +154,11 @@ def list_line_items(route, method_url, params, headers)
143154
line_items = assert_existence :checkout_session_line_items, $1, checkout_session_line_items[$1]
144155
line_items.map do |line_item|
145156
price = prices[line_item[:price]].clone
157+
158+
if price.nil?
159+
raise StripeMock::StripeMockError.new("Price not found for ID: #{line_item[:price]}")
160+
end
161+
146162
{
147163
id: line_item[:id],
148164
object: "item",

0 commit comments

Comments
 (0)