default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / ng_selfservice / payment_only_payment.php
1 <? $title ='Make A Payment'; include('elements/header.php'); ?>
2 <? $current_menu = 'payment_only_payment.php'; include('elements/payment_only_menu.php'); ?>
3
4 <?
5
6 if ( isset($_POST['amount']) && $_POST['amount'] ) {
7
8   $payment_results = $freeside->payment_only_process_payment(array(
9     'session_id' => $_COOKIE['session_id'],
10     'payby'      => $_POST['payby'],
11     'amount'     => $_POST['amount'],
12     'paybatch'   => $_POST['paybatch'],
13     //'discount_term' => $discount_term,
14   ));
15
16   if ( $payment_results['error'] ) {
17     $error = $payment_results['error'];
18   } else {
19     $receipt_html = $payment_results['receipt_html'];
20   }
21
22 }
23
24 #echo print_r($payment_results);
25
26 if ( $receipt_html ) { 
27 ?>
28
29   Your payment was processed successfully.  Thank you.<BR><BR>
30   <? echo $receipt_html; ?>
31
32 <? } else {
33
34   $payment_info = $freeside->payment_only_payment_info( array(
35     'session_id' => $_COOKIE['session_id'],
36   ) );
37
38   if ( isset($payment_info['error']) && $payment_info['error'] ) {
39     $error = $payment_info['error'];
40     // possible to just keep on this page
41     header('Location:payment_only_error.php?error='. urlencode($error));
42     die();
43   }
44
45   extract($payment_info);
46
47   $tr_amount_fee = $freeside->payment_only_mason_comp(array(
48       'session_id' => $_COOKIE['session_id'],
49       'comp'       => '/elements/tr-amount_fee.html',
50       'args'       => [ 'amount',  $balance ],
51   ));
52   //$tr_amount_fee = $tr_amount_fee->{'error'} || $tr_amount_fee->{'output'};
53   $tr_amount_fee = $tr_amount_fee['output'];
54
55  ?>
56
57   <? include('elements/error.php'); ?>
58
59   <SCRIPT TYPE="text/javascript">
60
61       function payby_changed(what) {
62         var amount = document.getElementById('amount');
63         var amountdue = document.getElementById('amountdue');
64         var surcharge_cell = document.getElementById('ajax_surcharge_cell');
65         var surcharge_percentage = document.getElementById('surcharge_percentage');
66         var surcharge_flatfee = document.getElementById('surcharge_flatfee');
67         if (what.value == "CHEK") {
68           surcharge_cell.style.display = 'none';
69           amount.value = amountdue.value;
70
71         }
72         else if (what.value == "CARD") {
73                 surcharge_cell.style.display = 'inline';
74                 amount.value = (+amountdue.value + (+amountdue.value * +surcharge_percentage.value) + +surcharge_flatfee.value).toFixed(2);
75         }
76       }
77
78     </SCRIPT>
79
80   <FORM NAME="OneTrueForm" METHOD="POST" ACTION="payment_only_payment.php" onSubmit="document.OneTrueForm.process.disabled=true">
81
82   <TABLE>
83
84   <TR>
85         <TD ALIGN="right"><B>Payment account</B></TD>
86         <TD COLSPAN=7>
87           <SELECT ID="payby" NAME="payby" onChange="payby_changed(this)">
88 <? if ($CARD) { ?>
89          <OPTION VALUE="CARD"><? echo $card_type ?> <? echo $card_mask ?></OPTION>
90 <? } ?>
91 <? if ($CHEK) { ?>
92          <OPTION VALUE="CHEK"><? echo $check_type ?> <? echo $check_mask ?></OPTION>
93 <? } ?>                 
94           </SELECT>
95         </TD>
96   </TR>
97         
98   <TR>
99     <TD ALIGN="right"><B>Amount&nbsp;Due</B></TD>
100     <TD COLSPAN=7>
101       <TABLE><TR><TD>
102         $<? echo sprintf("%.2f", $balance) ?>
103         <INPUT TYPE=hidden NAME="amountdue" ID="amountdue" VALUE="<? echo sprintf("%.2f", $balance) ?>" >
104       </TD></TR></TABLE>
105     </TD>
106   </TR>
107
108   <? echo $tr_amount_fee; ?>
109
110   </TABLE>
111   <BR>
112   <INPUT TYPE="hidden" NAME="paybatch" VALUE="<? echo $paybatch ?>">
113   <INPUT TYPE="submit" NAME="process" VALUE="Process payment"> <!-- onClick="this.disabled=true"> -->
114   </FORM>
115
116 <? } ?>
117 <? include('elements/menu_footer.php'); ?>
118 <? include('elements/footer.php'); ?>