Skip to content

Commit 4fee90f

Browse files
Merge pull request stripe-ruby-mock#694 from mnin/master
Introduce ideal and sepa_debit types for PaymentMethod
2 parents a95a612 + add5888 commit 4fee90f

File tree

3 files changed

+393
-94
lines changed

3 files changed

+393
-94
lines changed

lib/stripe_mock/data.rb

+58-23
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,9 @@ def self.mock_balance_transaction(params = {})
10931093
end
10941094

10951095
def self.mock_subscription_item(params = {})
1096-
iid = params[:id] || 'test_txn_default'
1096+
id = params[:id] || 'test_txn_default'
10971097
{
1098-
id: iid,
1098+
id: id,
10991099
object: 'subscription_item',
11001100
created: 1504716183,
11011101
metadata: {
@@ -1188,29 +1188,64 @@ def self.mock_payment_intent(params = {})
11881188
end
11891189

11901190
def self.mock_payment_method(params = {})
1191-
payment_method_id = params[:id] || "pm_1ExEuFL2DI6wht39WNJgbybl"
1192-
{
1193-
id: payment_method_id,
1194-
object: "payment_method",
1195-
type: "card",
1196-
billing_details: {},
1197-
card: {
1198-
brand: "visa",
1199-
checks: { address_line1_check: nil, address_postal_code_check: nil, cvc_check: "pass" },
1200-
country: "FR",
1201-
exp_month: 2,
1202-
exp_year: 2022,
1203-
fingerprint: "Hr3Ly5z5IYxsokWA",
1204-
funding: "credit",
1205-
last4: "3155",
1206-
three_d_secure_usage: { supported: true }
1191+
payment_method_id = params[:id] || 'pm_1ExEuFL2DI6wht39WNJgbybl'
1192+
1193+
type = params[:type].to_sym
1194+
data = {
1195+
card: {
1196+
brand: 'visa',
1197+
checks: {
1198+
address_line1_check: nil,
1199+
address_postal_code_check: nil,
1200+
cvc_check: 'pass'
12071201
},
1208-
customer: params[:customer] || nil,
1209-
metadata: {
1210-
order_id: "123456789"
1211-
}
1202+
country: 'FR',
1203+
exp_month: 2,
1204+
exp_year: 2022,
1205+
fingerprint: 'Hr3Ly5z5IYxsokWA',
1206+
funding: 'credit',
1207+
generated_from: nil,
1208+
last4: '3155',
1209+
three_d_secure_usage: { supported: true },
1210+
wallet: nil
1211+
},
1212+
ideal: {
1213+
bank: 'ing',
1214+
bic: 'INGBNL2A',
1215+
iban_last4: '****',
1216+
verified_name: 'JENNY ROSEN'
1217+
},
1218+
sepa_debit: {
1219+
bank_code: '37040044',
1220+
branch_code: '',
1221+
country: 'DE',
1222+
fingerprint: 'FD81kbVPe7M05BMj',
1223+
last4: '3000'
1224+
}
1225+
}
12121226

1213-
}.merge(params)
1227+
{
1228+
id: payment_method_id,
1229+
object: 'payment_method',
1230+
type: params[:type],
1231+
billing_details: {
1232+
address: {
1233+
city: 'New Orleans',
1234+
country: 'US',
1235+
line1: 'Bourbon Street 23',
1236+
line2: nil,
1237+
postal_code: '10000',
1238+
state: nil
1239+
},
1240+
1241+
name: 'John Dolton',
1242+
phone: nil
1243+
},
1244+
customer: params[:customer] || nil,
1245+
metadata: {
1246+
order_id: '123456789'
1247+
}
1248+
}.merge(type => data[type]).merge(params)
12141249
end
12151250

12161251
def self.mock_setup_intent(params = {})

lib/stripe_mock/request_handlers/payment_methods.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def detach_payment_method(route, method_url, params, headers)
7777

7878
# post /v1/payment_methods/:id
7979
def update_payment_method(route, method_url, params, headers)
80-
allowed_params = [:billing_details, :card, :metadata]
80+
allowed_params = [:billing_details, :card, :ideal, :sepa_debit, :metadata]
8181

8282
id = method_url.match(route)[1]
8383

@@ -103,14 +103,14 @@ def ensure_payment_method_required_params(params)
103103

104104
if invalid_type?(params[:type])
105105
raise Stripe::InvalidRequestError.new(
106-
'Invalid type: must be one of card or card_present',
106+
'Invalid type: must be one of card, ideal or sepa_debit',
107107
http_status: 400
108108
)
109109
end
110110
end
111111

112112
def invalid_type?(type)
113-
!['card', 'card_present'].include?(type)
113+
!%w(card ideal sepa_debit).include?(type)
114114
end
115115
end
116116
end

0 commit comments

Comments
 (0)