Skip to content

Instantly share code, notes, and snippets.

@gerrgg
Last active May 21, 2020 13:46
Show Gist options
  • Save gerrgg/7bce684698b85e51d9ccc4b38990ad77 to your computer and use it in GitHub Desktop.
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
<?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