From d6b6f81e383f9d876e67e9704914e887a331012e Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 25 May 2009 01:49:34 +0000 Subject: [PATCH] international self-service payments, RT#1592 --- FS/FS/ClientAPI/MasonComponent.pm | 44 ++++++++++++++++- FS/FS/ClientAPI/MyAccount.pm | 7 +-- fs_selfservice/FS-SelfService/SelfService.pm | 55 +++++++++++++++++++++- fs_selfservice/FS-SelfService/cgi/card.html | 50 +++++--------------- .../FS-SelfService/cgi/make_payment.html | 16 +++---- .../FS-SelfService/cgi/misc/counties.cgi | 18 +++++++ fs_selfservice/FS-SelfService/cgi/misc/states.cgi | 18 +++++++ fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 2 +- httemplate/elements/location.html | 20 ++++---- httemplate/elements/select-county.html | 6 ++- 10 files changed, 169 insertions(+), 67 deletions(-) create mode 100755 fs_selfservice/FS-SelfService/cgi/misc/counties.cgi create mode 100755 fs_selfservice/FS-SelfService/cgi/misc/states.cgi diff --git a/FS/FS/ClientAPI/MasonComponent.pm b/FS/FS/ClientAPI/MasonComponent.pm index 78ea9bd4f..d158ce842 100644 --- a/FS/FS/ClientAPI/MasonComponent.pm +++ b/FS/FS/ClientAPI/MasonComponent.pm @@ -1,9 +1,13 @@ package FS::ClientAPI::MasonComponent; use strict; -use vars qw($DEBUG $me); +use vars qw( $cache $DEBUG $me ); +use subs qw( _cache ); use FS::Mason qw( mason_interps ); use FS::Conf; +use FS::ClientAPI_SessionCache; +use FS::Record qw(qsearchs); +use FS::cust_main; $DEBUG = 0; $me = '[FS::ClientAPI::MasonComponent]'; @@ -13,6 +17,24 @@ my %allowed_comps = map { $_=>1 } qw( /misc/areacodes.cgi /misc/exchanges.cgi /misc/phonenums.cgi + /misc/states.cgi + /misc/counties.cgi +); + +my %session_comps = map { $_=>1 } qw( + /elements/location.html +); + +my %session_callbacks = ( + '/elements/location.html' => sub { + my( $custnum, $argsref ) = @_; + my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) + or return "unknown custnum $custnum"; + my %args = @$argsref; + $args{object} = $cust_main; + @$argsref = ( %args ); + return ''; #no error + }, ); my $outbuf; @@ -24,12 +46,23 @@ sub mason_comp { warn "$me mason_comp called on $packet\n" if $DEBUG; my $comp = $packet->{'comp'}; - unless ( $allowed_comps{$comp} ) { + unless ( $allowed_comps{$comp} || $session_comps{$comp} ) { return { 'error' => 'Illegal component' }; } my @args = $packet->{'args'} ? @{ $packet->{'args'} } : (); + if ( $session_comps{$comp} ) { + + my $session = _cache->get($packet->{'session_id'}) + or return ( 'error' => "Can't resume session" ); #better error message + my $custnum = $session->{'custnum'}; + + my $error = &{ $session_callbacks{$comp} }( $custnum, \@args ); + return { 'error' => $error } if $error; + + } + my $conf = new FS::Conf; $FS::Mason::Request::FSURL = $conf->config('selfservice_server-base_url'); $FS::Mason::Request::QUERY_STRING = $packet->{'query_string'} || ''; @@ -43,4 +76,11 @@ sub mason_comp { } +#hmm +sub _cache { + $cache ||= new FS::ClientAPI_SessionCache( { + 'namespace' => 'FS::ClientAPI::MyAccount', + } ); +} + 1; diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index ab5096891..48a6ba940 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -506,7 +506,8 @@ sub process_payment { } my %payby2fields = ( - 'CARD' => [ qw( paystart_month paystart_year payissue address1 address2 city state zip payip ) ], + 'CARD' => [ qw( paystart_month paystart_year payissue payip + address1 address2 city state zip country ) ], 'CHEK' => [ qw( ss paytype paystate stateid stateid_state payip ) ], ); @@ -527,8 +528,8 @@ sub process_payment { my $new = new FS::cust_main { $cust_main->hash }; if ($payby eq 'CARD' || $payby eq 'DCRD') { $new->set( $_ => $p->{$_} ) - foreach qw( payname paystart_month paystart_year payissue payip - address1 address2 city state zip payinfo ); + foreach qw( payinfo payname paystart_month paystart_year payissue payip + address1 address2 city state zip country ); $new->set( 'payby' => $p->{'auto'} ? 'CARD' : 'DCRD' ); } elsif ($payby eq 'CHEK' || $payby eq 'DCHK') { $new->set( $_ => $p->{$_} ) diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 47f312ac0..058955037 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -86,8 +86,9 @@ $socket .= '.'.$tag if defined $tag && length($tag); ); @EXPORT_OK = ( keys(%autoload), - qw( regionselector regionselector_hashref - expselect popselector domainselector didselector ) + qw( regionselector regionselector_hashref location_form + expselect popselector domainselector didselector + ) ); $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin'; @@ -550,6 +551,10 @@ State Zip or postal code +=item country + +Two-letter country code + =item payinfo Card number @@ -1436,6 +1441,52 @@ sub regionselector_hashref { }; } +=item location_form HASHREF | LIST + +Takes as input a hashref or list of key/value pairs with the following keys: + +=over 4 + +=item session_id + +Current customer session_id + +=item no_asterisks + +Omit red asterisks from required fields. + +=item address1_label + +Label for first address line. + +=back + +Returns an HTML fragment for a location form (address, city, state, zip, +country) + +=cut + +sub location_form { + my $param; + if ( ref($_[0]) ) { + $param = shift; + } else { + $param = { @_ }; + } + + my $session_id = delete $param->{'session_id'}; + + my $rv = mason_comp( 'session_id' => $session_id, + 'comp' => '/elements/location.html', + 'args' => [ %$param ], + ); + + #hmm. + $rv->{'error'} || $rv->{'output'}; + +} + + #=item expselect HASHREF | LIST # #Takes as input a hashref or list of key/value pairs with the following keys: diff --git a/fs_selfservice/FS-SelfService/cgi/card.html b/fs_selfservice/FS-SelfService/cgi/card.html index cf6d20d8d..c7db2b398 100644 --- a/fs_selfservice/FS-SelfService/cgi/card.html +++ b/fs_selfservice/FS-SelfService/cgi/card.html @@ -1,11 +1,11 @@ - Card number - + Card number + - + - - - - - - - - - - - + + + +<%= location_form( 'session_id' => $session_id, + 'no_asterisks' => 1, + #'address1_label' => 'Card billing address', + 'address1_label' => 'Card billing address', + ) +%> diff --git a/fs_selfservice/FS-SelfService/cgi/make_payment.html b/fs_selfservice/FS-SelfService/cgi/make_payment.html index a468d998a..da6e67ed2 100644 --- a/fs_selfservice/FS-SelfService/cgi/make_payment.html +++ b/fs_selfservice/FS-SelfService/cgi/make_payment.html @@ -22,23 +22,23 @@
Exp.Exp.
Exact name on card
Card billing address - -
Address line 2 - -
City - - - - - - - - -
- - State - - Zip - -
-
Exact name on card
- - + - - + - - + <%= include('card') %> - - diff --git a/fs_selfservice/FS-SelfService/cgi/misc/counties.cgi b/fs_selfservice/FS-SelfService/cgi/misc/counties.cgi new file mode 100755 index 000000000..476fe09a4 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/misc/counties.cgi @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w + +use strict; +use CGI; +use FS::SelfService qw( mason_comp ); + +my $cgi = new CGI; + +my $rv = mason_comp( 'comp' => '/misc/counties.cgi', + 'query_string' => $cgi->query_string, #pass CGI params... + ); + +#hmm. +my $output = $rv->{'error'} || $rv->{'output'}; + +print $cgi->header( '-expires' => 'now' ). + $output; + diff --git a/fs_selfservice/FS-SelfService/cgi/misc/states.cgi b/fs_selfservice/FS-SelfService/cgi/misc/states.cgi new file mode 100755 index 000000000..f75f2ae1d --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/misc/states.cgi @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w + +use strict; +use CGI; +use FS::SelfService qw( mason_comp ); + +my $cgi = new CGI; + +my $rv = mason_comp( 'comp' => '/misc/states.cgi', + 'query_string' => $cgi->query_string, #pass CGI params... + ); + +#hmm. +my $output = $rv->{'error'} || $rv->{'output'}; + +print $cgi->header( '-expires' => 'now' ). + $output; + diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index ecf2553a3..4c7b1d86a 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -664,7 +664,7 @@ package FS::SelfService::_selfservicecgi; #use FS::SelfService qw(regionselector expselect popselector); use HTML::Entities; -use FS::SelfService qw(regionselector popselector domainselector); +use FS::SelfService qw(regionselector popselector domainselector location_form); #false laziness w/agent.cgi sub include { diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 6691bc84e..dbc567d4d 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -23,7 +23,7 @@ Example: NAME = "<%$pre%>address1" ID = "<%$pre%>address1" VALUE = "<% $object->get($pre.'address1') |h %>" - SIZE = 58 + SIZE = 54 onChange = "<% $onchange %>" <% $disabled %> <% $style %> @@ -38,7 +38,7 @@ Example: NAME = "<%$pre%>address2" ID = "<%$pre%>address2" VALUE = "<% $object->get($pre.'address2') |h %>" - SIZE = 58 + SIZE = 54 onChange = "<% $onchange %>" <% $disabled %> <% $style %> @@ -48,7 +48,7 @@ Example: - - - - - + + + @@ -82,7 +80,7 @@ Example: - + % if ( !$pre ) { @@ -126,7 +124,7 @@ my @counties = counties( $object->get($pre.'state'), $object->get($pre.'country'), ); my @county_style = (); -push @county_style, 'visibility:hidden' +push @county_style, 'display:none' # 'visibility:hidden' unless scalar(@counties) > 1; my $style = diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html index 59f235a23..aa88abe96 100644 --- a/httemplate/elements/select-county.html +++ b/httemplate/elements/select-county.html @@ -58,10 +58,12 @@ Example: if ( countiesArray.length > 1 ) { what.form.<% $pre %>county.style.display = ''; - countyFormLabel.style.visibility = 'visible'; + //countyFormLabel.style.visibility = 'visible'; + countyFormLabel.style.display = ''; } else { what.form.<% $pre %>county.style.display = 'none'; - countyFormLabel.style.visibility = 'hidden'; + //countyFormLabel.style.visibility = 'hidden'; + countyFormLabel.style.display = 'none'; } //run the callback -- 2.11.0
Amount Due + Amount Due
$<%=sprintf("%.2f",$balance)%>
Payment amount + Payment amount
$">
Card type + Card type
+ Remember this information
+ NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }"> Charge future payments to this card automatically
<%$r%>City + <% $style %> > - ><%$r%>County - <% include('/elements/select-county.html', %select_hash ) %> <%$r%>State + ><%$r%>County<% include('/elements/select-county.html', %select_hash ) %><%$r%>State <% include('/elements/select-state.html', %select_hash ) %> <%$r%>Zip
<%$r%>Country<% include('/elements/select-country.html', %select_hash ) %><% include('/elements/select-country.html', %select_hash ) %>