RT#38881: BILL illegal payby in 4.x [update_payby]
authorJonathan Prykop <jonathan@freeside.biz>
Wed, 27 Jul 2016 04:46:01 +0000 (23:46 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Wed, 27 Jul 2016 04:46:01 +0000 (23:46 -0500)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/ClientAPI_XMLRPC.pm
bin/xmlrpc-insert_payby [new file with mode: 0755]
bin/xmlrpc-update_payby [new file with mode: 0755]
fs_selfservice/FS-SelfService/SelfService.pm

index d767e91..685821b 100644 (file)
@@ -1627,6 +1627,34 @@ sub insert_payby {
   
 }
 
+sub update_payby {
+  my $p = shift;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  my $cust_payby = qsearchs('cust_payby', {
+                              'custnum'      => $custnum,
+                              'custpaybynum' => $p->{'custpaybynum'},
+                           })
+    or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} };
+
+  foreach my $field (
+    qw( weight payby payinfo paycvv paydate payname paystate paytype payip )
+  ) {
+    next unless exists($p->{$field});
+    $cust_payby->set($field,$p->{$field});
+  }
+
+  my $error = $cust_payby->replace;
+  if ( $error ) {
+    return { 'error' => $error };
+  } else {
+    return { 'custpaybynum' => $cust_payby->custpaybynum };
+  }
+  
+}
+
 sub verify_payby {
   my $p = shift;
 
index 622f3df..08c6c2d 100644 (file)
@@ -129,6 +129,7 @@ sub ss2clientapi {
   'list_invoices'             => 'MyAccount/list_invoices', #?
   'list_payby'                => 'MyAccount/list_payby',
   'insert_payby'              => 'MyAccount/insert_payby',
+  'update_payby'              => 'MyAccount/update_payby',
   'delete_payby'              => 'MyAccount/delete_payby',
   'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
   'payment_info'              => 'MyAccount/payment_info',
diff --git a/bin/xmlrpc-insert_payby b/bin/xmlrpc-insert_payby
new file mode 100755 (executable)
index 0000000..9815d05
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use strict;
+use Frontier::Client;
+use Data::Dumper;
+
+use Getopt::Long;
+
+my( $email, $password ) = @ARGV;
+die "Usage: xmlrpc-insert_payby email password
+       [-w weight -b payby -i payinfo -c paycvv -d paydate -n payname -s paystate -t paytype -p payip]\n"
+  unless $email && length($password);
+
+my %opts;
+GetOptions(
+  "by=s"     => \$opts{'payby'},
+  "cvv=s"    => \$opts{'paycvv'},
+  "date=s"   => \$opts{'paydate'},
+  "info=s"   => \$opts{'payinfo'},
+  "name=s"   => \$opts{'payname'},
+  "payip=s"  => \$opts{'payip'},
+  "state=s"  => \$opts{'paystate'},
+  "type=s"   => \$opts{'paytype'},
+  "weight=i" => \$opts{'weight'},
+);
+
+foreach my $key (keys %opts) {
+  delete($opts{$key}) unless defined($opts{$key});
+}
+
+my $uri = new URI 'http://localhost:8080/';
+
+my $server = new Frontier::Client ( 'url' => $uri );
+
+my $login_result = $server->call(
+  'FS.ClientAPI_XMLRPC.login',
+    'email'    => $email,
+    'password' => $password,
+);
+die $login_result->{'error'}."\n" if $login_result->{'error'};
+
+my $call_result = $server->call(
+  'FS.ClientAPI_XMLRPC.insert_payby',
+    'session_id'   => $login_result->{'session_id'},
+    %opts,
+);
+die $call_result->{'error'}."\n" if $call_result->{'error'};
+
+print Dumper($call_result);
+print "Successfully inserted\n";
+
+1;
diff --git a/bin/xmlrpc-update_payby b/bin/xmlrpc-update_payby
new file mode 100755 (executable)
index 0000000..75a1a8d
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+use strict;
+use Frontier::Client;
+use Data::Dumper;
+
+use Getopt::Long;
+
+my( $email, $password, $custpaybynum ) = @ARGV;
+die "Usage: xmlrpc-update_payby email password custpaybynum
+       [-w weight -b payby -i payinfo -c paycvv -d paydate -n payname -s paystate -t paytype -p payip]\n"
+  unless $email && length($password) && $custpaybynum;
+
+my %opts;
+GetOptions(
+  "by=s"     => \$opts{'payby'},
+  "cvv=s"    => \$opts{'paycvv'},
+  "date=s"   => \$opts{'paydate'},
+  "info=s"   => \$opts{'payinfo'},
+  "name=s"   => \$opts{'payname'},
+  "payip=s"  => \$opts{'payip'},
+  "state=s"  => \$opts{'paystate'},
+  "type=s"   => \$opts{'paytype'},
+  "weight=i" => \$opts{'weight'},
+);
+
+foreach my $key (keys %opts) {
+  delete($opts{$key}) unless defined($opts{$key});
+}
+
+my $uri = new URI 'http://localhost:8080/';
+
+my $server = new Frontier::Client ( 'url' => $uri );
+
+my $login_result = $server->call(
+  'FS.ClientAPI_XMLRPC.login',
+    'email'    => $email,
+    'password' => $password,
+);
+die $login_result->{'error'}."\n" if $login_result->{'error'};
+
+my $call_result = $server->call(
+  'FS.ClientAPI_XMLRPC.update_payby',
+    'session_id'   => $login_result->{'session_id'},
+    'custpaybynum' => $custpaybynum,
+    %opts,
+);
+die $call_result->{'error'}."\n" if $call_result->{'error'};
+
+print Dumper($call_result);
+print "Successfully updated\n";
+
+1;
index bc54b1e..3be4ebd 100644 (file)
@@ -50,6 +50,7 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'list_invoices'             => 'MyAccount/list_invoices', #?
   'list_payby'                => 'MyAccount/list_payby',
   'insert_payby'              => 'MyAccount/insert_payby',
+  'update_payby'              => 'MyAccount/update_payby',
   'delete_payby'              => 'MyAccount/delete_payby', 
   'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
   'payment_info'              => 'MyAccount/payment_info',
@@ -682,6 +683,16 @@ Optional IP address from which payment was submitted
 If there is an error, returns a hash reference with a single key, B<error>,
 otherwise returns a hash reference with a single key, B<custpaybynum>.
 
+=item update_payby HASHREF
+
+Updates stored payment information.  Takes a hash reference with the same
+keys as insert_payby, as well as B<custpaybynum> to specify which record
+to update.  All keys except B<session_id> and B<custpaybynum> are optional;
+if omitted, the previous values in the record will be preserved.
+
+If there is an error, returns a hash reference with a single key, B<error>,
+otherwise returns a hash reference with a single key, B<custpaybynum>.
+
 =item delete_payby HASHREF
 
 Removes stored payment information.  Takes a hash reference with two keys,