default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / misc / void-cust_pay.html
1 %if ( $success ) {
2 <& /elements/header-popup.html, mt("Payment voided") &>
3   <SCRIPT TYPE="text/javascript">
4     window.top.location.reload();
5   </SCRIPT>
6   </BODY>
7 </HTML>
8 %} else {
9 <& /elements/header-popup.html, mt('Void payment')  &>
10
11 <& /elements/error.html &>
12
13 <P ALIGN="center"><B><% mt('Void this payment?') |h %></B>
14 % if ( $cust_pay->payby =~ /^(CARD|CHEK)$/ ) {
15     <P ALIGN="center"><% mt('(Do not send anything to the payment gateway)') |h %>
16 % }
17
18 <FORM action="<% ${p} %>misc/void-cust_pay.html">
19 <INPUT TYPE="hidden" NAME="paynum" VALUE="<% $paynum %>">
20
21 <TABLE BGCOLOR="#cccccc" BORDER="0" CELLSPACING="2" STYLE="margin-left:auto; margin-right:auto">
22 <& /elements/tr-select-reason.html,
23              'field'          => 'reasonnum',
24              'reason_class'   => 'P',
25              'cgi'            => $cgi
26 &>
27 </TABLE>
28
29 <BR>
30 <P ALIGN="CENTER">
31 <INPUT TYPE="submit" NAME="confirm_void_payment" VALUE="<% mt('Void payment') |h %>"> 
32 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
33 <INPUT TYPE="BUTTON" VALUE="<% mt("Don't void payment") |h %>" onClick="parent.cClick();"> 
34
35 </FORM>
36 </BODY>
37 </HTML>
38
39 %}
40 <%init>
41
42 #untaint paynum
43 my $paynum = $cgi->param('paynum');
44 if ($paynum) {
45   $paynum =~ /^(\d+)$/ || die "Illegal paynum";
46 } else {
47   my($query) = $cgi->keywords;
48   $query =~ /^(\d+)/ || die "Illegal paynum";
49   $paynum = $1;
50 }
51
52 my $cust_pay = qsearchs('cust_pay',{'paynum'=>$paynum}) || die "Payment not found";
53
54 my $right = 'Void payments';
55 $right = 'Credit card void' if $cust_pay->payby eq 'CARD';
56 $right = 'Echeck void'      if $cust_pay->payby eq 'CHEK';
57
58 die "access denied"
59   unless $FS::CurrentUser::CurrentUser->access_right($right);
60
61 my $success = 0;
62 if ($cgi->param('confirm_void_payment')) {
63
64   #untaint reasonnum / create new reason
65   my ($reasonnum, $error) = $m->comp('process/elements/reason');
66   if (!$reasonnum) {
67     $error = 'Reason required';
68   } else {
69     my $reason = qsearchs('reason', { 'reasonnum' => $reasonnum })
70       || die "Reason num $reasonnum not found in database";
71         $error = $cust_pay->void($reason) unless $error;
72   }
73
74   if ($error) {
75     $cgi->param('error',$error);
76   } else {
77     $success = 1;
78   }
79 }
80
81 </%init>