Last active
April 15, 2022 00:51
-
-
Save jiromm/5387374 to your computer and use it in GitHub Desktop.
Get Rates from CBA bank of Armenia
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 | |
ini_set('soap.wsdl_cache_enabled', '0'); | |
ini_set('soap.wsdl_cache_ttl', '0'); | |
define('WSDL', 'http://api.cba.am/exchangerates.asmx?wsdl'); | |
$error = false; | |
try { | |
$client = new SoapClient(WSDL, array( | |
'version' => SOAP_1_1 | |
)); | |
$result = $client->__soapCall("ExchangeRatesByDate", array(array( | |
'date' => date('Y-m-d\TH:i:s') | |
))); | |
if (is_soap_fault($result)) { | |
throw new Exception('Failed to get data'); | |
} else { | |
$data = $result->ExchangeRatesByDateResult; | |
} | |
} catch (Exception $e) { | |
$error = 'Message: ' . $e->getMessage() . "\nTrace:" . $e->getTraceAsString(); | |
} | |
if ($error === false) { | |
echo 'Current Date: ' . $data->CurrentDate . '<br>'; | |
echo 'Next Available Date: ' . $data->NextAvailableDate . '<br>'; | |
echo 'Previous Available Date: ' . $data->PreviousAvailableDate . '<br>'; | |
echo '<br>'; | |
$rates = $data->Rates->ExchangeRate; | |
if (is_array($rates) && count($rates) > 0) { | |
echo '<table><tr><th>ISO</th><th>Amount</th><th>Rate</th><th>Difference</th></tr>'; | |
foreach ($rates as $rate) { | |
echo '<tr>'; | |
echo '<td>' . $rate->ISO . '</td><td>' . $rate->Amount . '</td><td>' . $rate->Rate . '</td><td>' . $rate->Difference . '</td></tr>'; | |
echo '</tr>'; | |
} | |
echo '</table>'; | |
} | |
//echo '<pre>'; | |
//var_dump($data); | |
//echo '<pre>'; | |
} else { | |
echo '<pre>'; | |
echo $error; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment