[freeside-commits] branch master updated. fc937dac3920ddbf5d009bb28c75ff1eb529c625

Jeremy Davis jeremyd at 420.am
Wed Jan 28 20:26:42 PST 2015


The branch, master has been updated
       via  fc937dac3920ddbf5d009bb28c75ff1eb529c625 (commit)
      from  92a327b2bc09344a7e0db93f40e34b71547bf075 (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 fc937dac3920ddbf5d009bb28c75ff1eb529c625
Author: Jeremy Davis <jeremyd at freeside.biz>
Date:   Wed Jan 28 22:25:23 2015 -0600

    Ticket #33252 API customer update

diff --git a/FS/FS/API.pm b/FS/FS/API.pm
index 62a97d8..629463c 100644
--- a/FS/FS/API.pm
+++ b/FS/FS/API.pm
@@ -427,6 +427,119 @@ sub new_customer {
 
 =back 
 
+=item update_customer
+
+Updates an existing customer. Takes a hash reference as parameter with the foll$
+
+=over 4
+
+=item secret
+
+API Secret
+
+=item first
+
+first name (required)
+
+=item last
+
+last name (required)
+
+=item company
+
+Company name
+
+=item address1 (required)
+
+Address line one
+
+=item city (required)
+
+City
+
+=item county
+
+County
+
+=item state (required)
+
+State
+
+=item zip (required)
+
+Zip or postal code
+
+=item country
+
+2 Digit Country Code
+
+=item daytime
+
+Daytime phone number
+
+=item night
+
+Evening phone number
+
+=item fax
+
+Fax number
+
+=item mobile
+
+Mobile number
+
+=item invoicing_list
+
+comma-separated list of email addresses for email invoices. The special value '$
+postal_invoicing
+Set to 1 to enable postal invoicing
+
+=item payby
+
+CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY
+
+=item payinfo
+
+Card number for CARD/DCRD, account_number at aba_number for CHEK/DCHK, prepaid "pi$
+
+=item paycvv
+
+Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
+
+=item paydate
+
+Expiration date for CARD/DCRD
+
+=item payname
+
+Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
+
+=item referral_custnum
+
+Referring customer number
+
+=item salesnum
+Sales person number
+
+=item agentnum
+
+Agent number
+
+=cut
+sub update_customer {
+  my( $class, %opt ) = @_;
+
+  my $conf = new FS::Conf;
+  return { 'error' => 'Incorrect shared secret' }
+    unless $opt{secret} eq $conf->config('api_shared_secret');
+
+  FS::cust_main->API_update( %opt );
+}
+
+=back
+
+
 =item customer_info
 
 Returns general customer information. Takes a hash reference as parameter with the following keys: custnum and API secret 
diff --git a/FS/FS/cust_main/API.pm b/FS/FS/cust_main/API.pm
index 283683b..4a09b93 100644
--- a/FS/FS/cust_main/API.pm
+++ b/FS/FS/cust_main/API.pm
@@ -3,6 +3,7 @@ package FS::cust_main::API;
 use strict;
 use FS::Conf;
 use FS::part_tag;
+use FS::Record qw( qsearchs );
 
 =item API_getinfo FIELD => VALUE, ...
 
@@ -156,4 +157,66 @@ sub API_insert {
 
 }
 
+sub API_update {
+
+  my( $class, %opt ) = @_;
+
+  my $conf = new FS::Conf;
+
+
+  my $custnum = $opt{'custnum'}
+    or return { 'error' => "no customer record" };
+
+  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+    or return { 'error' => "unknown custnum $custnum" };
+
+  my $new = new FS::cust_main { $cust_main->hash };
+
+  $new->set( $_ => $opt{$_} )
+    foreach grep { exists $opt{$_} } qw(
+        agentnum salesnum refnum agent_custid referral_custnum
+        last first company
+        daytime night fax mobile
+        payby payinfo paydate paycvv payname
+      ),
+
+  
+  my @invoicing_list = $opt{'invoicing_list'}
+                         ? split( /\s*\,\s*/, $opt{'invoicing_list'} )
+                         : ();
+  push @invoicing_list, 'POST' if $opt{'postal_invoicing'};
+
+  my ($bill_hash, $ship_hash);
+  foreach my $f (FS::cust_main->location_fields) {
+    # avoid having to change this in front-end code
+    $bill_hash->{$f} = $opt{"bill_$f"} || $opt{$f};
+    $ship_hash->{$f} = $opt{"ship_$f"};
+  }
+
+  my $bill_location = FS::cust_location->new($bill_hash);
+  my $ship_location;
+  # we don't have an equivalent of the "same" checkbox in selfservice^Wthis API
+  # so is there a ship address, and if so, is it different from the billing 
+  # address?
+  if ( length($ship_hash->{address1}) > 0 and
+          grep { $bill_hash->{$_} ne $ship_hash->{$_} } keys(%$ship_hash)
+         ) {
+
+    $ship_location = FS::cust_location->new( $ship_hash );
+  
+  } else {
+    $ship_location = $bill_location;
+  }
+
+  $new->set('bill_location' => $bill_location);
+  $new->set('ship_location' => $ship_location);
+
+  my $error = $new->replace( $cust_main, \@invoicing_list );
+  return { 'error'   => $error } if $error;
+  
+  return { 'error'   => '',
+         };
+  
+}
+
 1;


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

Summary of changes:
 FS/FS/API.pm           |  113 ++++++++++++++++++++++++++++++++++++++++++++++++
 FS/FS/cust_main/API.pm |   63 +++++++++++++++++++++++++++
 2 files changed, 176 insertions(+)




More information about the freeside-commits mailing list