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