Last active
May 21, 2020 13:46
-
-
Save gerrgg/7bce684698b85e51d9ccc4b38990ad77 to your computer and use it in GitHub Desktop.
Uses the binlist.net API to return a card's type. Edit the return for even boarder details
This file contains 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 | |
function msp_get_card_type( $card_num ){ | |
/** | |
* Returns card type based on card number using public BIN API | |
* @param string $card_number | |
* @return string $card_type | |
*/ | |
$ch = curl_init(); | |
// clean white spaces | |
$card_num = preg_replace('/\s+/', '', $card_num); | |
$host = "https://lookup.binlist.net/" . substr($card_num, 0, 8); | |
curl_setopt($ch, CURLOPT_URL, $host); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$response = json_decode( curl_exec($ch) ); | |
return ucfirst( $response->scheme ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment