Module: PaymentsHelper
- Defined in:
- app/helpers/payments_helper.rb
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
48 49 50 |
# File 'app/helpers/payments_helper.rb', line 48 def (payment) payment_dropdown_actions(payment).reject { |a| a == :divider } end |
#payment_dropdown_actions(payment) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/payments_helper.rb', line 14 def payment_dropdown_actions(payment) [].tap do |opts| if (payment.category == Payment::PAYPAL || payment.category == Payment::CREDIT_CARD) && payment.total_captured < payment.amount if payment. || (payment.captured? && payment.supports_multicapture?) opts << link_to(fa_icon('hand-holding-dollar', text: 'Capture Funds'), capture_funds_payment_path(payment), class: 'dropdown-item') end end if payment.can_be_voided? opts << link_to(fa_icon('ban', text: 'Void'), void_order_payment_path(@order, payment), class: 'dropdown-item') end if payment. && user_has_role?('accounting_rep') opts << link_to(fa_icon('check', text: 'Approve'), approve_payment_path(payment), class: 'dropdown-item') end opts << :divider if opts.any? if payment.category == Payment::CREDIT_CARD && (payment. || payment.captured?) opts << link_to("Send Auth Receipt", send_receipt_order_payment_path(@order, payment), class: 'dropdown-item') end if payment.receipts.any? opts << link_to("Capture Receipt", email_receipt_path(payment.receipts.last), class: 'dropdown-item') end 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
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 87 88 89 90 91 92 93 94 |
# File 'app/helpers/payments_helper.rb', line 52 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
109 110 111 112 113 114 115 116 117 118 |
# File 'app/helpers/payments_helper.rb', line 109 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
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/payments_helper.rb', line 96 def reorder_tabs_by_preference(hsh) return hsh unless @payment_preference&.category.present? 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
3 4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/payments_helper.rb', line 3 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 return payment end |
#user_has_role?(role) ⇒ Boolean
120 121 122 |
# File 'app/helpers/payments_helper.rb', line 120 def user_has_role?(role) (current_account&.has_role?(role)).to_b end |
#user_is_manager? ⇒ Boolean
124 125 126 |
# File 'app/helpers/payments_helper.rb', line 124 def user_is_manager? (current_account&.is_manager?).to_b end |