mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 16:38:18 +00:00
no destroy
This commit is contained in:
parent
0f8b36f7de
commit
b375b265b9
6 changed files with 37 additions and 20 deletions
|
|
@ -1,5 +1,5 @@
|
|||
class HCB::OauthConnectionsController < ApplicationController
|
||||
skip_after_action :verify_authorized, only: [:new, :callback, :destroy]
|
||||
skip_after_action :verify_authorized, only: [:new, :callback]
|
||||
|
||||
def new
|
||||
redirect_to hcb_oauth_authorize_url, allow_other_host: true
|
||||
|
|
@ -27,11 +27,6 @@ class HCB::OauthConnectionsController < ApplicationController
|
|||
redirect_to hcb_payment_accounts_path, notice: "HCB account linked! Now create a payment account."
|
||||
end
|
||||
|
||||
def destroy
|
||||
current_user.hcb_oauth_connection&.destroy
|
||||
redirect_to root_path, notice: "HCB account unlinked"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def hcb_oauth_client
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class HCB::PaymentAccountsController < ApplicationController
|
|||
skip_after_action :verify_authorized
|
||||
|
||||
before_action :require_hcb_connection, except: [:index]
|
||||
before_action :set_payment_account, only: [:show, :destroy]
|
||||
before_action :set_payment_account, only: [:show]
|
||||
|
||||
def index
|
||||
@payment_accounts = current_user.hcb_payment_accounts
|
||||
|
|
@ -38,11 +38,6 @@ class HCB::PaymentAccountsController < ApplicationController
|
|||
def show
|
||||
end
|
||||
|
||||
def destroy
|
||||
@payment_account.destroy
|
||||
redirect_to hcb_payment_accounts_path, notice: "Payment account removed"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_hcb_connection
|
||||
|
|
|
|||
33
app/services/hcb/transfer_service.rb
Normal file
33
app/services/hcb/transfer_service.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
class HCB::TransferService
|
||||
attr_reader :hcb_payment_account, :amount_cents, :memo, :errors
|
||||
|
||||
def initialize(hcb_payment_account:, amount_cents:, memo:)
|
||||
@hcb_payment_account = hcb_payment_account
|
||||
@amount_cents = amount_cents
|
||||
@memo = memo
|
||||
@errors = []
|
||||
end
|
||||
|
||||
def call
|
||||
return failure("No HCB payment account provided") unless hcb_payment_account
|
||||
return failure("Amount must be positive") unless amount_cents.positive?
|
||||
|
||||
transfer = hcb_payment_account.create_disbursement!(
|
||||
amount_cents: amount_cents,
|
||||
memo: memo,
|
||||
)
|
||||
|
||||
transfer
|
||||
rescue HCBV4::APIError => e
|
||||
failure("HCB disbursement failed: #{e.message}")
|
||||
rescue => e
|
||||
failure("Transfer failed: #{e.message}")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def failure(message)
|
||||
@errors << message
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
<% if current_user.hcb_connected? %>
|
||||
<div class="notice success">
|
||||
✓ HCB account linked
|
||||
<%= link_to "Unlink", hcb_oauth_connection_path, method: :delete, data: { confirm: "Are you sure? This will remove all payment accounts." }, class: "btn btn-small danger" %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
|
|
@ -20,7 +19,6 @@
|
|||
<tr>
|
||||
<th>Organization</th>
|
||||
<th>Created</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
@ -28,9 +26,6 @@
|
|||
<tr>
|
||||
<td><%= account.organization_name %></td>
|
||||
<td><%= account.created_at.strftime("%Y-%m-%d") %></td>
|
||||
<td>
|
||||
<%= link_to "Remove", hcb_payment_account_path(account), method: :delete, data: { confirm: "Remove this payment account?" }, class: "btn btn-small danger" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -14,5 +14,4 @@
|
|||
|
||||
<div class="actions">
|
||||
<%= link_to "Back to Payment Accounts", hcb_payment_accounts_path, class: "btn btn-small" %>
|
||||
<%= link_to "Remove", hcb_payment_account_path(@payment_account), method: :delete, data: { confirm: "Remove this payment account?" }, class: "btn btn-small danger" %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -531,10 +531,10 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
namespace :hcb do
|
||||
resource :oauth_connection, only: [:new, :destroy] do
|
||||
resource :oauth_connection, only: [:new] do
|
||||
get :callback, on: :collection
|
||||
end
|
||||
resources :payment_accounts, only: [:index, :new, :create, :show, :destroy]
|
||||
resources :payment_accounts, only: [:index, :new, :create, :show]
|
||||
end
|
||||
resources :source_tags
|
||||
namespace :warehouse do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue