It is recommended to send the any confidential detail like bank detail or card detail to send to Stripe server and Stripe will return the token then you can send that token to you server and do the necessary operations.
Here In this article you will learn that how to create stripe account token in stripe.js for registering the bank account at Stripe and how can you verify bank account at Stripe.
Here is the HTML form, After filling the bank information when you click on Add bank button it will create the account token through the script main.js.
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
|
<form action="" method="POST" id="payment-form">
<span class="bank-errors" style="color:#de9183;"></span>
<div class="row s-content">
<div class="small-12 columns">
<div class="row">
<div class="small-8 columns">
<div class="group">
<input type="text" required="" data-stripe="country" class="country" size="20" maxlength="20" value='US'>
<label class="floating">Country</label>
</div>
</div>
<div class="small-8 columns">
<div class="group">
<input type="text" required="" data-stripe="currency" class="currency" value='USD'>
<label class="floating">Currency</label>
</div>
</div>
<div class="small-8 columns">
<div class="group">
<input type="text" required="" data-stripe="routing_number" class="routing_number" value='111000025'>
<label class="floating">Routing Number</label>
</div>
</div>
<div class="small-8 columns">
<div class="group">
<input type="text" required="" data-stripe="account_number" class="account_number" value='000123456789'>
<label class="floating">Acct Number</label>
</div>
</div>
<div class="small-8 columns">
<div class="group">
<input type="text" required="" data-stripe="account_holder_name" class="account_holder_name" value='Saurabh'>
<label class="floating">Account holder name</label>
</div>
</div>
<div class="small-8 columns">
<div class="group">
<!-- company/individual -->
<input type="text" required="" data-stripe="account_holder_type" class="account_holder_type" value='individual'>
<label class="floating">Account holder type</label>
</div>
</div>
</div>
</div>
<div class="small-12 columns">
<button class="btn-bg submit" type="submit">Add Bank</button>
</div>
</div>
</form>
<script scr="main.js"></script>
|
main.js
Here in main.js we authorize stripe client request through the publishable key. I have given a demo key you can replace it with your publishable key.
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
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script>
Stripe.setPublishableKey('pk_test_2836LfV12urisllZSk8q7X4Fr');$(function() {
var $form = $('#payment-form');
$form.submit(function(event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);// Request a token from Stripe:
Stripe.bankAccount.createToken($form, stripeResponseHandler);// Prevent the form from being submitted:
return false;
});
});
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem!
// Show the errors on the form:
$form.find('.bank-errors').text(response.error.message);
$form.find('button').prop('disabled', false); // Re-enable submission
} else { // Token created!
// Get the token ID:
var token = response.id;
// Insert the token into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// Submit the form:
$form.get(0).submit();
}
}
</script>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?php
if(!empty($_POST))
{
$customerResponse = \Stripe\Customer::create(array(
"source" => $_POST['stripeToken'],
"description" => "Saurabh Bank1"
));
$cutomerId = $customerResponse->id;
$bankId = $customerResponse->default_source;
// get the existing bank account
$customer = \Stripe\Customer::retrieve($cutomerId);
$bank_account = $customer->sources->retrieve($bankId);
// verify the account
$result = $bank_account->verify(array('amounts' => array(32, 45)));
echo '<tt><pre>'; echo var_export($result,TRUE); echo '</pre></tt>';
}
?>
|
After registering the bank account on Stripe you also would require to verify the bank account. I have given example of verifying the bank account by 2 transactions.