first crack at payment processing with self-service (step two of the process)
authorivan <ivan>
Mon, 19 May 2003 13:38:41 +0000 (13:38 +0000)
committerivan <ivan>
Mon, 19 May 2003 13:38:41 +0000 (13:38 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/cust_main.pm
fs_selfservice/FS-SelfService/cgi/make_payment.html
fs_selfservice/FS-SelfService/cgi/process_payment.html [new file with mode: 0644]
fs_selfservice/FS-SelfService/cgi/selfservice.cgi

index a64cfb5..2ce55a8 100644 (file)
@@ -185,7 +185,30 @@ sub make_payment{
 
   my $custnum = $session->{'custnum'};
 
+  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+    or return { 'error' => "unknown custnum $custnum" };
+
+  if ( $p->{'save'} ) {
+    my $new = new FS::cust_main { $cust_main->hash };
+    $new->set( $_ => $p->{$_} )
+      foreach qw( payname address1 address2 city state zip payinfo );
+    $new->set( 'paydate' => $p->{'month'}. '-'. $p->{'year'} );
+    $new->set( 'payby' => $p->{'auto'} ? 'CARD' : 'DCRD' );
+    my $error = $new->replace($cust_main);
+    return { 'error' => $error } if $error;
+    $cust_main = $new;
+  }
+
+  my $error = $cust_main->realtime_bop( 'CC', $p->{'amount'}, quiet=>1,
+    'paydate' => $p->{'month'}. '-'. $p->{'year'},
+    map { $_ => $p->{$_} }
+      qw( payname address1 address2 city state zip payinfo )
+  );
+  return { 'error' => $error } if $error;
+
+  $cust_main->apply_payments;
 
+  return { 'error' => '' };
 
 }
 
index b162622..09c5647 100644 (file)
@@ -1411,7 +1411,6 @@ sub collect {
 
 =item realtime_bop METHOD AMOUNT [ OPTION => VALUE ... ]
 
-
 Runs a realtime credit card, ACH (electronic check) or phone bill transaction
 via a Business::OnlinePayment realtime gateway.  See
 L<http://420.am/business-onlinepayment> for supported gateways.
@@ -1420,6 +1419,10 @@ Available methods are: I<CC>, I<ECHECK> and I<LEC>
 
 Available options are: I<description>, I<invnum>, I<quiet>
 
+The additional options I<payname>, I<address1>, I<address2>, I<city>, I<state>,
+I<zip>, I<payinfo> and I<paydate> are also available.  Any of these options,
+if set, will override the value from the customer record.
+
 I<description> is a free-text field passed to the gateway.  It defaults to
 "Internet services".
 
@@ -1443,6 +1446,11 @@ sub realtime_bop {
   eval "use Business::OnlinePayment";  
   die $@ if $@;
 
+  #overrides
+  $self->set( $_ => $options{$_} )
+    foreach grep { exists($options{$_}) }
+            qw( payname address1 address2 city state zip payinfo paydate );
+
   #load up config
   my $bop_config = 'business-onlinepayment';
   $bop_config .= '-ach'
@@ -1571,7 +1579,8 @@ sub realtime_bop {
     );
 
     my $cust_pay = new FS::cust_pay ( {
-       'invnum'   => $self->invnum, #!!!!!!!!
+       'custnum'  => $self->custnum,
+       'invnum'   => $options{'invnum'},
        'paid'     => $amount,
        '_date'     => '',
        'payby'    => $method2payby{$method},
index 6adc0bd..fdb411b 100644 (file)
@@ -31,7 +31,7 @@
     <SELECT NAME="card_type"><OPTION></OPTION>
       <%= foreach ( keys %card_types ) {
             $selected = $card_type eq $card_types{$_} ? ' SELECTED' : '';
-            $OUT .= qq(<OPTION$selected VALUE="). $card_types->{$_}. qq(">$_\n);
+            $OUT .= qq(<OPTION$selected VALUE="). $card_types{$_}. qq(">$_\n);
       } %>
     </SELECT>
   </TD>
   </TD>
 </TR><TR>
   <TD COLSPAN=2>
-    <INPUT TYPE="checkbox"<%= $payby eq 'CARD' ? ' CHECKED' : '' %> NAME="auto" VALUE="1">
+    <INPUT TYPE="checkbox"<%= $payby eq 'CARD' ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
     Charge future payments to this card automatically
   </TD>
 </TR>
diff --git a/fs_selfservice/FS-SelfService/cgi/process_payment.html b/fs_selfservice/FS-SelfService/cgi/process_payment.html
new file mode 100644 (file)
index 0000000..e4946dc
--- /dev/null
@@ -0,0 +1,18 @@
+<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR>
+<%= $url = "$selfurl?session=$session_id;action="; ''; %>
+<TABLE BORDER=0 CELLPADDING=4><TR><TD VALIGN="top" HEIGHT=384 BGCOLOR="#dddddd">
+<A HREF="<%= $url %>myaccount">MyAccount</A><BR>
+<!-- <A HREF="<%= $url %>other">SomethingElse</A><BR> -->
+</TD><TD VALIGN="top">
+<FONT SIZE=4>Payment results</FONT><BR><BR>
+<%= if ( $error ) {
+  $OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">Error processing your payment: $error</FONT!;
+} else {
+  $OUT .= 'Your payment was processed sucessfully.  Thank you.';
+} %>
+</TD></TR></TABLE>
+<HR>
+<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT>
+</BODY></HTML>
+
index 2ce2c8b..d43df40 100644 (file)
@@ -96,6 +96,8 @@ sub make_payment {
 
 sub process_payment {
 
+  use Business::CreditCard;
+
   $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/
     or die "illegal amount"; #!!!
   my $amount = $1;
@@ -143,7 +145,7 @@ sub process_payment {
   $auto = 1 if $cgi->param('auto');
 
   $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch";
-  my $patbatch = $1;
+  my $paybatch = $1;
 
   process_payment(
     'session_id' => $session_id,