Move select-options-formatting logic to helper

This commit is contained in:
Matt-Yorkley
2021-11-30 13:35:39 +00:00
parent d85597fe4c
commit ce7fb1b4dc
2 changed files with 10 additions and 1 deletions

View File

@@ -143,4 +143,13 @@ module CheckoutHelper
def checkout_step?(step)
checkout_step == step.to_s
end
def stripe_card_options(cards)
cards.map do |cc|
[
"#{cc.brand} #{cc.last_digits} #{I18n.t(:card_expiry_abbreviation)}:#{cc.month.to_s.rjust(2, '0')}/#{cc.year}",
cc.id
]
end
end
end

View File

@@ -9,7 +9,7 @@
%label
= t('split_checkout.step2.form.stripe.use_saved_card')
= select_tag :card,
options_for_select(@saved_credit_cards.map {|cc| [ "#{cc.brand} #{cc.last_digits} #{I18n.t(:card_expiry_abbreviation)}:#{cc.month.to_s.rjust(2, '0')}/#{cc.year}", cc.id ] } + [[t('split_checkout.step2.form.stripe.create_new_card'), ""]], @selected_card),
options_for_select(stripe_card_options(@saved_credit_cards) + [[t('split_checkout.step2.form.stripe.create_new_card'), ""]], @selected_card),
{ "data-action": "change->stripe-cards#onSelectCard", "data-stripe-cards-target": "select" }
.checkout-input{"data-stripe-cards-target": "stripeelements"}