summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authormark <mark>2010-03-09 21:57:52 +0000
committermark <mark>2010-03-09 21:57:52 +0000
commit2dbf3fa84c7825aa02e168bc07a167ca9ad79620 (patch)
tree317bccc51f934e9b9425280c03e711168ab3c6e6 /FS
parente84081ace9a19bd8007a74e8c062f4bc8d573e5d (diff)
RT#7407, variable length prepaid card codes
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/prepay_credit.pm9
1 files changed, 5 insertions, 4 deletions
diff --git a/FS/FS/prepay_credit.pm b/FS/FS/prepay_credit.pm
index 302ba37c7..e5773aebd 100644
--- a/FS/FS/prepay_credit.pm
+++ b/FS/FS/prepay_credit.pm
@@ -136,7 +136,7 @@ sub agent {
=over 4
-=item generate NUM TYPE HASHREF
+=item generate NUM TYPE LENGTH HASHREF
Generates the specified number of prepaid cards. Returns an array reference of
the newly generated card identifiers, or a scalar error message.
@@ -145,11 +145,12 @@ the newly generated card identifiers, or a scalar error message.
#false laziness w/agent::generate_reg_codes
sub generate {
- my( $num, $type, $hashref ) = @_;
+ my( $num, $type, $length, $hashref ) = @_;
my @codeset = ();
push @codeset, ( 'A'..'Z' ) if $type =~ /alpha/;
push @codeset, ( '1'..'9' ) if $type =~ /numeric/;
+ $length ||= 8;
local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
@@ -163,11 +164,11 @@ sub generate {
my $dbh = dbh;
my $condup = 0; #don't retry forever
-
+
my @cards = ();
for ( 1 ... $num ) {
- my $identifier = join('', map($codeset[int(rand $#codeset)], (0..7) ) );
+ my $identifier = join('', map($codeset[int(rand $#codeset)], (1..$length) ) );
redo if qsearchs('prepay_credit',{identifier=>$identifier}) && $condup++<23;
$condup = 0;