-
Notifications
You must be signed in to change notification settings - Fork 0
/
vouchers.php
137 lines (119 loc) · 3.3 KB
/
vouchers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/** VOUCHERS.PHP
*
* Begins the voucher-orders
*
* @author Emily Sommer <[email protected]>
* @copyright 2011-2012 Patient Proxy
*
*/
// INCLUDES
require_once('extensions/stripe/lib/Stripe.php');
require_once('includes/header.php');
// PREPARE VARS
$legal_voucher = '';
$load_page = '';
$request_signature = '';
$refreshed = '';
$token = '';
$chargeAmount = '';
$charge = '';
$charged = '';
$valid_email = '';
$valid_mailing = '';
$error_message = '';
// CHECK REFRESH
$request_signature = md5($_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'].print_r($_POST, true));
if ( isset($_SESSION['last_request_sig']) && $_SESSION['last_request_sig'] == $request_signature ) {
$refreshed = true;
} else {
$refreshed = false;
$_SESSION['last_request_sig'] = $request_signature;
}
// STRIPE CHARGE
if ( isset($_POST['stripeToken'])
&& !empty($_POST['stripeToken'])
&& !$refreshed ) {
// make sure valid email & mailing first
if ( isset($_POST['emailaddress']) && !empty($_POST['emailaddress']) ) {
$valid_email = 'yes';
// add test for VALIDITY of email
//
//
} else {
$error_message .= '<br />Please provide a valid email address so we can contact you in case of problems with your order.';
}
if ( isset($_POST['mailingaddress']) && !empty($_POST['mailingaddress']) ) {
$valid_mailing = 'yes';
} else {
$error_message .= '<br />Please provide a valid mailing address to which we can send your order.';
}
if ( ($valid_email == 'yes') && ($valid_mailing == 'yes') ) {
// get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$chargeAmount = $_POST['chargeAmount'];
// set your secret key: remember to change this to your live secret key in production
// see your keys here https://manage.stripe.com/account
Stripe::setApiKey();
// create the charge on Stripe's servers - this will charge the user's card
$charge = Stripe_Charge::create(array(
"amount" => $chargeAmount, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => "[email protected]")
);
if ( $charge ) {
$charged = 'yes';
}
}
}
// CHECK $_POST & $_SESSION for legal
if ( isset($_POST['legal_voucher']) && $_POST['legal_voucher'] == 'agree' ) {
$legal_voucher = 'agree';
$_SESSION['legal_voucher'] = 'agree';
} else if ( isset($_SESSION['legal_voucher']) && $_SESSION['legal_voucher'] == 'agree' ) {
$legal_voucher = 'agree';
} else {
$legal_voucher = '';
}
// CHECK $_GET vars for navigation
if ( isset($_GET['page']) && !empty($_GET['page']) ) {
$load_page = str_replace('-', '_', $_GET['page']);
}
switch($load_page) {
case('legal'):
require_once('pages/voucher_legal.php');
break;
case('pay'):
if ( $legal_voucher == 'agree' ) {
require_once('pages/voucher_payment.php');
} else {
require_once('pages/voucher_legal.php');
}
break;
case('thanks'):
if ( $charged == 'yes' ) {
require_once('pages/voucher_thanks.php');
} else {
require_once('pages/voucher_payment.php');
}
break;
default:
require_once('pages/voucher_info.php');
break;
}
// CLEAR VARS
$page_load = '';
$legal_voucher = '';
$request_signature = '';
$refreshed = '';
$token = '';
$chargeAmount = '';
$charge = '';
$charged = '';
$valid_email = '';
$valid_mailing = '';
$error_message = '';
// END PAGE
require_once('includes/footer.php');
?>