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]';
/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;
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'} || '';
}
+#hmm
+sub _cache {
+ $cache ||= new FS::ClientAPI_SessionCache( {
+ 'namespace' => 'FS::ClientAPI::MyAccount',
+ } );
+}
+
1;
}
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 ) ],
);
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->{$_} )
);
@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';
Zip or postal code
+=item country
+
+Two-letter country code
+
=item payinfo
Card number
};
}
+=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:
<TR>
- <TD ALIGN="right">Card number</TD>
- <TD>
+ <TH ALIGN="right">Card number</TH>
+ <TD COLSPAN=6>
<TABLE>
<TR>
<TD>
<INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%=$payinfo%>"> </TD>
- <TD>Exp.</TD>
+ <TH>Exp.</TH>
<TD>
<SELECT NAME="month">
<%= for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) {
'';
%>
<TR>
- <TD ALIGN="right">Exact name on card</TD>
- <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%=$payname%>"></TD>
-</TR><TR>
- <TD ALIGN="right">Card billing address</TD>
- <TD>
- <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address1" VALUE="<%=$address1%>">
- </TD>
-</TR><TR>
- <TD ALIGN="right">Address line 2</TD>
- <TD>
- <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address2" VALUE="<%=$address2%>">
- </TD>
-</TR><TR>
- <TD ALIGN="right">City</TD>
- <TD>
- <TABLE>
- <TR>
- <TD>
- <INPUT TYPE="text" NAME="city" SIZE="12" MAXLENGTH=80 VALUE="<%=$city%>">
- </TD>
- <TD>State</TD>
- <TD>
- <SELECT NAME="state">
- <%= for ( @states ) {
- $OUT .= '<OPTION'. ($_ eq $state ? ' SELECTED' : '' ). ">$_\n";
- } %>
- </SELECT>
- </TD>
- <TD>Zip</TD>
- <TD>
- <INPUT TYPE="text" NAME="zip" SIZE=11 MAXLENGTH=10 VALUE="<%=$zip%>">
- </TD>
- </TR>
- </TABLE>
- </TD>
+ <TH ALIGN="right">Exact name on card</TH>
+ <TD COLSPAN=6><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%=$payname%>"></TD>
</TR>
+
+<%= location_form( 'session_id' => $session_id,
+ 'no_asterisks' => 1,
+ #'address1_label' => 'Card billing address',
+ 'address1_label' => 'Card billing address',
+ )
+%>
<INPUT TYPE="hidden" NAME="action" VALUE="payment_results">
<TABLE BGCOLOR="#cccccc">
<TR>
- <TD ALIGN="right">Amount Due</TD>
- <TD>
+ <TH ALIGN="right">Amount Due</TH>
+ <TD COLSPAN=7>
<TABLE><TR><TD BGCOLOR="#ffffff">
$<%=sprintf("%.2f",$balance)%>
</TD></TR></TABLE>
</TD>
</TR>
<TR>
- <TD ALIGN="right">Payment amount</TD>
- <TD>
+ <TH ALIGN="right">Payment amount</TH>
+ <TD COLSPAN=7>
<TABLE><TR><TD BGCOLOR="#ffffff">
$<INPUT TYPE="text" NAME="amount" SIZE=8 VALUE="<%=sprintf("%.2f",$balance)%>">
</TD></TR></TABLE>
</TD>
</TR><TR>
- <TD ALIGN="right">Card type</TD>
- <TD>
+ <TH ALIGN="right">Card type</TH>
+ <TD COLSPAN=7>
<SELECT NAME="card_type"><OPTION></OPTION>
<%= foreach ( keys %card_types ) {
$selected = $card_type eq $card_types{$_} ? ' SELECTED' : '';
</TR>
<%= include('card') %>
<TR>
- <TD COLSPAN=2>
+ <TD COLSPAN=8>
<INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1">
Remember this information
</TD>
</TR><TR>
- <TD COLSPAN=2>
+ <TD COLSPAN=8>
<INPUT TYPE="checkbox"<%= $payby eq 'CARD' ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
Charge future payments to this card automatically
</TD>
--- /dev/null
+#!/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;
+
--- /dev/null
+#!/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;
+
#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 {
NAME = "<%$pre%>address1"
ID = "<%$pre%>address1"
VALUE = "<% $object->get($pre.'address1') |h %>"
- SIZE = 58
+ SIZE = 54
onChange = "<% $onchange %>"
<% $disabled %>
<% $style %>
NAME = "<%$pre%>address2"
ID = "<%$pre%>address2"
VALUE = "<% $object->get($pre.'address2') |h %>"
- SIZE = 58
+ SIZE = 54
onChange = "<% $onchange %>"
<% $disabled %>
<% $style %>
<TR>
<TH ALIGN="right"><%$r%>City</TH>
- <TD>
+ <TD WIDTH="1">
<INPUT TYPE = "text"
NAME = "<%$pre%>city"
ID = "<%$pre%>city"
<% $disabled %>
<% $style %>
>
- </TD>
- <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
- <TD>
- <% include('/elements/select-county.html', %select_hash ) %>
</TD>
- <TH ALIGN="right"><%$r%>State</TH>
- <TD>
+ <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
+ <TD><% include('/elements/select-county.html', %select_hash ) %></TD>
+ <TH ALIGN="right" WIDTH="1"><%$r%>State</TH>
+ <TD WIDTH="1">
<% include('/elements/select-state.html', %select_hash ) %>
</TD>
<TH><%$r%>Zip</TH>
<TR>
<TH ALIGN="right"><%$r%>Country</TH>
- <TD COLSPAN=5><% include('/elements/select-country.html', %select_hash ) %></TD>
+ <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
</TR>
% if ( !$pre ) {
$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 =
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