add card-types configuration value for self-service
authorivan <ivan>
Tue, 14 Nov 2006 02:54:07 +0000 (02:54 +0000)
committerivan <ivan>
Tue, 14 Nov 2006 02:54:07 +0000 (02:54 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/Conf.pm

index aa8ff9e..c0fb46b 100644 (file)
@@ -204,33 +204,62 @@ sub payment_info {
   #generic
   ##
 
-  my $conf = new FS::Conf;
-  my %states = map { $_->state => 1 }
-                 qsearch('cust_main_county', {
-                   'country' => $conf->config('countrydefault') || 'US'
-                 } );
-
   use vars qw($payment_info); #cache for performance
-  $payment_info ||= {
+  unless ( $payment_info ) {
+
+    my $conf = new FS::Conf;
+    my %states = map { $_->state => 1 }
+                   qsearch('cust_main_county', {
+                     'country' => $conf->config('countrydefault') || 'US'
+                   } );
+
+    my %card_types = (
+      #displayname                    #value (Business::CreditCard)
+      "VISA"                       => "VISA card",
+      "MasterCard"                 => "MasterCard",
+      "Discover"                   => "Discover card",
+      "American Express"           => "American Express card",
+      "Diner's Club/Carte Blanche" => "Diner's Club/Carte Blanche",
+      "enRoute"                    => "enRoute",
+      "JCB"                        => "JCB",
+      "BankCard"                   => "BankCard",
+      "Switch"                     => "Switch",
+      "Solo"                       => "Solo",
+    );
+    my @conf_card_types = grep { ! /^\s*$/ } $conf->config('card-types');
+    if ( @conf_card_types ) {
+      #perhaps the hash is backwards for this, but this way works better for
+      #usage in selfservice
+      %card_types = map  { $_ => $card_types{$_} }
+                    grep {
+                           my $d = $_;
+                          grep { $card_types{$d} eq $_ } @conf_card_types
+                         }
+                   keys %card_types;
+    }
 
-    #list all counties/states/countries
-    'cust_main_county' => 
-      [ map { $_->hashref } qsearch('cust_main_county', {}) ],
+    $payment_info = {
 
-    #shortcut for one-country folks
-    'states' =>
-      [ sort { $a cmp $b } keys %states ],
+      #list all counties/states/countries
+      'cust_main_county' => 
+        [ map { $_->hashref } qsearch('cust_main_county', {}) ],
 
-    'card_types' => {
-      'VISA' => 'VISA card',
-      'MasterCard' => 'MasterCard',
-      'Discover' => 'Discover card',
-      'American Express' => 'American Express card',
-      'Switch' => 'Switch',
-      'Solo' => 'Solo',
-    },
+      #shortcut for one-country folks
+      'states' =>
+        [ sort { $a cmp $b } keys %states ],
 
-  };
+      'card_types' => {
+        'VISA' => 'VISA card',
+        'MasterCard' => 'MasterCard',
+        'Discover' => 'Discover card',
+        'American Express' => 'American Express card',
+        'Switch' => 'Switch',
+        'Solo' => 'Solo',
+      },
+
+    };
+
+  }
 
   ##
   #customer-specific
index edb1ca3..bf853bc 100644 (file)
@@ -1,6 +1,6 @@
 package FS::Conf;
 
-use vars qw($default_dir @config_items $DEBUG );
+use vars qw($default_dir @config_items @card_types $DEBUG );
 use IO::File;
 use File::Basename;
 use FS::ConfItem;
@@ -284,6 +284,20 @@ httemplate/docs/config.html
 
 =cut
 
+#Business::CreditCard
+@card_types = (
+  "VISA card",
+  "MasterCard",
+  "Discover card",
+  "American Express card",
+  "Diner's Club/Carte Blanche",
+  "enRoute",
+  "JCB",
+  "BankCard",
+  "Switch",
+  "Solo",
+);
+
 @config_items = map { new FS::ConfItem $_ } (
 
   {
@@ -1476,15 +1490,7 @@ httemplate/docs/config.html
     'section'     => 'billing',
     'description' => 'Save CVV2 information after the initial transaction for the selected credit card types.  Enabling this option may be in violation of your merchant agreement(s), so please check them carefully before enabling this option for any credit card types.',
     'type'        => 'selectmultiple',
-    'select_enum' => [ "VISA card",
-                       "MasterCard",
-                       "Discover card",
-                       "American Express card",
-                       "Diner's Club/Carte Blanche",
-                       "enRoute",
-                       "JCB",
-                       "BankCard",
-                     ],
+    'select_enum' => \@card_types,
   },
 
   {
@@ -1909,10 +1915,18 @@ httemplate/docs/config.html
   {
     'key'         => 'support-key',
     'section'     => '',
-    'description' => 'A support key enables access to commercial services accessed over the network, such as access to the internal ticket system, priority support and optional backups.',
+    'description' => 'A support key enables access to commercial services delivered over the network, such as the payroll module, access to the internal ticket system, priority support and optional backups.',
     'type'        => 'text',
   },
 
+  {
+    'key'         => 'card-types',
+    'section'     => 'billing',
+    'description' => 'Select one or more card types to enable only those card types.  If no card types are selected, all card types are available.',
+    'type'        => 'selectmultiple',
+    'select_enum' => \@card_types,
+  },
+
 );
 
 1;