Dima_S

Untitled

Sep 20th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.22 KB | None | 0 0
  1. dima@dima-Aspire-ES1-512:~/rails_project/accountdock-rails-master$ git diff
  2. diff --git a/app/controllers/team/home_controller.rb b/app/controllers/team/home_controller.rb
  3. index 06eb213..d7e064d 100644
  4. --- a/app/controllers/team/home_controller.rb
  5. +++ b/app/controllers/team/home_controller.rb
  6. @@ -5,7 +5,7 @@ class Team::HomeController < Team::BaseController
  7.  
  8. @stripeCustomers = current_account.stripe_customers_estimate
  9. @setting = current_account.setting
  10. - @connection = current_account.connections.first
  11. + @connections = current_account.connections
  12.  
  13. # Graphs
  14. @customer_delinquents = current_account.customers.delinquent.group_by_month("customers.updated_at", last: 12, format: "%b %Y").count
  15. diff --git a/app/helpers/team_helper.rb b/app/helpers/team_helper.rb
  16. index 362225e..4754cdf 100644
  17. --- a/app/helpers/team_helper.rb
  18. +++ b/app/helpers/team_helper.rb
  19. @@ -33,7 +33,7 @@ module TeamHelper
  20. disputes_count
  21. end
  22.  
  23. - def vendor_name
  24. - current_account.connections.first.vendor.capitalize
  25. + def vendor_name(connection)
  26. + connection.vendor.capitalize
  27. end
  28. end
  29. diff --git a/app/models/account.rb b/app/models/account.rb
  30. index 5e79c52..4de1172 100644
  31. --- a/app/models/account.rb
  32. +++ b/app/models/account.rb
  33. @@ -131,13 +131,13 @@ class Account < ActiveRecord::Base
  34.  
  35. # Add a Stripe connection
  36. def add_connection(params)
  37. - if self.connections.blank?
  38. + if self.connections.find_by(type: params[BraintreeConnection]).blank?
  39. self.connections.create(params)
  40. # Queue an initial sync of Stripe data to our local DB so Customers, etc show in
  41. # our UI and can be used for queries on expiry, etc.
  42. AccountSyncJob.perform_later(self) unless self.connections.first.try(:synced)
  43. else
  44. - self.connection.update_attributes!(params)
  45. + self.connections.first.update_attributes!(params)
  46. end
  47. end
  48.  
  49. diff --git a/app/services/braintree_services/sync_service.rb b/app/services/braintree_services/sync_service.rb
  50. index ccd1e6f..9e1ee2d 100644
  51. --- a/app/services/braintree_services/sync_service.rb
  52. +++ b/app/services/braintree_services/sync_service.rb
  53. @@ -1,5 +1,7 @@
  54. class BraintreeServices::SyncService < SharedServices::BaseSyncService
  55. +
  56. private
  57. +
  58. def sync_customers
  59. sync_message('Customers')
  60.  
  61. diff --git a/app/views/team/home/index.html.haml b/app/views/team/home/index.html.haml
  62. index ff2b82a..fff9f7b 100644
  63. --- a/app/views/team/home/index.html.haml
  64. +++ b/app/views/team/home/index.html.haml
  65. @@ -24,202 +24,209 @@
  66. .progress.progress-striped.active
  67. .progress-bar.progress-bar-success{'role' => 'progressbar', 'aria-valuenow' => "#{@percentage}", 'aria-valuemin' => '0', 'aria-v
  68. = "#{@percentage} % Complete"
  69. +
  70. %section.setup-steps
  71. .row
  72. - .col-lg-9
  73. - .panel.panel-default
  74. - %a.panel-body
  75. - %i.fa.fa-check.step-complete
  76. - Connect #{vendor_name} account
  77. - %span.label.label-primary
  78. - Authenticated as:
  79. - %strong
  80. - = @setting.display_name
  81. - on #{vendor_name}
  82. - %a.btn.btn-grey.btn-sm.pull-right.step-expand{'data-original' => 'Details'} Details
  83. - .step-content
  84. - %ul.stripe-connected-details
  85. - %li
  86. - %i.fa.fa-eye
  87. - You have granted AccountDock
  88. - %strong #{@connection.scope_in_words}
  89. - access
  90. -
  91. - %li
  92. - %i.fa.fa-users
  93. - Detected
  94. + - @connections.each do |connection|
  95. + .col-lg-9
  96. + .panel.panel-default
  97. + %a.panel-body
  98. + %i.fa.fa-check.step-complete
  99. + Connect #{vendor_name(connection)} account
  100. + %span.label.label-primary
  101. + Authenticated as:
  102. %strong
  103. - = @stripeCustomers
  104. - customers
  105. + = @setting.display_name
  106. + on #{vendor_name(connection)}
  107. + %a.btn.btn-grey.btn-sm.pull-right.step-expand{'data-original' => 'Details'} Details
  108. + .step-content
  109. + %ul.stripe-connected-details
  110. + %li
  111. + %i.fa.fa-eye
  112. + You have granted AccountDock
  113. + %strong #{connection.scope_in_words}
  114. + access
  115. +
  116. + %li
  117. + %i.fa.fa-users
  118. + Detected
  119. + %strong
  120. + = @stripeCustomers
  121. + customers
  122. +
  123. .row
  124. - .col-lg-9
  125. - .panel.panel-default
  126. - %a.panel-body
  127. - - if current_account.synced?
  128. - %i.fa.fa-check.step-complete
  129. - - else
  130. - %i.fa.fa-refresh.step-incomplete
  131. - Synchronizing with #{vendor_name}...
  132. - %a.btn.btn-grey.btn-sm.pull-right.step-expand{'data-original' => 'Details'} Details
  133. - .step-content
  134. - %ul.stripe-connected-details
  135. - %li
  136. - %i.fa.fa-warning
  137. - AccountDock is synchronizing with #{vendor_name} to generate pre-dunning, dunning and dispute notifications. These are confi
  138. + - @connections.each do |connection|
  139. + .col-lg-9
  140. + .panel.panel-default
  141. + %a.panel-body
  142. + - if current_account.synced?
  143. + %i.fa.fa-check.step-complete
  144. + - else
  145. + %i.fa.fa-refresh.step-incomplete
  146. + Synchronizing with #{vendor_name(connection)}...
  147. + %a.btn.btn-grey.btn-sm.pull-right.step-expand{'data-original' => 'Details'} Details
  148. + .step-content
  149. + %ul.stripe-connected-details
  150. + %li
  151. + %i.fa.fa-warning
  152. + AccountDock is synchronizing with #{vendor_name(connection)} to generate pre-dunning, dunning and dispute notifications. T
  153. +
  154. .row
  155. - .col-lg-9
  156. - .panel.panel-default
  157. - %a.panel-body
  158. - - if current_account.installed?
  159. - %i.fa.fa-check.step-complete
  160. - - else
  161. - %i.fa.fa-warning.step-incomplete
  162. - Place embed code in your application
  163. - %a.btn.btn-grey.btn-sm.pull-right.step-expand{'data-original' => 'Instructions'} Instructions
  164. + - @connections.each do |connection|
  165. + .col-lg-9
  166. + .panel.panel-default
  167. + %a.panel-body
  168. + - if current_account.installed?
  169. + %i.fa.fa-check.step-complete
  170. + - else
  171. + %i.fa.fa-warning.step-incomplete
  172. + Place embed code in your application
  173. + %a.btn.btn-grey.btn-sm.pull-right.step-expand{'data-original' => 'Instructions'} Instructions
  174.  
  175. - .step-content.embed-step-content
  176. - %ul.nav.nav-tabs
  177. - %li.active{:role => 'presentation'}
  178. - = link_to 'Modal/Window Button', '#modal-window-embed', {'aria-controls' => 'home', :role => 'tab', 'data-toggle' => 'tab'}
  179. - %li{:role => 'presentation'}
  180. - = link_to 'Inline', '#inline-embed', {'aria-controls' => 'profile', :role => 'tab', 'data-toggle' => 'tab'}
  181. - .tab-content
  182. - .tab-pane.active#modal-window-embed{:role => 'tabpanel'}
  183. - %h3
  184. - Modal/Window Button
  185. - = link_to team_customization_path, class: 'customize-link' do
  186. - %i.fa.fa-paint-brush
  187. - Customize
  188. - %ol.quick-setup-steps.circles-list
  189. - %li
  190. - Place the AccountDock script after jQuery is loaded on your page.
  191. - .highlight
  192. - %pre
  193. - %code.language-html{'data-lang' => "html"}
  194. - = preserve do
  195. - :escaped
  196. - <script src="https://static.accountdock.com/app.min.js"></script>
  197. - %li
  198. - Place the following code into your javascript file or on the page where you'd like the AccountDock button to appear. (No
  199. - .highlight
  200. - %pre
  201. - %code.language-html{'data-lang' => "html"}
  202. - = preserve do
  203. - :escaped
  204. - <script type="text/javascript">
  205. - var handler = AccountDock.configure({
  206. - key: '#{current_account.public_key}',
  207. - customer: 'YOUR_STRIPE_CUSTOMER_ID'
  208. - });
  209. - $(function(){
  210. - $('#billing').on(
  211. - 'click',
  212. - function(event) {
  213. - event.preventDefault();
  214. - handler.open();
  215. - }
  216. - );
  217. - });
  218. - </script>
  219. + .step-content.embed-step-content
  220. + %ul.nav.nav-tabs
  221. + %li.active{:role => 'presentation'}
  222. + = link_to 'Modal/Window Button', '#modal-window-embed', {'aria-controls' => 'home', :role => 'tab', 'data-toggle' => 'tab'
  223. + %li{:role => 'presentation'}
  224. + = link_to 'Inline', '#inline-embed', {'aria-controls' => 'profile', :role => 'tab', 'data-toggle' => 'tab'}
  225. + .tab-content
  226. + .tab-pane.active#modal-window-embed{:role => 'tabpanel'}
  227. + %h3
  228. + Modal/Window Button
  229. + = link_to team_customization_path, class: 'customize-link' do
  230. + %i.fa.fa-paint-brush
  231. + Customize
  232. + %ol.quick-setup-steps.circles-list
  233. %li
  234. - Wherever you want the billing history button to appear on the page, add the markup that will trigger AccountDock to ap
  235. + Place the AccountDock script after jQuery is loaded on your page.
  236. .highlight
  237. %pre
  238. %code.language-html{'data-lang' => "html"}
  239. = preserve do
  240. :escaped
  241. - <button id="billing">View Billing</button>
  242. + <script src="https://static.accountdock.com/app.min.js"></script>
  243. + %li
  244. + Place the following code into your javascript file or on the page where you'd like the AccountDock button to appear. (
  245. + .highlight
  246. + %pre
  247. + %code.language-html{'data-lang' => "html"}
  248. + = preserve do
  249. + :escaped
  250. + <script type="text/javascript">
  251. + var handler = AccountDock.configure({
  252. + key: '#{current_account.public_key}',
  253. + customer: 'YOUR_STRIPE_CUSTOMER_ID'
  254. + });
  255. + $(function(){
  256. + $('#billing').on(
  257. + 'click',
  258. + function(event) {
  259. + event.preventDefault();
  260. + handler.open();
  261. + }
  262. + );
  263. + });
  264. + </script>
  265. + %li
  266. + Wherever you want the billing history button to appear on the page, add the markup that will trigger AccountDock to
  267. + .highlight
  268. + %pre
  269. + %code.language-html{'data-lang' => "html"}
  270. + = preserve do
  271. + :escaped
  272. + <button id="billing">View Billing</button>
  273. +
  274. + %p{style: "color: #74c274;"}
  275. + %strong>Note:</strong>
  276. + Email receipt notifications are off by default. To enable them, visit the customizations area
  277. + .tab-pane#inline-embed{:role => 'tabpanel'}
  278. + %h3
  279. + Inline Embed
  280. + = link_to team_customization_path, class: 'customize-link' do
  281. + %i.fa.fa-paint-brush
  282. + Customize
  283. + %ol.quick-setup-steps.circles-list
  284. + %li
  285. + Place the AccountDock script after jQuery is loaded on your page.
  286. + .highlight
  287. + %pre
  288. + %code.language-html{'data-lang' => "html"}
  289. + = preserve do
  290. + :escaped
  291. + <script src="https://static.accountdock.com/app.min.js"></script>
  292. + %li
  293. + Place the following code into your javascript file or on the page where you'd like the AccountDock button to appear. (
  294. + .highlight
  295. + %pre
  296. + %code.language-html{'data-lang' => "html"}
  297. + =preserve do
  298. + :escaped
  299. + <script type="text/javascript">
  300. + var handler = AccountDock.configure({
  301. + key: '#{current_account.public_key}',
  302. + customer: 'YOUR_STRIPE_CUSTOMER_ID'
  303. + });
  304. + $(function() {
  305. + handler.open({
  306. + container: '#inlineBillingWrapper'
  307. + });
  308. + });
  309. + </script>
  310. + %li
  311. + Wherever you want the billing history widget to appear on the page, add a container with the appropriate ID.
  312. + .highlight
  313. + %pre
  314. + %code.language-html{'data-lang' => "html"}
  315. + =preserve do
  316. + :escaped
  317. + <div id="inlineBillingWrapper"></div>
  318. + %br
  319. + %em Optionally
  320. + , add in default styles for the container while the application loads:
  321. + .highlight
  322. + %pre
  323. + %code.language-html{'data-lang' => "html"}
  324. + =preserve do
  325. + :escaped
  326. + #inlineBillingWrapper {
  327. + border: 1px solid #e0e0e0;
  328. + max-width: 940px;
  329. + box-sizing: content-box;
  330. + background-image: url('//i.imgur.com/uM2gq.gif');
  331. + background-position: center center;
  332. + background-repeat: no-repeat;
  333. + min-height: 100px;
  334. + background-color: #fff;
  335. + }
  336.  
  337. %p{style: "color: #74c274;"}
  338. %strong>Note:</strong>
  339. Email receipt notifications are off by default. To enable them, visit the customizations area
  340. - .tab-pane#inline-embed{:role => 'tabpanel'}
  341. - %h3
  342. - Inline Embed
  343. - = link_to team_customization_path, class: 'customize-link' do
  344. - %i.fa.fa-paint-brush
  345. - Customize
  346. - %ol.quick-setup-steps.circles-list
  347. - %li
  348. - Place the AccountDock script after jQuery is loaded on your page.
  349. - .highlight
  350. - %pre
  351. - %code.language-html{'data-lang' => "html"}
  352. - = preserve do
  353. - :escaped
  354. - <script src="https://static.accountdock.com/app.min.js"></script>
  355. - %li
  356. - Place the following code into your javascript file or on the page where you'd like the AccountDock button to appear. (No
  357. - .highlight
  358. - %pre
  359. - %code.language-html{'data-lang' => "html"}
  360. - =preserve do
  361. - :escaped
  362. - <script type="text/javascript">
  363. - var handler = AccountDock.configure({
  364. - key: '#{current_account.public_key}',
  365. - customer: 'YOUR_STRIPE_CUSTOMER_ID'
  366. - });
  367. - $(function() {
  368. - handler.open({
  369. - container: '#inlineBillingWrapper'
  370. - });
  371. - });
  372. - </script>
  373. - %li
  374. - Wherever you want the billing history widget to appear on the page, add a container with the appropriate ID.
  375. - .highlight
  376. - %pre
  377. - %code.language-html{'data-lang' => "html"}
  378. - =preserve do
  379. - :escaped
  380. - <div id="inlineBillingWrapper"></div>
  381. - %br
  382. - %em Optionally
  383. - , add in default styles for the container while the application loads:
  384. - .highlight
  385. - %pre
  386. - %code.language-html{'data-lang' => "html"}
  387. - =preserve do
  388. - :escaped
  389. - #inlineBillingWrapper {
  390. - border: 1px solid #e0e0e0;
  391. - max-width: 940px;
  392. - box-sizing: content-box;
  393. - background-image: url('//i.imgur.com/uM2gq.gif');
  394. - background-position: center center;
  395. - background-repeat: no-repeat;
  396. - min-height: 100px;
  397. - background-color: #fff;
  398. - }
  399. -
  400. - %p{style: "color: #74c274;"}
  401. - %strong>Note:</strong>
  402. - Email receipt notifications are off by default. To enable them, visit the customizations area
  403.  
  404. %p
  405. %strong Not quite ready to embed in your application?
  406. Check out the #{link_to 'customers', team_customers_path} page to see what your customers will see.
  407. %section.action-items
  408. .row
  409. - .col-lg-9
  410. - .panel.panel-default
  411. - %i.fa.fa-warning.step-incomplete
  412. - %div
  413. - %p These items require your attention:
  414. - %ul
  415. - - if current_account.customers.delinquent.count > 0
  416. - %li You have #{link_to "#{current_account.customers.delinquent.count} / #{current_account.customers.count} customers", team_
  417. - - if current_account.customers.missing_email.count > 0
  418. - %li You have #{link_to "#{current_account.customers.missing_email.count} / #{current_account.customers.count} customers", te
  419. - - if current_account.disputes.opened.count > 0
  420. - %li
  421. - You have #{link_to "#{current_account.disputes.opened.count} / #{current_account.disputes_count} disputes", team_disputes_
  422. - - if current_account.disputes_count > 0
  423. - %p
  424. - - group_disputes_for_count(current_account).each do |status, count|
  425. - -if count > 0
  426. - %span.label.label-primary #{status} : #{count}
  427. + - @connections.each do |connection|
  428. + .col-lg-9
  429. + .panel.panel-default
  430. + %i.fa.fa-warning.step-incomplete
  431. + %div
  432. + %p These items require your attention:
  433. + %ul
  434. + - if current_account.customers.delinquent.count > 0
  435. + %li You have #{link_to "#{current_account.customers.delinquent.count} / #{current_account.customers.count} customers", tea
  436. + - if current_account.customers.missing_email.count > 0
  437. + %li You have #{link_to "#{current_account.customers.missing_email.count} / #{current_account.customers.count} customers",
  438. + - if current_account.disputes.opened.count > 0
  439. + %li
  440. + You have #{link_to "#{current_account.disputes.opened.count} / #{current_account.disputes_count} disputes", team_dispute
  441. + - if current_account.disputes_count > 0
  442. + %p
  443. + - group_disputes_for_count(current_account).each do |status, count|
  444. + -if count > 0
  445. + %span.label.label-primary #{status} : #{count}
  446. %section.charts
  447. .row
  448. .col-lg-9
  449. diff --git a/lib/stripe_client.rb b/lib/stripe_client.rb
  450. index 5d20dac..82014f3 100644
  451. --- a/lib/stripe_client.rb
  452. +++ b/lib/stripe_client.rb
  453. @@ -83,7 +83,7 @@ class StripeClient
  454. customer.save
  455. end
  456.  
  457. - def create_subscription_for_plan (customer_id, plan_id)
  458. + def create_subscription_for_plan(customer_id, plan_id)
  459. customer = self.customer(customer_id)
  460. customer.subscriptions.create({plan: plan_id})
  461. end
  462. @@ -95,7 +95,8 @@ class StripeClient
  463. end
  464.  
  465. private
  466. - def client
  467. +
  468. + def self.client
  469. @client ||= OAuth2::Client.new(
  470. config[:stripe_client_id],
  471. config[:stripe_api_key],
  472. @@ -107,7 +108,7 @@ class StripeClient
  473. ).auth_code
  474. end
  475.  
  476. - def self.config(name)
  477. - Rails.application.secrets[name]
  478. + def self.config
  479. + Rails.application.secrets
  480. end
  481. end
Advertisement
Add Comment
Please, Sign In to add comment