[freeside-commits] branch master updated. 24cc2801560aa110a077ee7f3a6e50d6aa40fc36

Ivan ivan at 420.am
Mon Feb 16 00:01:11 PST 2015


The branch, master has been updated
       via  24cc2801560aa110a077ee7f3a6e50d6aa40fc36 (commit)
      from  0870a4c1fb02be43ea5524f58650d99c81477681 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 24cc2801560aa110a077ee7f3a6e50d6aa40fc36
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon Feb 16 00:01:07 2015 -0800

    multiple payment options (event action migration), RT#23741

diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 263be80..35a1e19 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -312,6 +312,9 @@ sub upgrade_data {
     #payby conditions to new ones
     'part_event_condition' => [],
 
+    #payby actions to new ones
+    'part_event' => [],
+
     #cust_main (remove paycvv from history, locations, cust_payby, etc)
     'cust_main' => [],
 
diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm
index 20698fb..1f6a9e9 100644
--- a/FS/FS/cust_main/Billing_Realtime.pm
+++ b/FS/FS/cust_main/Billing_Realtime.pm
@@ -45,6 +45,36 @@ These methods are available on FS::cust_main objects.
 
 =over 4
 
+=item realtime_cust_payby
+
+=cut
+
+sub realtime_cust_payby {
+  my( $self, %options ) = @_;
+
+  local($DEBUG) = $FS::cust_main::DEBUG if $FS::cust_main::DEBUG > $DEBUG;
+
+  $options{amount} = $self->balance unless exists( $options{amount} );
+
+  my @cust_payby = qsearch({
+    'table'     => 'cust_payby',
+    'hashref'   => { 'custnum' => $self->custnum, },
+    'extra_sql' => " AND payby IN ( 'CARD', 'CHEK' ) ",
+    'order_by'  => 'ORDER BY weight ASC',
+  });
+                                                   
+  my $error;
+  foreach my $cust_payby (@cust_payby) {
+    $error = $cust_payby->realtime_bop( %options, );
+    last unless $error;
+  }
+
+  #XXX what about the earlier errors?
+
+  $error;
+
+}
+
 =item realtime_collect [ OPTION => VALUE ... ]
 
 Attempt to collect the customer's current balance with a realtime credit 
diff --git a/FS/FS/part_event.pm b/FS/FS/part_event.pm
index e7acf5a..d15f35b 100644
--- a/FS/FS/part_event.pm
+++ b/FS/FS/part_event.pm
@@ -604,6 +604,22 @@ sub process_initialize {
   $part_event->initialize;
 }
 
+sub _upgrade_data { #class method
+  my ($class, %opts) = @_;
+
+  foreach my $part_event (
+    qsearch('part_event', { 'action' => 'cust_bill_realtime_card' }),
+    qsearch('part_event', { 'action' => 'cust_bill_realtime_check' }),
+  ) {
+
+    $part_event->action('realtime_auto');
+    my $error = $part_event->replace;
+    die $error if $error;
+
+  }
+     
+}
+
 =back
 
 =head1 SEE ALSO
diff --git a/FS/FS/part_event/Action/realtime_auto.pm b/FS/FS/part_event/Action/realtime_auto.pm
new file mode 100644
index 0000000..3902319
--- /dev/null
+++ b/FS/FS/part_event/Action/realtime_auto.pm
@@ -0,0 +1,41 @@
+package FS::part_event::Action::realtime_auto;
+
+use strict;
+use base qw( FS::part_event::Action );
+
+sub description {
+  #'Run card with a <a href="http://420.am/business-onlinepayment/">Business::OnlinePayment</a> realtime gateway';
+  'Run card or check with a Business::OnlinePayment realtime gateway';
+}
+
+sub eventtable_hashref {
+  { 'cust_bill' => 1,
+    'cust_main' => 1,
+  };
+}
+
+sub default_weight { 30; }
+
+sub do_action {
+  my( $self, $object ) = @_;
+
+  my $cust_main = $self->cust_main($object);
+
+  my %opt = ('cc_surcharge_from_event' => 1);
+
+  my $amount;
+  my $balance = $cust_main->balance;
+  if ( ref($object) eq 'FS::cust_main' ) {
+    $amount = $balance;
+  } elsif ( ref($object) eq 'FS::cust_bill' ) {
+    $amount = ( $balance < $object->owed ) ? $balance : $object->owed;
+    $opt{'invnum'} = $object->invnum;
+  } else {
+    die 'guru meditation #5454.au';
+  }
+
+  $cust_main->realtime_cust_payby( 'amount' => $amount, %opt, );
+
+}
+
+1;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Upgrade.pm                         |    3 +++
 FS/FS/cust_main/Billing_Realtime.pm      |   30 ++++++++++++++++++++++
 FS/FS/part_event.pm                      |   16 ++++++++++++
 FS/FS/part_event/Action/realtime_auto.pm |   41 ++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+)
 create mode 100644 FS/FS/part_event/Action/realtime_auto.pm




More information about the freeside-commits mailing list