From: Jonathan Prykop Date: Wed, 27 Jul 2016 04:46:01 +0000 (-0500) Subject: RT#38881: BILL illegal payby in 4.x [update_payby] X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=da5bcce2b8fdd32e5e9ab54523fc5e5a1705f1dd RT#38881: BILL illegal payby in 4.x [update_payby] --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index d767e910d..685821bad 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -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; diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm index 622f3df05..08c6c2d59 100644 --- a/FS/FS/ClientAPI_XMLRPC.pm +++ b/FS/FS/ClientAPI_XMLRPC.pm @@ -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 index 000000000..9815d0551 --- /dev/null +++ b/bin/xmlrpc-insert_payby @@ -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 index 000000000..75a1a8da9 --- /dev/null +++ b/bin/xmlrpc-update_payby @@ -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; diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index bc54b1ef3..3be4ebd8b 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -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, otherwise returns a hash reference with a single key, B. +=item update_payby HASHREF + +Updates stored payment information. Takes a hash reference with the same +keys as insert_payby, as well as B to specify which record +to update. All keys except B and B 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, +otherwise returns a hash reference with a single key, B. + =item delete_payby HASHREF Removes stored payment information. Takes a hash reference with two keys,