From 8f1188e8550992bf3d9078e7a6042420eaf92bd5 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Tue, 3 Oct 2017 11:15:51 -0400 Subject: [PATCH] RT# 77193 - updated selfservice change payment accounts to work with version 4 --- FS/FS/ClientAPI/MyAccount.pm | 1 + .../FS-SelfService/cgi/myaccount_menu.html | 7 +- fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 87 +++++++++++++++++++--- 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index a10a45285..30ab96b49 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -882,6 +882,7 @@ sub payment_info { if ($cust_payby) { $return{payname} = $cust_payby->payname || ( $cust_main->first. ' '. $cust_main->get('last') ); + $return{custpaybynum} = $cust_payby->custpaybynum; if ( $cust_payby->payby =~ /^(CARD|DCRD)$/ ) { $return{card_type} = cardtype($cust_payby->payinfo); diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html b/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html index 6af5e5ec0..1bc35e34c 100644 --- a/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html +++ b/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html @@ -93,9 +93,10 @@ push @menu, unless ( $access_pkgnum ) { push @menu, - { title=>'Change billing address', url=>'change_bill', indent=>2 }, - { title=>'Change service address', url=>'change_ship', indent=>2 }, - { title=>'Change payment information', url=>'change_pay', indent=>2 }, + { title=>'Change billing address', url=>'change_bill', indent=>2 }, + { title=>'Change service address', url=>'change_ship', indent=>2 }, + { title=>'Change credit card information', url=>'change_creditcard_pay', indent=>2 }, + { title=>'Change check information', url=>'change_check_pay', indent=>2 }, ; } diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index cd9e32c78..f194746c5 100755 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -12,8 +12,8 @@ use Date::Format; use Date::Parse 'str2time'; use Number::Format 1.50; use FS::SelfService qw( - access_info login_info login customer_info edit_info invoice - payment_info process_payment realtime_collect process_prepay + access_info login_info login customer_info edit_info insert_payby update_payby + invoice payment_info process_payment realtime_collect process_prepay list_pkgs order_pkg signup_info order_recharge part_svc_info provision_acct provision_external provision_phone provision_forward unprovision_svc change_pkg suspend_pkg domainselector @@ -59,6 +59,10 @@ my @actions = ( qw( change_bill change_ship change_pay + change_creditcard_pay + change_check_pay + process_change_creditcard_pay + process_change_check_pay process_change_bill process_change_ship process_change_pay @@ -261,19 +265,30 @@ sub myaccount { customer_info( 'session_id' => $session_id ); } -sub change_bill { my $payment_info = - payment_info( 'session_id' => $session_id ); - return $payment_info if ( $payment_info->{'error'} ); - my $customer_info = - customer_info( 'session_id' => $session_id ); - return { - %$payment_info, - %$customer_info, - }; - } +sub change_bill { + my $payby = shift; + my $payment_info; + if ($payby) { + $payment_info = payment_info( 'session_id' => $session_id, 'payment_payby' => $payby, ); + } + else { + $payment_info = payment_info( 'session_id' => $session_id, ); + } + + return $payment_info if ( $payment_info->{'error'} ); + my $customer_info = + customer_info( 'session_id' => $session_id ); + return { + %$payment_info, + %$customer_info, + }; +} sub change_ship { change_bill(@_); } sub change_pay { change_bill(@_); } +sub change_creditcard_pay { change_bill('CARD'); } +sub change_check_pay { change_bill('CHEK'); } + sub _process_change_info { my ($erroraction, @fields) = @_; @@ -298,6 +313,30 @@ sub _process_change_info { } } +sub _process_change_payby { + my ($erroraction, @fields) = @_; + + my $results = ''; + + $results ||= update_payby ( + 'session_id' => $session_id, + map { ($_ => $cgi->param($_)) } grep { defined($cgi->param($_)) } @fields, + ); + + + if ( $results->{'error'} ) { + no strict 'refs'; + $action = $erroraction; + return { + $cgi->Vars, + %{&$action()}, + 'error' => ''. $results->{'error'}. '', + }; + } else { + return $results; + } +} + sub process_change_bill { _process_change_info( 'change_bill', qw( first last company address1 address2 city state @@ -342,6 +381,30 @@ sub process_change_pay { _process_change_info( 'change_pay', @list ); } +sub process_change_creditcard_pay { + my $payby = $cgi->param( 'payby' ); + $cgi->param('paydate', $cgi->param('year') . '-' . $cgi->param('month') . '-01'); + my @list = + qw( payby payinfo payinfo1 payinfo2 paydate payname custpaybynum + address1 address2 city county state zip country auto paytype + paystate ss stateid stateid_state invoicing_list + ); + + _process_change_payby( 'change_creditcard_pay', @list ); +} + +sub process_change_check_pay { + my $payby = $cgi->param( 'payby' ); + $cgi->param('paydate', $cgi->param('year') . '-' . $cgi->param('month') . '-01'); + my @list = + qw( payby payinfo payinfo1 payinfo2 paydate payname custpaybynum + address1 address2 city county state zip country auto paytype + paystate ss stateid stateid_state invoicing_list + ); + + _process_change_payby( 'change_check_pay', @list ); +} + sub view_invoice { $cgi->param('invnum') =~ /^(\d+)$/ or die "illegal invnum"; -- 2.11.0