prepaid download/upload tracking
[freeside.git] / FS / FS / payby.pm
index 8f7f1ae..42328b4 100644 (file)
@@ -3,6 +3,7 @@ package FS::payby;
 use strict;
 use vars qw(%hash %payby2bop);
 use Tie::IxHash;
+use Business::CreditCard;
 
 
 =head1 NAME
@@ -35,6 +36,11 @@ Payment types.
 
 =cut
 
+# paybys can be any/all of:
+# - a customer payment type (cust_main.payby)
+# - a payment or refund type (cust_pay.payby)
+# - an event type (part_bill_event.payby)
+
 tie %hash, 'Tie::IxHash',
   'CARD' => {
     tinyname  => 'card',
@@ -93,8 +99,13 @@ tie %hash, 'Tie::IxHash',
   },
   'DCLN' => {  # This is only an event.
     tinyname  => 'declined',
-    shortname => 'Declined payment',
-    longname  => 'Declined payment',
+    shortname => 'Batch declined payment',
+    longname  => 'Batch declined payment',
+
+    #its neither of these..
+    #cust_main => '',
+    cust_pay  => '',
+
   },
 ;
 
@@ -107,11 +118,31 @@ sub payby2longname {
   map { $_ => $hash{$_}->{longname} } $self->payby;
 }
 
+sub shortname {
+  my( $self, $payby ) = @_;
+  $hash{$payby}->{shortname};
+}
+
+sub longname {
+  my( $self, $payby ) = @_;
+  $hash{$payby}->{longname};
+}
+
 %payby2bop = (
   'CARD' => 'CC',
   'CHEK' => 'ECHECK',
 );
 
+sub payby2bop {
+  my( $self, $payby ) = @_;
+  $payby2bop{ $self->payby2payment($payby) };
+}
+
+sub payby2payment {
+  my( $self, $payby ) = @_;
+  $hash{$payby}{'cust_pay'} || $payby;
+}
+
 sub cust_payby {
   my $self = shift;
   grep { ! exists $hash{$_}->{cust_main} } $self->payby;
@@ -132,7 +163,7 @@ sub payinfo_check{
         or return "Illegal (mistyped?) credit card number (payinfo)";
       $$payinforef = $1;
       validate($$payinforef) or return "Illegal credit card number";
-      return "Unknown card type" if cardype($$payinforef) eq "Unknown";
+      return "Unknown card type" if cardtype($$payinforef) eq "Unknown";
     } else {
       $$payinforef="N/A";
     }