forked from joaool/MotherGithub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_balanced2.html
211 lines (195 loc) · 11 KB
/
test_balanced2.html
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
209
210
211
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Balanced Sample Form</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="FL_ui/js/bootstrap.min.js"></script>
<link href="FL_ui/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://js.balancedpayments.com/1.1/balanced.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Callback for handling responses from Balanced
function handleResponse(response) {
// Successful tokenization
if (response.status_code === 201) {
var fundingInstrument = response.cards != null ? response.cards[0] : response.bank_accounts[0];
// Call your backend
jQuery.post("/path/to/your/backend", {
uri: fundingInstrument.href
}, function(r) {
// Check your backend response
if (r.status === 201) {
// Your successful logic here from backend ruby
} else {
// Your failure logic here from backend ruby
}
});
} else {
// Failed to tokenize, your error logic here
}
// Debuging, just displays the tokenization result in a pretty div
$('#response .panel-body pre').html(JSON.stringify(response, false, 4));
$('#response').slideDown(300);
}
// Click event for tokenize credit card
$('#cc-submit').click(function (e) {
e.preventDefault();
$('#response').hide();
var payload = {
name: $('#cc-name').val(),
number: $('#cc-number').val(),
expiration_month: $('#cc-ex-month').val(),
expiration_year: $('#cc-ex-year').val(),
cvv: $('#cc-cvv').val(),
address: {
postal_code: $('#ex-postal-code').val()
}
};
// Tokenize credit card
balanced.card.create(payload, handleResponse);
});
// Click event for tokenize bank account
$('#ba-submit').click(function (e) {
e.preventDefault();
$('#response').hide();
var payload = {
name: $('#ba-name').val(),
account_number: $('#ba-number').val(),
routing_number: $('#ba-routing').val(),
account_type: $('#ba-account-type').val()
};
// Tokenize bank account
balanced.bankAccount.create(payload, handleResponse);
});
// Simply populates credit card and bank account fields with test data
$('#populate').click(function () {
$(this).attr("disabled", true);
$('#cc-name').val('John Doe');
$('#cc-number').val('4111111111111111');
$('#cc-ex-month').val('12');
$('#cc-ex-year').val('2020');
$('#ex-csc').val('123');
$('#ex-postal-code').val('94301');
$('#ba-name').val('John Doe');
$('#ba-number').val('9900000000');
$('#ba-routing').val('321174851');
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="alert alert-info">
<p>Do not provide real credit card or bank account details into these forms. Instead use <a href="https://docs.balancedpayments.com/current/overview.html#test-credit-card-numbers" class="alert-link" target="_blank">test cards</a> and <a href="https://docs.balancedpayments.com/current/overview.html#test-bank-account-numbers" class="alert-link" target="_blank">bank accounts</a>.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<button type="button" id="populate" class="btn btn-default pull-right" style="margin-bottom: 20px;">Populate Test Data</button>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Tokenize Credit Card</h3>
</div>
<div class="panel-body">
<form role="form" class="form-horizontal">
<div class="form-group">
<label class="col-lg-5 control-label">Name on Card</label>
<div class="col-lg-5">
<input type="text" id="cc-name" class="form-control" autocomplete="off" placeholder="John Doe" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Card Number</label>
<div class="col-lg-5">
<input type="text" id="cc-number" class="form-control" autocomplete="off" placeholder="4111111111111111" maxlength="16" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Expiration</label>
<div class="col-lg-2">
<input type="text" id="cc-ex-month" class="form-control" autocomplete="off" placeholder="01" maxlength="2" />
</div>
<div class="col-lg-2">
<input type="text" id="cc-ex-year" class="form-control" autocomplete="off" placeholder="2013" maxlength="4" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Card Verification Value (CVV)</label>
<div class="col-lg-2">
<input type="text" id="cc-cvv" class="form-control" autocomplete="off" placeholder="453" maxlength="4" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Postal Code</label>
<div class="col-lg-2">
<input type="text" id="ex-postal-code" class="form-control" autocomplete="off" placeholder="12345" />
</div>
</div>
<a id="cc-submit" class="btn btn-large btn-primary pull-right">Tokenize</a>
</form>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Tokenize Bank Account</h3>
</div>
<div class="panel-body">
<form role="form" class="form-horizontal">
<div class="form-group">
<label class="col-lg-5 control-label">Account Holder's Name</label>
<div class="col-lg-6">
<input type="text" id="ba-name" class="form-control" autocomplete="off" placeholder="John Doe" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Routing Number</label>
<div class="col-lg-6">
<input type="text" id="ba-routing" class="form-control" autocomplete="off" placeholder="322271627" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Account Number</label>
<div class="col-lg-6">
<input type="text" id="ba-number" class="form-control" autocomplete="off" placeholder="9900000000" />
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Account Type</label>
<div class="col-lg-6">
<select id="ba-account-type" class="form-control">
<option value="checking">Checking</option>
<option value="savings">Savings</option>
</select>
</div>
</div>
<a id="ba-submit" class="btn btn-large btn-primary pull-right">Tokenize</a>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div id="response" class="col-lg-12" style="display: none;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Response</h3>
</div>
<div class="panel-body">
<pre></pre>
</div>
</div>
</div>
</div>
</div>
</body>
</html>