Last active
August 3, 2023 09:05
-
-
Save najathi/44bf096751a3111e1eeaf9bdd0b0d5ea to your computer and use it in GitHub Desktop.
Recyle Order - Bank Validation API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="mb-3"> | |
<p class="h6 mt-3 pb-0 mb-2">Bank Account</p> | |
<hr class="mb-3 mt-0"> | |
<div class="row"> | |
<input type="hidden" name="isBankValidate" id="isBankValidate" value="0"> | |
<input type="hidden" name="bank_branch" id="bank_branch" value=""> | |
<input type="hidden" name="bank_institute" id="bank_institute" value=""> | |
<div class="col-md-4 col-xs-12"> | |
<div class="form-group"> | |
<label for="country">Sort Code</label> | |
<input type="number" class="form-control" name="sort_code" id="sort_code"> | |
</div> | |
</div> | |
<div class="col-md-4 col-xs-12"> | |
<div class="form-group"> | |
<label for="country">Account Number</label> | |
<input type="number" class="form-control" name="account_number" | |
id="account_number"> | |
</div> | |
</div> | |
<div class="col-md-4 col-xs-12"> | |
<div class="form-group"> | |
<label for="country"> </label> | |
<button class="btn btn-outline-primary twoToneButton bank-verify-btn" id="check_bank" | |
onclick="UserAction()" type="button"></i>VERIFY MY BANK DETAILS | |
<i class='fa fa-search' aria-hidden='true'></i> | |
</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script> | |
function UserAction() { | |
var twoToneButton = document.querySelector('.twoToneButton'); | |
let short = $('#sort_code').val(); | |
let account = $('#account_number').val(); | |
let route_url = "{{route('check_bank',[':short', ':account']) }}"; | |
route_url = route_url.replace(':short', short); | |
route_url = route_url.replace(':account', account); | |
if (short == "" || account == "") { | |
if (short == "") { | |
display_toast('error', "Short Code must be required."); | |
return; | |
} | |
if (account == "") { | |
display_toast('error', "Account Number must be required."); | |
return; | |
} | |
} else { | |
isLoadingSpannierBank(true); | |
$.ajax({ | |
headers: { | |
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
}, | |
type: 'get', | |
url: route_url, | |
cache: false, | |
success: function (result) { | |
twoToneButton.classList.remove('loading'); | |
console.log('result', result); | |
if (result.resultCode == "01") { | |
display_toast('success', result.resultDescription); | |
// set the value | |
$('#isBankValidate').val('1'); | |
$('#bank_institute').val(result.accountProperties.institution); | |
$('#bank_branch').val(result.accountProperties.branch); | |
} else { | |
display_toast('error', result.resultDescription); | |
$('#isBankValidate').val('0'); | |
} | |
isLoadingSpannierBank(false); | |
}, | |
error: function (xhr) { | |
console.log('xhr', xhr) | |
isLoadingSpannierBank(false); | |
} | |
}); | |
isLoadingSpannierBank(false); | |
} | |
} | |
function isLoadingSpannierBank(res) { | |
var twoToneButton = document.querySelector('.twoToneButton'); | |
if (res) { | |
$("button#check_bank").prop('disabled', true); | |
twoToneButton.classList.add('loader-btn'); | |
$(".twoToneButton").text("loading..."); | |
$("button#check_bank").append(`<i class='fa fa-circle-o-notch fa-spin' style='padding-left: 20px; padding-right:20px;'></i>`); | |
} else { | |
$("button#check_bank").prop('disabled', false); | |
twoToneButton.classList.remove('loader-btn'); | |
$(".twoToneButton").text("VERIFY MY BANK DETAILS"); | |
$("button#check_bank").append(` <i class='fa fa-search' aria-hidden='true'></i>`); | |
} | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// validate | |
public function bank_check($short, $account) | |
{ | |
$bank_v_access_key = env('BANK_ACCOUNT_CHECK_KEY'); | |
$bank_v_password = env('BANK_ACCOUNT_CHECK_PASSWORD'); | |
$sort_code = $short; | |
$account_number = $account; | |
$client = new Client(['base_uri' => 'https://tls.bankaccountchecker.com']); | |
$res = $client->request('GET', '/listener.php', [ | |
'headers' => [ | |
'Content-Type' => 'application/json', | |
], | |
'query' => [ | |
'key' => $bank_v_access_key, | |
'password' => $bank_v_password, | |
'output' => 'json', | |
'type' => 'uk_bankaccount', | |
'sortcode' => $sort_code, | |
'bankaccount' => $account_number, | |
], | |
'connect_timeout' => 10, | |
]); | |
$bank_info = json_decode($res->getBody()); | |
return response()->json($bank_info, 200); | |
} | |
// save order | |
public function save_order(Request $request) | |
{ | |
$messages = [ | |
'sort_code.digits_between' => 'sort code must be 6 digit', | |
'account_number.digits_between' => 'Account number must be 8 digit' | |
]; | |
$validator = Validator::make($request->all(), [ | |
'firstName' => 'required', | |
'lastName' => 'required', | |
'email' => 'required', | |
'country' => 'required', | |
'city' => 'required', | |
'postcode' => 'required', | |
'sort_code' => 'required|digits_between:6,6', | |
'account_number' => 'required|digits_between:8,8', | |
'payment_method' => 'required', | |
], $messages); | |
if ($validator->fails()) { | |
return $validator->errors()->first(); | |
} | |
$bank_v_access_key = env('BANK_ACCOUNT_CHECK_KEY'); | |
$bank_v_password = env('BANK_ACCOUNT_CHECK_PASSWORD'); | |
$sort_code = $request->sort_code; | |
$account_number = $request->account_number; | |
$client = new Client(['base_uri' => 'https://tls.bankaccountchecker.com']); | |
try { | |
$res = $client->request('GET', '/listener.php', [ | |
'headers' => [ | |
'Content-Type' => 'application/json', | |
], | |
'query' => [ | |
'key' => $bank_v_access_key, | |
'password' => $bank_v_password, | |
'output' => 'json', | |
'type' => 'uk_bankaccount', | |
'sortcode' => $sort_code, | |
'bankaccount' => $account_number, | |
], | |
'connect_timeout' => 10, | |
]); | |
$bank_info = json_decode($res->getBody()); | |
if ($bank_info->resultCode == "01") { | |
// bank account number is valid result | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::get('check_bank/{short}/{account}', 'Website\OrderController@bank_check')->name('check_bank'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment