Debug call to apilayer
This commit is contained in:
parent
ceeb9752ce
commit
4a81e8fd62
@ -109,9 +109,18 @@ elseif ($action == 'update_currency')
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($action == 'synchronize')
|
||||
elseif ($action == 'setapilayer')
|
||||
{
|
||||
MultiCurrency::syncRates($conf->global->MULTICURRENCY_APP_ID);
|
||||
if (GETPOSTISSET('modify_apilayer'))
|
||||
{
|
||||
dolibarr_set_const($db, 'MULTICURRENCY_APP_ID', GETPOST('MULTICURRENCY_APP_ID', 'alpha'));
|
||||
dolibarr_set_const($db, 'MULTICURRENCY_APP_SOURCE', GETPOST('MULTICURRENCY_APP_SOURCE', 'alpha'));
|
||||
dolibarr_set_const($db, 'MULTICURRENCY_ALTERNATE_SOURCE', GETPOST('MULTICURRENCY_ALTERNATE_SOURCE', 'alpha'));
|
||||
}
|
||||
else
|
||||
{
|
||||
MultiCurrency::syncRates($conf->global->MULTICURRENCY_APP_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -177,17 +186,20 @@ if ($conf->use_javascript_ajax) {
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
//Online payment with currency on document
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->transnoentitiesnoconv("multicurrency_useCurrency").'</td>';
|
||||
print '<td align="center">';
|
||||
if ($conf->use_javascript_ajax) {
|
||||
print ajax_constantonoff('MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT');
|
||||
} else {
|
||||
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
|
||||
print $form->selectarray("MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT", $arrval, $conf->global->MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT);
|
||||
// Online payment with currency on document. This option should be on by default.
|
||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
|
||||
{
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->transnoentitiesnoconv("MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT").'</td>';
|
||||
print '<td align="center">';
|
||||
if ($conf->use_javascript_ajax) {
|
||||
print ajax_constantonoff('MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT');
|
||||
} else {
|
||||
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
|
||||
print $form->selectarray("MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT", $arrval, $conf->global->MULTICURRENCY_USE_CURRENCY_ON_DOCUMENT);
|
||||
}
|
||||
print '</td></tr>';
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
/* TODO uncomment when the functionality will integrated
|
||||
|
||||
@ -224,59 +236,48 @@ print '<br>';
|
||||
|
||||
if (!empty($conf->global->MAIN_MULTICURRENCY_ALLOW_SYNCHRONIZATION))
|
||||
{
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" id="form_sync">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="setapilayer">';
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$form->textwithpicto($langs->trans("CurrencyLayerAccount"), $langs->trans("CurrencyLayerAccount_help_to_synchronize")).'</td>'."\n";
|
||||
print '<td class="right">';
|
||||
print '<form id="form_sync" action="" method="POST">';
|
||||
print '<input type="hidden" name="action" value="synchronize" />';
|
||||
print '<textarea id="response" class="hideobject" name="response"></textarea>';
|
||||
print $langs->trans("Value").' <input type="button" id="bt_sync" class="button" onclick="javascript:getRates();" value="'.$langs->trans('Synchronize').'" />';
|
||||
print '</form>';
|
||||
print '</td></tr>';
|
||||
$urlforapilayer='https://currencylayer.com'; //https://apilayer.net
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$form->textwithpicto($langs->trans("CurrencyLayerAccount"), $langs->trans("CurrencyLayerAccount_help_to_synchronize", $urlforapilayer)).'</td>'."\n";
|
||||
print '<td class="right">';
|
||||
print '<textarea id="response" class="hideobject" name="response"></textarea>';
|
||||
print $langs->trans("Value").' <input type="button" id="bt_sync" name="bt_sync_apilayer" class="button" value="'.$langs->trans('Synchronize').'" />';
|
||||
print '<input type="submit" name="modify_apilayer" class="button" value="'.$langs->trans("Modify").'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td><a target="_blank" href="https://currencylayer.com">'.$langs->transnoentitiesnoconv("multicurrency_appId").'</a></td>';
|
||||
print '<td class="fieldrequired"><a target="_blank" href="'.$urlforapilayer.'">'.$langs->transnoentitiesnoconv("multicurrency_appId").'</a></td>';
|
||||
print '<td class="right">';
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="set_MULTICURRENCY_APP_ID">';
|
||||
print '<input type="text" name="MULTICURRENCY_APP_ID" value="'.$conf->global->MULTICURRENCY_APP_ID.'" size="28" /> ';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
||||
print '</form>';
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->transnoentitiesnoconv("multicurrency_appCurrencySource").'</td>';
|
||||
print '<td class="right">';
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="set_MULTICURRENCY_APP_SOURCE">';
|
||||
print '<input type="text" name="MULTICURRENCY_APP_SOURCE" value="'.$conf->global->MULTICURRENCY_APP_SOURCE.'" size="10" placeholder="USD" /> '; // Default: USD
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
||||
print '</form>';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->transnoentitiesnoconv("multicurrency_alternateCurrencySource").'</td>';
|
||||
print '<td class="right">';
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="set_MULTICURRENCY_ALTERNATE_SOURCE">';
|
||||
print '<input type="text" name="MULTICURRENCY_ALTERNATE_SOURCE" value="'.$conf->global->MULTICURRENCY_ALTERNATE_SOURCE.'" size="10" placeholder="EUR" /> '; // Example: EUR
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
||||
print '</form>';
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
@ -287,15 +288,17 @@ print '<td align="center">'.$langs->trans("Rate").'</td>'."\n";
|
||||
print '</tr>';
|
||||
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add_currency">';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$form->selectCurrency('', 'code').'</td>';
|
||||
print '<td class="right">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add_currency">';
|
||||
print '<input type="text" name="rate" value="" size="13" placeholder="'.$langs->trans('Rate').'" /> ';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
@ -325,23 +328,6 @@ foreach ($TCurrency as &$currency)
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
print '
|
||||
<script type="text/javascript">
|
||||
function getRates()
|
||||
{
|
||||
$("#bt_sync").attr("disabled", true);
|
||||
var url_sync = "http://apilayer.net/api/live?access_key='.$conf->global->MULTICURRENCY_APP_ID.'&format=1'.(!empty($conf->global->MULTICURRENCY_APP_SOURCE) ? '&source='.$conf->global->MULTICURRENCY_APP_SOURCE : '').'";
|
||||
|
||||
$.ajax({
|
||||
url: url_sync,
|
||||
dataType: "jsonp"
|
||||
}).done(function(response) {
|
||||
$("#response").val(JSON.stringify(response));
|
||||
$("#form_sync").submit();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
';
|
||||
|
||||
// End of page
|
||||
llxFooter();
|
||||
|
||||
@ -7,10 +7,10 @@ multicurrency_syncronize_error=Synchronization error: %s
|
||||
MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE=Use the date of the document to find the currency rate, instead of using the latest known rate
|
||||
multicurrency_useOriginTx=When an object is created from another, keep the original rate from the source object (otherwise use the latest known rate)
|
||||
CurrencyLayerAccount=CurrencyLayer API
|
||||
CurrencyLayerAccount_help_to_synchronize=You must create an account on their website to use this functionality.<br>Get your <b>API key</b>.<br>If you use a free account you can't change the <b>currency source</b> (USD by default).<br>If your main currency is not USD you can use the <b>alternate currency source</b> to force your main currency.<br><br>You are limited to 1000 synchronizations per month.
|
||||
CurrencyLayerAccount_help_to_synchronize=You must create an account on website %s to use this functionality.<br>Get your <b>API key</b>.<br>If you use a free account you can't change the <b>currency source</b> (USD by default).<br>If your main currency is not USD you can use the <b>alternate currency source</b> to force your main currency.<br><br>You are limited to 1000 synchronizations per month.
|
||||
multicurrency_appId=API key
|
||||
multicurrency_appCurrencySource=Currency source
|
||||
multicurrency_alternateCurrencySource=Alternate currency source
|
||||
multicurrency_appCurrencySource=Source currency
|
||||
multicurrency_alternateCurrencySource=Alternate source currency
|
||||
CurrenciesUsed=Currencies used
|
||||
CurrenciesUsed_help_to_add=Add the different currencies and rates you need to use on your <b>proposals</b>, <b>orders</b> etc.
|
||||
rate=rate
|
||||
|
||||
@ -633,7 +633,11 @@ class MultiCurrency extends CommonObject
|
||||
{
|
||||
global $conf, $db, $langs;
|
||||
|
||||
$ch = curl_init('http://apilayer.net/api/live?access_key='.$key.'');
|
||||
$urlendpoint = 'http://apilayer.net/api/live?access_key='.$key;
|
||||
dol_syslog("Call url endpoint ".$urlendpoint);
|
||||
|
||||
// TODO Use getURLContent() function instead.
|
||||
$ch = curl_init($urlendpoint);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
@ -663,6 +667,7 @@ class MultiCurrency extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
|
||||
setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user