function createToken($tokenData){ $res = false; // проверка наличия всех полей foreach(array('IPN_CC_TOKEN', 'CARD_HOLDER_NAME', 'CARD_MASK', 'IPN_INFO', 'IPN_CC_EXP_DATE') as $one) { if(!array_key_exists($one, $tokenData)) die("missing value: " . $one); } $merchant = 'merchant'; $token = $_POST['IPN_CC_TOKEN']; $data = addSign(array('merchant' => $merchant, 'refNo' => $token)); $tokenInfo = json_decode(sendRequest($data), 1); if(isset($tokenInfo['meta']['status']['message']) && $tokenInfo['meta']['status']['message'] == 'success' && isset($tokenInfo['token'])){ $token = $data['token']; // сохранить токен в БД } return $res; }
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); $curlerrcode = curl_errno($ch); $curlerr = curl_error($ch); if($curlerrcode || $curlerr) { // обработать ошибки CURL & die } return curl_exec($ch); } $merchant = 'merchant'; $token = '1c82fc76364cb1eafa04f7225b16b1ae'; $data = addSign(array('merchant' => $merchant)); $history = json_decode(sendHistoryRequest($token, $data), 1); if ($history['meta']['response']['httpCode'] !== 200) die($history['meta']['response']['httpMessage']); print_r($history);
// обработать ошибки CURL & die } return curl_exec($ch); } $merchant = 'merchant'; $tokens = array( 0 => '1c82fc76364cb1eafa04f7225b16b1ae', 1 => '2d82fc76364cb1eafa04f7225b16b1bf' ); $data = array(); foreach($tokens as $k => $v) $data = array('tokens['.$k.']' => $v) + $data; $data = $data + array('merchant' => $merchant); $data = addSign($data); $response = json_decode(sendTokensRequest($data), 1); if ($response['meta']['response']['httpCode'] !== 200) die($response['meta']['response']['httpMessage']); print_r($response);