7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/stripe/models/payment_method.rb', line 7
def self.from_response(kb_account_id, kb_payment_method_id, kb_tenant_id, cc_or_token, response, options, = {:source_type => "cc"}, model = ::Killbill::Stripe::StripePaymentMethod)
stripe_customer_id = options[:customer] || self.stripe_customer_id_from_kb_account_id(kb_account_id, kb_tenant_id)
if response.params["bank_account"]
= {} payment_response = {
"token" => response.params["bank_account"]["id"],
"address_country" => response.params["bank_account"]["country"],
}
customer_response = { "id" => stripe_customer_id }
[:bank_name] = response.params["bank_account"]["bank_name"]
[:bank_routing_number] = response.params["bank_account"]["routing_number"]
[:source_type] = "bank_account"
cc_or_token ||= response.params["bank_account"]["id"]
elsif !stripe_customer_id.blank? && response.respond_to?(:responses)
payment_response = response.responses.first.params
customer_response = response.responses.last.params
elsif response.params['sources']
payment_response = response.params['sources']['data'][0]
customer_response = response.params
if response.params['sources']['data'][0]["object"] == "bank_account"
[:bank_name] = response.params["sources"]["data"][0]["bank_name"]
[:bank_routing_number] = response.params["sources"]["data"][0]["routing_number"]
[:source_type] = "bank_account"
end
else
payment_response = {}
customer_response = { 'id' => stripe_customer_id }
end
super(kb_account_id,
kb_payment_method_id,
kb_tenant_id,
cc_or_token,
response,
options,
{
:stripe_customer_id => customer_response['id'],
:token => payment_response['id'],
:cc_first_name => payment_response['name'],
:cc_last_name => nil,
:cc_type => payment_response['brand'],
:cc_exp_month => payment_response['exp_month'],
:cc_exp_year => payment_response['exp_year'],
:cc_last_4 => payment_response['last4'],
:address1 => payment_response['address_line1'],
:address2 => payment_response['address_line2'],
:city => payment_response['address_city'],
:state => payment_response['address_state'],
:zip => payment_response['address_zip'],
:country => payment_response['address_country']
}.merge!(.compact), model)
end
|