#!/usr/bin/php '', 'VCardId' => '', 'Request' => '', 'Version' => '3.0', 'IssuerId' => '1', 'Locale' => 'fr', 'Trigger' => 'trigger', 'IE' => 'false', ); protected $_startTime = 0; public function __construct() { HTTP_query::$headers['Referer'] = 'https://www.service-virtualis.com/'; HTTP_query::$headers['User-Agent'] = 'Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.1.16) Gecko/20110107 Iceweasel/3.5.16 (like Firefox/3.5.16)'; $this->_startTime = time(); } protected function _requestAPI($request, $options) { $data = array( 'Request' => $request, 'startTime' => time() - $this->_startTime, ); $data = array_merge($data, $options); $data = array_merge($this->request_data, $data); $data = array_merge($this->request_data, $data); list($headers, $body) = HTTP_query::query('POST', $this->api_url, $this->cookies, $data); if ($headers['_code'] != 200) { throw new Exception("Invalid code: ".$headers['_code']); } $this->cookies = $headers['_cookies']; $data = array(); parse_str($body, &$data); return $data; } public function login($login, $password) { $data = $this->_requestAPI('GetActiveCards', array( 'motDePasse'=> $password, 'noPersonne'=> $login, 'codeEFS' => '21', 'codeSi' => '001', ) ); $this->request_data['CardType'] = $data['CardType1']; $this->request_data['VCardId'] = $data['VCardId1']; $this->request_data['SessionId'] = $data['SessionId']; return $data['CardholderName1']; } public function listVirtualCards() { $data = $this->_requestAPI('GetActiveAccounts', array( 'Start' => '0', 'Next' => '20', ) ); if (empty($data['Action']) || $data['Action'] != 'ActiveAccounts') return false; $cards = array(); for ($i = 1; $i <= (int)$data['Total']; $i++) { $cards[$i] = array( 'amount' => floatval($data['UCumulativeLimit'.$i]), 'expiration' => $data['Expiry'.$i], 'number' => $data['PAN'.$i], 'code' => $data['AVV'.$i], 'left' => floatval($data['UOpenToBuy'.$i]), 'issued' => $data['IssueDate'.$i], 'details' => array(), ); foreach ($data as $key=>$v) { if (substr($key, - (int) strlen($i)) == $i) { $cards[$i]['details'][$key] = $v; } } } return $cards; } public function createVirtualCard($amount, $validity_months) { $data = $this->_requestAPI('GetCPN', array( 'TransLimit' => '', 'CumulativeLimit' => strval(floatval($amount)), 'ValidFor' => (string)(int)$validity_months, 'CPNType' => 'SP', ) ); return array( 'amount' => (float)$amount, 'expiration' => $data['Expiry'], 'number' => $data['PAN'], 'code' => $data['AVV'], ); } public function deleteVirtualCard($number) { $data = $this->_requestAPI('CancelCPN', array( 'CPNPAN' => $number, ) ); if ($data['Action'] == 'CancelCPN') return true; print_r($data); return false; } public function listLastTransactions() { $data = $this->_requestAPI('GetPastTransactions', array( 'Start' => '0', 'Next' => '20', ) ); $out = array(); if ($data['RecordCount'] > 0) { for ($i = 1; $i <= $data['RecordCount']; $i++) { $out[] = array( 'card_number' => $data['PAN'.$i], 'merchant_name' => $data['MerchantName'.$i], 'merchant_city' => $data['MerchantCity'.$i], 'date' => $data['TransactionDate'.$i], 'amount' => (float) substr($data['TransactionAmount'.$i], 1), ); } } return $out; } } $ecb = new Virtualis_CB; echo "Login : "; system('stty echo'); $login = trim(fgets(STDIN)); echo "Mot de passe : "; system('stty -echo'); $password = trim(fgets(STDIN)); system('stty echo'); // add a new line since the users CR didn't echo echo "\n"; $name = $ecb->login($login, $password); echo "Login OK, bienvenue $name !\n"; menu: echo "--\n"; echo "Choisir 'c' pour créer une nouvelle carte virtuelle.\n"; echo "Choisir 'l' pour lister les cartes existantes.\n"; echo "Choisir 't' pour lister les dernières transactions.\n"; echo "Choix : "; system('stty echo'); $choice = trim(fgets(STDIN)); if ($choice == 'l') { $cards = $ecb->listVirtualCards(); if (!$cards) { echo "Déconnecté.\n"; exit; } echo "--\n"; if (count($cards) == 0) echo "Aucune carte active.\n"; else { if (count($cards) == 1) echo "1 carte active.\n"; else echo count($cards) . " cartes actives.\n"; echo "--\n"; foreach ($cards as $i=>$card) { echo "$i.\t"; echo str_pad(substr($card['number'], -4), strlen($card['number']), '*', STR_PAD_LEFT); echo "\t"; echo ($card['amount'] - $card['left']) . ' € / '.$card['amount']." €\t"; echo "Créée le ".$card['issued']."\t"; echo "Expire le ".$card['expiration']."\n"; } echo "--\n"; echo "Sélectionnez un numéro de carte pour voir les détails.\n"; echo "Choisir 'd [numéro de carte]' pour supprimer une carte.\n"; echo "Toute autre touche retourne au menu.\n"; menu_liste: echo "Choix : "; system('stty echo'); $choice = trim(fgets(STDIN)); if (is_numeric($choice)) { print_r($cards[$choice]); } elseif (preg_match('!^[ds]\s+(\d+)$!', $choice, $match)) { $ecb->deleteVirtualCard($cards[$match[1]]['number']); } else { goto menu; } goto menu_liste; } } elseif ($choice == 't') { $transactions = $ecb->listLastTransactions(); foreach ($transactions as $t) { echo "\tCarte n° ".$t['card_number']."\n"; echo "\tMarchand : ".$t['merchant_name']." (".$t['merchant_city'].")\n"; echo "\tDate : ".$t['date']."\n"; echo "\tMontant : ".$t['amount']." €\n"; echo "\t--\n"; } goto menu; } elseif ($choice == 'c') { echo "Montant en euros : "; system('stty echo'); $amount = floatval(trim(fgets(STDIN))); echo "Validité en mois : "; system('stty echo'); $months = intval(trim(fgets(STDIN))); $card = $ecb->createVirtualCard($amount, $months); echo "--\n"; echo "Nouvelle carte créée !\n"; echo "Montant maximum : ".$card['amount']." €\n"; echo "Numéro : ".$card['number']."\n"; echo "Expiration : ".$card['expiration']."\n"; echo "Code de vérification : ".$card['code']."\n"; } else { die("Quitte.\n"); } goto menu; ?>