Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 2484 Bytes
1 | ######################################################################## |
2 | # File:: purchase_cards_helper.rb |
3 | # (C):: Hipposoft 2010 |
4 | # |
5 | # Purpose:: Utility methods for views related to credit/debit cards. |
6 | # ---------------------------------------------------------------------- |
7 | # 23-Mar-2010 (ADH): Created. |
8 | ######################################################################## |
9 | |
10 | module PurchaseCardsHelper |
11 | |
12 | # Return HTML for a selection menu for the given form and method (e.g. |
13 | # a method of ":card_type" to work for a form generated for a model instance |
14 | # with the instance having a compatible attribute named ":card_type"). The |
15 | # menu maps Active Merchant card types to internationalised human-readable |
16 | # strings. When submitted, a form containing the menu will have a field name |
17 | # based on the method name you supplied and a field value from the list of |
18 | # Active Mercant card types. Code accepting the form submission should check |
19 | # to make sure the card type is a supported value in case someone hacks the |
20 | # form and tries to submit some other card type for some reason. |
21 | # |
22 | # Internationalisation runs through "apphelp_view_hint" with the Controller |
23 | # set to "PaymentGatewayOnsiteController" and token names of |
24 | # "card_type_<name>". If a translation is missing, an attempt to create a |
25 | # decent result is generated from the raw card name directly. |
26 | # |
27 | # A blank first value *is* included so that users are forced to make a valid |
28 | # selection for 'new' objects. |
29 | # |
30 | # If you want to only accept a certain list of cards, pass an array of card |
31 | # types in the optional third parameter. Any of those cards supported by |
32 | # ActiveMerchant will be shown. Any not supported by ActiveMerchant will be |
33 | # ignored. Any additional supported card types not in your list will also be |
34 | # ignored. |
35 | # |
36 | def purchasecardshelp_type_menu( form, method, permitted_types = nil ) |
37 | types = ActiveMerchant::Billing::CreditCard.card_companies.keys |
38 | |
39 | unless ( permitted_types.nil? ) |
40 | types.reject! do | card_type | |
41 | ! permitted_types.include?( card_type ) |
42 | end |
43 | end |
44 | |
45 | form.select( |
46 | method, |
47 | types.collect { | card_type | |
48 | type_name = apphelp_view_hint( |
49 | "card_type_#{ card_type }", |
50 | PaymentGatewayOnsiteController, |
51 | :default => card_type.titleize |
52 | ) |
53 | |
54 | [ type_name, card_type ] |
55 | }.sort { | a, b | a[ 0 ] <=> b[ 0 ] }, |
56 | :include_blank => true |
57 | ) |
58 | end |
59 | end |