forked from Mastercard-Gateway/simplify-php-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paymentForm.php
208 lines (195 loc) · 6.31 KB
/
paymentForm.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html data-wf-site="5582f9e5792714e458bb85b8" data-wf-page="5582f9e5792714e458bb85b9">
<head>
<meta charset="utf-8">
<title>Simplify Test Payment Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="css/webflow.css">
<link rel="stylesheet" type="text/css" href="css/simplify-test.webflow.css">
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js"></script>
<script>
WebFont.load({
google: {
families: ["Inconsolata:400,400italic,700,700italic"]
}
});
</script>
<script type="text/javascript" src="js/modernizr.js"></script>
<link rel="apple-touch-icon" href="//daks2k3a4ib2z.cloudfront.net/img/webclip.png">
<style>
body {
font-family: 'Avenir Next', Avenir, 'Helvetica Neue', Helvetica, Arial, sans-serif;
text-rendering: optimizeLegibility;
}
h1 {
font-family: 'Avenir Next', Avenir, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.footer-section {
margin-top: 10px;
}
.error {
color: red;
}
.success {
color: green;
}
.message {
margin-top: 50px;
}
.w-button {
background-color: #f60;
border-radius: 3px;
}
.busy-container {
display: none;
}
</style>
<?php
$publicKey = getenv('SIMPLIFY_API_PUBLIC_KEY');
?>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="//www.simplify.com/commerce/v1/simplify.js"></script>
<script type="text/javascript">
var $error, $success, $paymentBtn, $busyContainer;
$(document).ready(function () {
var $selYear = $('#cc-exp-year');
$error = $(".error");
$success = $(".success");
$paymentBtn = $("#process-payment-btn");
$busyContainer = $('.busy-container');
var currentYear = new Date().getFullYear();
for (var year = currentYear; year < currentYear + 10; year++) {
$selYear.append("<option " + ((year === (currentYear + 1)) ? " selected " : "") + " value='" + year.toString().substr(2) + "'>" + year + "</option>");
}
$paymentBtn.click(function () {
$busyContainer.fadeIn();
$error.fadeOut().html("");
$success.fadeOut().html("");
// Disable the submit button
$paymentBtn.attr("disabled", "disabled");
// Generate a card token & handle the response
SimplifyCommerce.generateToken({
key: "<?echo $publicKey?>",
card: {
number: $("#cc-number").val(),
cvc: $("#cc-cvc").val(),
expMonth: $("#cc-exp-month").val(),
expYear: $("#cc-exp-year").val()
}
}, simplifyResponseHandler);
});
});
function simplifyResponseHandler(data) {
$busyContainer.fadeOut();
$paymentBtn.removeAttr("disabled");
if (data.error) {
console.error("Error creating card token", data);
if (data.error.code == "validation") {
var fieldErrors = data.error.fieldErrors,
fieldErrorsLength = fieldErrors.length,
errorMessage = "";
for (var i = 0; i < fieldErrorsLength; i++) {
errorMessage += " Field: '" + fieldErrors[i].field +
"' is invalid - " + fieldErrors[i].message + "<br/>";
}
$error.html(errorMessage).fadeIn();
}
} else {
var token = data["id"];
var amount = $('#amount').val();
var request = $.ajax({
url: "/charge.php",
type: "POST",
data: { simplifyToken: token, amount: amount}
});
request.done(function (response) {
console.log("Response = ", response);
if (response.id) {
$success.html("Payment successfully processed & payment id = " + response.id + " !").fadeIn();
}
else if (response.status) {
$error.html("Payment failed with status = " + response.status + " !").fadeIn();
}
else {
$error.html("Payment failed with response... <br/> " + JSON.stringify(response)).fadeIn();
}
});
request.fail(function (jqXHR, status) {
console.error('Payment processing failed = ', jqXHR, status);
});
}
}
</script>
</head>
<body>
<div class="w-container message">
<div>
<h1 class="main-message">Run Test Payments on Simplify Commerce</h1>
</div>
<form role="form" class="w-form" id="simplify-payment-form">
<table width="100%">
<tr>
<td><label class="text">Amount in cents (i.e. 50 = $0.50): </label></td>
<td><label class="text"><input id="amount" class="w-input" type="text" maxlength="10" autocomplete="off"
value="100" autofocus
placeholder="Enter Amount"/>
</label></td>
</tr>
<tr>
<td><label class="text">Credit Card Number: </label></td>
<td>
<input id="cc-number" type="text" class="w-input" maxlength="20" autocomplete="off"
value="5555555555554444"/>
</label></td>
</tr>
<tr>
<td><label class="text">CVC: </label></td>
<td>
<input id="cc-cvc" type="text" class="w-input" maxlength="4" autocomplete="off" value="123"/>
</label></td>
</tr>
<tr>
<td><label class="text">Expiry Date: </label></td>
<td>
<select id="cc-exp-month" class="w-select">
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select id="cc-exp-year" class="w-select">
</select>
</tr>
<tr>
<td></td>
<td>
<button id="process-payment-btn" class="w-button">Run Test Payment</button>
</td>
</tr>
</table>
<div class="footer-section">
<div class="busy-container"><img src="images/ajax-loader.gif"/></div>
<div class="success"></div>
<div class="error"></div>
<div class="text">For more test cards, please checkout this <a class="link" target="_new"
href="https://www.simplify.com/commerce/docs/tutorial/index#testing">page.</a>
</div>
</div>
</form>
</div>
<div class="w-section footer-section">
<div class="logo-container"><img class="logo" src="images/simplifyLogo@2x.png" width="102">
</div>
</div>
</body>
</html>