Class: Spree::Admin::BankAccountsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Admin::BankAccountsController
- Defined in:
- app/controllers/spree/admin/bank_accounts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
-
#sync ⇒ Object
Never builds and holds a plan across the request:
apply!with no argument derives and validates the plan itself, including the abort guard against a provider auth failure returning[](whichplanwould otherwise read as "every account disappeared" and deactivate all of them). - #toggle_offered ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 15 def create @bank_account = @payment_method.bank_accounts.new(bank_account_params) if @bank_account.save redirect_to_index 'Bank account created.' else render :new end rescue JSON::ParserError @bank_account = @payment_method.bank_accounts.new(raw_bank_account_params.except(:details)) @bank_account.errors.add(:details, 'must contain valid JSON') render :new end |
#destroy ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 53 def destroy if @bank_account.synced? flash[:error] = 'Synced accounts cannot be deleted. Deactivate instead.' else @bank_account.destroy end redirect_to_index end |
#edit ⇒ Object
29 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 29 def edit; end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 7 def index @bank_accounts = @payment_method.bank_accounts.order(:currency, :id) end |
#new ⇒ Object
11 12 13 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 11 def new @bank_account = @payment_method.bank_accounts.new end |
#sync ⇒ Object
Never builds and holds a plan across the request: apply! with no
argument derives and validates the plan itself, including the abort
guard against a provider auth failure returning [] (which plan
would otherwise read as "every account disappeared" and deactivate
all of them). Passing a pre-built plan here would bypass that guard
entirely -- see SyncAccounts#apply! and #plan.
Rescues only EmptyResponseError -- the one operational failure
SyncAccounts itself distinguishes from a programming error. A bare
rescue StandardError here would also swallow a NoMethodError or
similar bug and report it to the admin as an unremarkable "Sync
failed", hiding it instead of surfacing it as the 500 it should be.
88 89 90 91 92 93 94 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 88 def sync Spree::BankPayments::SyncAccounts.new(payment_method: @payment_method).apply! redirect_to_index 'Accounts synced.' rescue Spree::BankPayments::SyncAccounts::EmptyResponseError => e flash[:error] = "Sync failed: #{e.}. No accounts were changed." redirect_to_index end |
#toggle_offered ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 63 def toggle_offered Spree::BankPayments::BankAccount.transaction do @payment_method.bank_accounts. for_currency(@bank_account.currency).offered. where.not(id: @bank_account.id). update_all(offered: false) @bank_account.update!(offered: !@bank_account.offered?) end redirect_to_index end |
#update ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/spree/admin/bank_accounts_controller.rb', line 31 def update # Synced accounts are the provider's record, not ours -- editing their # currency or details here would silently diverge from the account # actually watched. Checked against the *raw*, unparsed params so a # malformed `details` payload can't slip past this guard by raising # JSON::ParserError before it runs (see the JSON.parse call in # #bank_account_params). if @bank_account.synced? && synced_field_present? flash[:error] = 'Synced accounts cannot be edited. Re-sync to refresh them.' return redirect_to_index end if @bank_account.update(bank_account_params) redirect_to_index 'Bank account updated.' else render :edit end rescue JSON::ParserError @bank_account.errors.add(:details, 'must contain valid JSON') render :edit end |