Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dima@dima-Aspire-ES1-512:~/rails_project/accountdock-rails-30-09$ git diff
- diff --git a/app/controllers/direct/base_controller.rb b/app/controllers/direct/base_controller.rb
- index 4511afd..74744f5 100644
- --- a/app/controllers/direct/base_controller.rb
- +++ b/app/controllers/direct/base_controller.rb
- @@ -27,8 +27,8 @@ class Direct::BaseController < ApplicationController
- def fetch_account
- account_public_key = params[:direct_id] || params[:key] # Last is legacy
- @account = Account.find_by_public_key(account_public_key)
- - raise "Can't find the account" if @account.nil? or !@account.connection.present?
- - @account.update_attribute(:installed, true) unless @account.installed?
- + raise "Can't find the account" if @account.nil? or @account.connections.find_by(type: 'StripeConnection').nil?
- + @account.connections.find_by(type: 'StripeConnection').update_attribute(:installed, true) unless @account.connections.find_by(type: 'StripeConnection').installed?
- end
- # The main purpose of this modal HTML is to show in
- # someone else's website in an IFrame. So have to relax
- diff --git a/app/controllers/direct/settings_controller.rb b/app/controllers/direct/settings_controller.rb
- index 543440a..37aaf18 100644
- --- a/app/controllers/direct/settings_controller.rb
- +++ b/app/controllers/direct/settings_controller.rb
- @@ -1,6 +1,6 @@
- class Direct::SettingsController < Direct::BaseController
- def index
- - @customer = @account.customers.find_by_stripe_customer_id(params[:customer_id])
- + @customer = @account.customers.find_by_vendor_customer_id(params[:customer_id])
- raise "Can't find the customer" if @customer.nil?
- render layout: false
- @@ -8,7 +8,7 @@ class Direct::SettingsController < Direct::BaseController
- def create
- unless @account.is_demo?
- - @customer = @account.customers.find_by_stripe_customer_id(params[:customer_id])
- + @customer = @account.customers.find_by_vendor_customer_id(params[:customer_id])
- raise "Can't find the customer" if @customer.nil?
- settings = settings_params
- diff --git a/app/controllers/direct/transactions_controller.rb b/app/controllers/direct/transactions_controller.rb
- index 4ba46e6..402064d 100644
- --- a/app/controllers/direct/transactions_controller.rb
- +++ b/app/controllers/direct/transactions_controller.rb
- @@ -1,6 +1,6 @@
- class Direct::TransactionsController < Direct::BaseController
- def index
- - @customer = @account.customers.find_by_stripe_customer_id(params[:customer_id])
- + @customer = @account.customers.find_by_vendor_customer_id(params[:customer_id])
- raise "Can't find the customer" if @customer.nil?
- # TODO: This was in the PHP javascript code to pass in timezone.
- @@ -13,7 +13,7 @@ class Direct::TransactionsController < Direct::BaseController
- @collection.sort! {|a, b| b.created_at <=> a.created_at}
- begin
- - @upcoming_invoice = @account.stripe.upcoming_invoice(@customer.stripe_customer_id)
- + @upcoming_invoice = @account.client.upcoming_invoice(@customer.vendor_customer_id)
- rescue => e
- end
- diff --git a/app/controllers/stripe_controller.rb b/app/controllers/stripe_controller.rb
- index 91b8d7d..1f899eb 100644
- --- a/app/controllers/stripe_controller.rb
- +++ b/app/controllers/stripe_controller.rb
- @@ -18,6 +18,7 @@ class StripeController < ApplicationController
- if account.new_record?
- #generate Account
- + binding.pry
- account.set_handle(stripe_account.display_name || stripe_account.email[/[^@]+/])
- if account.valid?
- account.save
- diff --git a/app/controllers/team/connection_controller.rb b/app/controllers/team/connection_controller.rb
- index 88d764c..0716cee 100644
- --- a/app/controllers/team/connection_controller.rb
- +++ b/app/controllers/team/connection_controller.rb
- @@ -4,6 +4,7 @@ class Team::ConnectionController < ApplicationController
- end
- def switch
- +binding.pry
- account = current_user.accounts.find_by_public_key(params[:public_key])
- not_found if account.nil?
- diff --git a/app/models/account.rb b/app/models/account.rb
- index 4023555..7a1ba0a 100644
- --- a/app/models/account.rb
- +++ b/app/models/account.rb
- @@ -112,7 +112,7 @@ class Account < ActiveRecord::Base
- # Is there a Vendor connection?
- def has_connection?
- - self.connections.present?
- + self.connections.braintree_connection.present? && self.connections.stripe_connection.present?
- end
- # Vendor Accessors
- diff --git a/app/models/account_stripe_event.rb b/app/models/account_stripe_event.rb
- index f7506b5..adb4b7f 100644
- --- a/app/models/account_stripe_event.rb
- +++ b/app/models/account_stripe_event.rb
- @@ -53,7 +53,7 @@ class AccountStripeEvent < ActiveRecord::Base
- case event.type
- # Customers
- when 'customer.created', 'customer.updated' # Includes updating default card
- - account.sync_stripe_customer(event.data.object)
- + account.sync_customer(event.data.object)
- when 'customer.deleted'
- account.connections.stripe_connection.remove_customer(event.data.object)
- # TODO: Remove this OLD API shiz when we upgrade the Stripe API:
- diff --git a/app/models/connections/braintree_connection.rb b/app/models/connections/braintree_connection.rb
- index 8c176ff..cb8858c 100644
- --- a/app/models/connections/braintree_connection.rb
- +++ b/app/models/connections/braintree_connection.rb
- @@ -36,8 +36,8 @@ class BraintreeConnection < Connection
- end
- def braintree(account)
- - @braintree ||= BraintreeClient.new(account.connections.braintree_connection.try(:secret_key))
- - @account = account
- + return @braintree ||= BraintreeClient.new(account.connections.braintree_connection.try(:secret_key))
- + # @account = account
- end
- def vendor
- diff --git a/app/models/connections/stripe_connection.rb b/app/models/connections/stripe_connection.rb
- index e31e387..e5ccbe4 100644
- --- a/app/models/connections/stripe_connection.rb
- +++ b/app/models/connections/stripe_connection.rb
- @@ -37,7 +37,7 @@ class StripeConnection < Connection
- def stripe(account)
- @stripe ||= StripeClient.new(account.connections.stripe_connection.try(:secret_key))
- - @account = account
- + # @account = account
- end
- def vendor
- diff --git a/app/services/braintree_services/sync_service.rb b/app/services/braintree_services/sync_service.rb
- index 6a9a16c..aeb7fab 100644
- --- a/app/services/braintree_services/sync_service.rb
- +++ b/app/services/braintree_services/sync_service.rb
- @@ -1,10 +1,11 @@
- class BraintreeServices::SyncService < SharedServices::BaseSyncService
- private
- def sync_customers
- +
- sync_message("Customers")
- updated_customers = []
- - braintree_customers = Braintree::Gateway.new(access_token: @account.connections.braintree_connection.secret_key).customer.all.ids
- + braintree_customers = @account.connections.braintree_connection.braintree(@account).customers.all.ids
- braintree_customers.each do |customer|
- updated_customers << customer
- sync_braintree_customer(customer)
- @@ -42,7 +43,17 @@ class BraintreeServices::SyncService < SharedServices::BaseSyncService
- if braintree_customer.try(:deleted)
- customer.update_attributes({ deleted: true, live: livemode? })
- else
- - customer.assign_attributes({ })
- + customer.assign_attributes({
- + email: braintree_customer.email.try(:delete, "\000"),
- + default_source: default_card(braintree_customer),
- + # description: braintree_customer.description || '',
- + # metadata_raw: braintree_customer.metadata.to_json,
- + live: Braintree::Configuration.environment.to_s == 'production',
- + # account_balance: braintree_customer.account_balance,
- + # currency: braintree_customer.currency,
- + # business_vat_id: braintree_customer.try(:business_vat_id),
- + created_at: Time.at(braintree_customer.created)
- + })
- customer.save!
- end
- customer
- @@ -51,4 +62,12 @@ class BraintreeServices::SyncService < SharedServices::BaseSyncService
- retry unless (attempts -= 1).zero?
- raise ex
- end
- +
- + def default_card(customer)
- + customer.payment_methods.each do |payment_methods|
- + if payment_methods.default?
- + return payment_methods.token
- + end
- + end
- + end
- end
- diff --git a/app/services/stripe_services/sync_service.rb b/app/services/stripe_services/sync_service.rb
- index 28582db..2cf2bb0 100644
- --- a/app/services/stripe_services/sync_service.rb
- +++ b/app/services/stripe_services/sync_service.rb
- @@ -1,7 +1,6 @@
- class StripeServices::SyncService < SharedServices::BaseSyncService
- - private
- + # private
- def sync_customers
- - byebug
- sync_message('Customers')
- updated_customers = []
- options = {limit: 100}
- @@ -13,7 +12,7 @@ class StripeServices::SyncService < SharedServices::BaseSyncService
- end
- end
- # This marks historic data from AccountDock PHP... future webhooks should do this
- - @account.customers.where.not(stripe_customer_id: updated_customers).update_all(deleted: true)
- + @account.customers.where.not(vendor_customer_id: updated_customers).update_all(deleted: true)
- # Theoretically this isn't necessary (we should only have added new)
- unless @account.customers.count == @account.customers_count
- puts "Customer Cache varied by #{@account.customers_count - @account.customers.count}."
- @@ -85,7 +84,7 @@ class StripeServices::SyncService < SharedServices::BaseSyncService
- def sync_stripe_customer(stripe_customer)
- attempts ||= 2
- - customer = @account.customers.where(stripe_customer_id: stripe_customer.id).first_or_initialize
- + customer = @account.customers.where(vendor_customer_id: stripe_customer.id).first_or_initialize
- # Note stripe can give us a neutered version of a customer if the customer has been
- # deleted. It looks like: #<Stripe::Customer:0x3f id=cus_3cT> JSON: { "id": "cus_3cT", "deleted": true }
- if stripe_customer.try(:deleted) # Non-deleted customers, don't even respond to deleted.
- @@ -136,7 +135,7 @@ class StripeServices::SyncService < SharedServices::BaseSyncService
- def sync_cards(customer, default_source = '')
- updated_cards = []
- options = {limit: 100}
- - while (stripe_cards = @account.connections.stripe_connection.cards(customer.stripe_customer_id, options).to_a).any?
- + while (stripe_cards = @account.connections.stripe_connection.cards(customer.vendor_customer_id, options).to_a).any?
- options[:starting_after] = stripe_cards.last.id
- stripe_cards.each do |cc|
- updated_cards << cc.id # Store the stripe ID for cleaning below
- diff --git a/app/views/direct/base/app.html.haml b/app/views/direct/base/app.html.haml
- index a57edb7..d5c4f37 100644
- --- a/app/views/direct/base/app.html.haml
- +++ b/app/views/direct/base/app.html.haml
- @@ -7,8 +7,8 @@
- = javascript_include_tag '//api.filestackapi.com/filestack.js', 'application', 'angular'
- :javascript
- var app = angular.module('app', [])
- - .constant('TRAN', "#{direct_customer_transactions_path(@account.public_key, @customer.stripe_customer_id, format: :json)}")
- - .constant('SETTING', "#{direct_customer_settings_path(@account.public_key, @customer.stripe_customer_id, format: :json)}")
- + .constant('TRAN', "#{direct_customer_transactions_path(@account.public_key, @customer.vendor_customer_id, format: :json)}")
- + .constant('SETTING', "#{direct_customer_settings_path(@account.public_key, @customer.vendor_customer_id, format: :json)}")
- .constant('BULK', {email: "#{charges_bulk_email_path(key: @account.public_key, format: :json)}", zip: "#{charges_bulk_zip_url(key: @account.public_key)}"})
- .constant('EMAIL', "#{@customer.email}")
- .constant('DISPLAY_NAME', "#{@account.setting.email_sender_display_name}")
- diff --git a/app/views/direct/modals/_settings.html.haml b/app/views/direct/modals/_settings.html.haml
- index 6bb332b..655a7e5 100644
- --- a/app/views/direct/modals/_settings.html.haml
- +++ b/app/views/direct/modals/_settings.html.haml
- @@ -4,7 +4,7 @@
- %div
- %header Receipt Settings
- %a.closeBtn.fa.fa-close{href: '#', 'ng-click'=>"closeModal('settings')"}
- - = form_tag direct_customer_settings_path(direct_id: @account.public_key, customer_id: @customer.stripe_customer_id, format: :json), remote: true, role: 'form' do
- + = form_tag direct_customer_settings_path(direct_id: @account.public_key, customer_id: @customer.vendor_customer_id, format: :json), remote: true, role: 'form' do
- .body
- .columns.clearfix
- .column
- diff --git a/lib/braintree_client.rb b/lib/braintree_client.rb
- index 18ffd6b..0a871d8 100644
- --- a/lib/braintree_client.rb
- +++ b/lib/braintree_client.rb
- @@ -27,12 +27,17 @@ class BraintreeClient
- [:customer].each do |m|
- braintree_class = "Braintree::#{m.capitalize}".constantize
- + # BraintreeClient.oauth_gateway
- define_method(m) do |*opts|
- - braintree_class.find(*opts, @access_token)
- + braintree_class.find(*opts)
- end
- define_method(m.to_s.pluralize) do |opts={}|
- - default_options = { limit: 100 }
- - braintree_class.all(default_options.merge(opts), @access_token)
- + # default_options = { limit: 100 }
- + bt_customers = []
- + braintree_class.all.ids.each do |bt_customer|
- + bt_customers << Braintree::Customer.find(bt_customer)
- + end
- + return bt_customers
- end
- # TODO
- define_method("#{m.to_s.pluralize}_count") do
- @@ -104,7 +109,7 @@ class BraintreeClient
- @gateway ||= Braintree::Gateway.new({
- client_id: config[:client_id],
- client_secret: config[:client_secret],
- - client_public: config[:client_public],
- + # client_public: config[:client_public],
- environment: config[:environment]
- }).oauth
- end
Advertisement
Add Comment
Please, Sign In to add comment