use Data::Dumper;
@ISA = qw( Exporter );
-@EXPORT_OK = qw( send_email send_fax states_hash state_label );
+@EXPORT_OK = qw( send_email send_fax
+ states_hash counties state_label
+ card_types
+ );
$DEBUG = 0;
# sort
map { s/[\n\r]//g; $_; }
map { $_->state; }
- qsearch( 'cust_main_county',
- { 'country' => $country },
- 'DISTINCT ON ( state ) *',
- )
- ;
+ qsearch({
+ 'select' => 'state',
+ 'table' => 'cust_main_county',
+ 'hashref' => { 'country' => $country },
+ 'extra_sql' => 'GROUP BY state',
+ });
#it could throw a fatal "Invalid country code" error (for example "AX")
my $subcountry = eval { new Locale::SubCountry($country) }
@states;
}
+=item counties STATE COUNTRY
+
+Returns a list of counties for this state and country.
+
+=cut
+
+sub counties {
+ my( $state, $country ) = @_;
+
+ sort map { s/[\n\r]//g; $_; }
+ map { $_->county }
+ qsearch({
+ 'select' => 'DISTINCT county',
+ 'table' => 'cust_main_county',
+ 'hashref' => { 'state' => $state,
+ 'country' => $country,
+ },
+ });
+}
+
=item state_label STATE COUNTRY_OR_LOCALE_SUBCOUNRY_OBJECT
=cut
}
+=item card_types
+
+Returns a hash reference of the accepted credit card types. Keys are shorter
+identifiers and values are the longer strings used by the system (see
+L<Business::CreditCard).
+
+=cut
+
+#$conf from above
+
+sub card_types {
+ my $conf = new FS::Conf;
+
+ 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;
+ }
+
+ \%card_types;
+}
+
=back
=head1 BUGS