Module: PaymentsHelper
- Defined in:
- app/helpers/payments_helper.rb
Overview
View helper: payments.
Instance Method Summary collapse
- #payment_command_options(payment) ⇒ Object
- #payment_dropdown_actions(payment) ⇒ Object
- #payment_tab_options(payment, payment_options) ⇒ Object
- #preferred_tab_key(category, available_tabs) ⇒ Object
- #reorder_tabs_by_preference(hsh) ⇒ Object
- #setup_for_payment(payment, category, order) ⇒ Object
- #user_has_role?(role) ⇒ Boolean
- #user_is_manager? ⇒ Boolean
Instance Method Details
#payment_command_options(payment) ⇒ Object
40 41 42 |
# File 'app/helpers/payments_helper.rb', line 40 def (payment) payment_dropdown_actions(payment).reject { |a| a == :divider } end |
#payment_dropdown_actions(payment) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/payments_helper.rb', line 15 def payment_dropdown_actions(payment) [].tap do |opts| if [Payment::PAYPAL, Payment::CREDIT_CARD].include?(payment.category) && payment.total_captured < payment.amount opts << link_to(fa_icon('hand-holding-dollar', text: 'Capture Funds'), capture_funds_payment_path(payment), class: 'dropdown-item') if payment. || (payment.captured? && payment.supports_multicapture?) end opts << link_to(fa_icon('ban', text: 'Void'), void_order_payment_path(@order, payment), class: 'dropdown-item') if payment.can_be_voided? opts << link_to(fa_icon('check', text: 'Approve'), approve_payment_path(payment), class: 'dropdown-item') if payment. && user_has_role?('accounting_rep') opts << :divider if opts.any? opts << link_to("Send Auth Receipt", send_receipt_order_payment_path(@order, payment), class: 'dropdown-item') if payment.category == Payment::CREDIT_CARD && (payment. || payment.captured?) opts << link_to("Capture Receipt", email_receipt_path(payment.receipts.last), class: 'dropdown-item') if payment.receipts.any? if payment.category == Payment::PAYPAL_INVOICE && @order. && payment. opts << link_to("Check Invoice Status", check_invoice_status_order_payment_path(@order, payment), class: 'dropdown-item') opts << link_to("Resend Invoice", resend_paypal_invoice_order_payment_path(@order, payment), class: 'dropdown-item') end if payment.category == Payment::PAYPAL && payment. opts << link_to("Re-authorize", (payment), class: 'dropdown-item', data: { turbo_confirm: 'If the transaction cannot be reauthorized, the current authorization will be voided. Are you sure you want to continue?' }) end opts << link_to("View PO", upload_path(payment.po_upload), class: 'dropdown-item') if payment.category == Payment::PO && payment.po_upload.present? opts << link_to("Fraud Report", fraud_report_payment_path(payment), class: 'dropdown-item') if payment.fraud_report.present? opts << :divider opts << link_to("Edit", edit_order_payment_path(@order, payment), class: 'dropdown-item') end end |
#payment_tab_options(payment, payment_options) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/payments_helper.rb', line 44 def (payment, ) hsh = {} if @incrementable_auths.present? hsh[:increment_authorization] = { title: 'Increment Authorization', partial: 'crm/payments/gateways/increment_authorization', locals: { incrementable_auths: @incrementable_auths, order: @order } } end if @customer&.paypal_vault_token_id.present? hsh[:'paypal-vault'] = { title: 'PayPal Vault', partial: 'crm/payments/gateways/paypal_vault', locals: { customer: @customer, order: @order } } end .each do |payment_option| hsh[payment_option.parameterize.to_sym] = { partial: 'payment_option', locals: { payment: payment, payment_option: payment_option, payment_options: , order: @order } } end hsh.merge!(payment_link: { partial: 'crm/payments/gateways/payment_link' }) if current_user&.has_role?(%w[admin accounting_manager]) && @customer&.credit_card_vaults&.where(hidden: true)&.exists? hsh[:'saved-vaults'] = { title: 'Saved Vaults', partial: 'crm/payments/gateways/saved_vaults', locals: { customer: @customer, order: @order }, tab_class: 'bg-warning text-dark' } end reorder_tabs_by_preference(hsh) end |
#preferred_tab_key(category, available_tabs) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/payments_helper.rb', line 101 def preferred_tab_key(category, available_tabs) case category when Payment::CREDIT_CARD then :'credit-card' when Payment::PAYPAL then available_tabs.key?(:'paypal-vault') ? :'paypal-vault' : :'paypal-invoice' when Payment::PO then :'purchase-order' when Payment::VPO then :'verbal-purchase-order' when Payment::CHECK then :check when Payment::WIRE then :'wire-transfer' end end |
#reorder_tabs_by_preference(hsh) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/payments_helper.rb', line 88 def reorder_tabs_by_preference(hsh) return hsh if @payment_preference&.category.blank? preferred_key = preferred_tab_key(@payment_preference.category, hsh) return hsh unless preferred_key && hsh.key?(preferred_key) pinned = {} pinned[:increment_authorization] = hsh.delete(:increment_authorization) if hsh.key?(:increment_authorization) preferred_entry = hsh.delete(preferred_key) { **pinned, preferred_key => preferred_entry, **hsh } end |
#setup_for_payment(payment, category, order) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/payments_helper.rb', line 4 def setup_for_payment(payment, category, order) payment.tap do |pp| if category == Payment::ADV_REPL pp.amount = order.rma.credit_available if order.balance > order.rma.credit_available elsif category == Payment::RMA_CREDIT pp.amount = order.precreated_rma_credit_available if order.balance > order.precreated_rma_credit_available end end payment end |
#user_has_role?(role) ⇒ Boolean
112 113 114 |
# File 'app/helpers/payments_helper.rb', line 112 def user_has_role?(role) current_account&.has_role?(role)&.to_b end |
#user_is_manager? ⇒ Boolean
116 117 118 |
# File 'app/helpers/payments_helper.rb', line 116 def user_is_manager? current_account&.is_manager?&.to_b end |