ba5cd88d9f69c9e939134f8e7ceda303a0c04d63
[freeside.git] / fs_selfservice / wordpress / payment_cc.php
1 <?php
2
3 require( dirname( __FILE__ ) . '/wp-blog-header.php' );
4
5 $freeside = new FreesideSelfService();
6
7 if ( isset($_POST['amount']) && $_POST['amount'] ) {
8
9   $payment_results = $freeside->process_payment(array(
10     'session_id' => $_COOKIE['freeside_session_id'],
11     'payby'      => 'CARD',
12     'amount'     => $_POST['amount'],
13     'payinfo'    => $_POST['payinfo'],
14     'paycvv'     => $_POST['paycvv'],
15     'month'      => $_POST['month'],
16     'year'       => $_POST['year'],
17     'payname'    => $_POST['payname'],
18     'address1'   => $_POST['address1'],
19     'address2'   => $_POST['address2'],
20     'city'       => $_POST['city'],
21     'state'      => $_POST['state'],
22     'zip'        => $_POST['zip'],
23     'country'    => $_POST['country'],
24     'save'       => $_POST['save'],
25     'auto'       => $_POST['auto'],
26     'paybatch'   => $_POST['paybatch'],
27     //'discount_term' => $discount_term,
28   ));
29
30   if ( $payment_results['error'] ) {
31     $_REQUEST['freeside_error'] = $payment_results['error'];
32   } else {
33     $receipt_html = $payment_results['receipt_html'];
34   }
35
36 }
37
38 if ( $receipt_html ) { ?>
39
40   Your payment was processed successfully.  Thank you.<BR><BR>
41   <?php echo $receipt_html; ?>
42
43 <?php } else {
44
45   $payment_info = $freeside->payment_info( array(
46     'session_id' => $_COOKIE['freeside_session_id'],
47     'payment_payby' => 'CARD',
48   ) );
49
50   if ( isset($payment_info['error']) && $payment_info['error'] ) {
51     $error = $payment_info['error'];
52     wp_redirect('example_login.php?freeside_error='. urlencode($error));
53     die();
54   }
55
56   extract($payment_info);
57
58   $tr_amount_fee = $freeside->mason_comp(array(
59       'session_id' => $_COOKIE['freeside_session_id'],
60       'comp'       => '/elements/tr-amount_fee.html',
61       'args'       => [ 'amount',  $balance ],
62   ));
63   //$tr_amount_fee = $tr_amount_fee->{'error'} || $tr_amount_fee->{'output'};
64   $tr_amount_fee = $tr_amount_fee['output'];
65
66   ?>
67
68   <?php include('elements/error.php'); ?>
69
70   <FORM NAME="OneTrueForm" METHOD="POST" ACTION="payment_cc.php" onSubmit="document.OneTrueForm.process.disabled=true">
71
72   <TABLE>
73   <TR>
74     <TD ALIGN="right">Amount&nbsp;Due</TD>
75     <TD COLSPAN=7>
76       <TABLE><TR><TD>
77         $<?php echo sprintf("%.2f", $balance) ?>
78       </TD></TR></TABLE>
79     </TD>
80   </TR>
81
82   <?php echo $tr_amount_fee; ?>
83
84   <TR>
85     <TD ALIGN="right">Card&nbsp;type</TD>
86     <TD COLSPAN=7>
87       <SELECT NAME="card_type"><OPTION></OPTION>
88         <?php foreach ( $card_types AS $ct ) { ?>
89           <OPTION <?php if ( $card_type == $ct ) { echo 'SELECTED'; } ?>
90                   VALUE="<?php echo $ct; ?>"><?php echo $ct; ?>
91         <?php } ?>
92       </SELECT>
93     </TD>
94   </TR>
95
96   <?php include('elements/card.php'); ?>
97
98   <TR>
99     <TD COLSPAN=8>
100       <INPUT TYPE="checkbox" <?php if ( ! $save_unchecked ) { echo 'CHECKED'; } ?> NAME="save" VALUE="1">
101       Remember this card and billing address
102     </TD>
103   </TR><TR>
104     <TD COLSPAN=8>
105       <INPUT TYPE="checkbox" <?php if ( $payby == 'CARD' ) { echo ' CHECKED'; } ?> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }">
106       Charge future payments to this card automatically
107     </TD>
108   </TR>
109   </TABLE>
110   <BR>
111   <INPUT TYPE="hidden" NAME="paybatch" VALUE="<?php echo $paybatch ?>">
112   <INPUT TYPE="submit" NAME="process" VALUE="Process payment"> <!-- onClick="this.disabled=true"> -->
113   </FORM>
114
115 <?php } ?>
116
117 <?php get_footer(); ?>