· 9 years ago · Sep 21, 2016, 01:36 PM
1def add_connection(vendor_connection)
2 if self.connections.blank?
3 self.connections.create(
4 scope: vendor_connection.scope,
5 client_id: vendor_connection.client_id,
6 refresh_token: vendor_connection.refresh_token,
7 secret_key: vendor_connection.secret_key,
8 vendor_customer_id: vendor_connection.vendor_customer_id,
9 publishable_key: vendor_connection.publishable_key
10 )
11 AccountSyncJob.perform_later(self) unless self.connections.first.try(:synced)
12 else
13 self.connections.update_attributes!(
14 scope: vendor_connection.scope,
15 client_id: vendor_connection.client_id,
16 refresh_token: vendor_connection.refresh_token,
17 secret_key: vendor_connection.secret_key,
18 vendor_customer_id: vendor_connection.vendor_customer_id,
19 publishable_key: vendor_connection.publishable_key
20 )
21 end
22 end
23
24
25
26
27
28account.add_connection(
29 BraintreeConnection.new(
30 scope: token_params[:scope],
31 client_id: token_params[:client_id],
32 refresh_token: token_params[:refresh_token],
33 secret_key: token_params[:access_token],
34 vendor_customer_id: params[:merchantId],
35 publishable_key: ''
36 )
37 )
38
39
40account.add_connection(
41 StripeConnection.new(
42 scope: token_params[:scope],
43 client_id: token_params[:stripe_client_id],
44 refresh_token: token_params[:refresh_token],
45 secret_key: token_params[:access_token],
46 vendor_customer_id: token_params[:stripe_user_id],
47 publishable_key: token_params[:stripe_publishable_key]
48 )
49 )