public function refreshPaymentOptions($serviceId, $apiToken) { $serviceId = $this->db->escape($serviceId); //eerst de oude verwijderen $sql = "DELETE options,optionsubs FROM `" . DB_PREFIX . "paynl_paymentoptions` as options " . "LEFT JOIN `" . DB_PREFIX . "paynl_paymentoption_subs` as optionsubs ON optionsubs.paymentOptionId = options.id " . "WHERE options.serviceId = '{$serviceId}'"; $this->db->query($sql); //nieuwe ophalen $api = new Pay_Api_Getservice(); $api->setApiToken($apiToken); $api->setServiceId($serviceId); $result = $api->doRequest(); $imgBasePath = $result['service']['basePath']; foreach ($result['paymentOptions'] as $paymentOption) { $img = $imgBasePath . $paymentOption['path'] . $paymentOption['img']; //variabelen filteren $optionId = $this->db->escape($paymentOption['id']); $name = $this->db->escape($paymentOption['visibleName']); $img = $this->db->escape($img); $sql = "INSERT INTO `" . DB_PREFIX . "paynl_paymentoptions` " . "(optionId, serviceId, name, img, update_date) VALUES " . "('{$optionId}', '{$serviceId}', '{$name}', '{$img}', NOW())"; $this->db->query($sql); $internalOptionId = $this->db->getLastId(); foreach ($paymentOption['paymentOptionSubList'] as $optionSub) { $optionSubId = $optionSub['id']; $name = $optionSub['visibleName']; $img = $imgBasePath . $optionSub['path'] . $optionSub['img']; //variabelen filteren $optionSubId = $this->db->escape($optionSubId); $name = $this->db->escape($name); $img = $this->db->escape($img); $sql = "INSERT INTO `" . DB_PREFIX . "paynl_paymentoption_subs` " . "(optionSubId, paymentOptionId, name, img, update_date) VALUES " . "('{$optionSubId}', {$internalOptionId}, '{$name}', '{$img}', NOW() )"; $this->db->query($sql); } } }
function fn_getPaynlOptionId($var) { $paynl_setting = Registry::get('addons.paynl_addon'); $service = new Pay_Api_Getservice(); $service->setApiToken($paynl_setting['token_api']); $service->setServiceId($paynl_setting['service_id']); try { $result = $service->doRequest(); } catch (Exception $ex) { fn_set_notification('E', __('error'), $ex->getMessage()); fn_redirect('/index.php?dispatch=checkout.checkout'); } return $result['paymentOptions']; }
public function displayFormSettings() { $arrConfig = array(); $arrConfig[] = 'PAYNL_TOKEN'; $arrConfig[] = 'PAYNL_SERVICE_ID'; $arrConfig[] = 'PAYNL_WAIT'; $arrConfig[] = 'PAYNL_SUCCESS'; $arrConfig[] = 'PAYNL_AMOUNTNOTVALID'; $arrConfig[] = 'PAYNL_CANCEL'; $arrConfig[] = 'PAYNL_COUNTRY_EXCEPTIONS'; $arrConfig[] = 'PAYNL_PAYMENT_METHOD_ORDER'; $arrConfig[] = 'PAYNL_PAYMENT_EXTRA_COSTS'; $arrConfig[] = 'PAYNL_VALIDATE_ON_START'; $arrConfig[] = 'PAYNL_PAYMENT_METHOD_NAME'; $arrConfig[] = 'PAYNL_PAYMENT_MIN'; $arrConfig[] = 'PAYNL_PAYMENT_MAX'; $conf = Configuration::getMultiple($arrConfig); $paynltoken = array_key_exists('paynltoken', $_POST) ? $_POST['paynltoken'] : (array_key_exists('PAYNL_TOKEN', $conf) ? $conf['PAYNL_TOKEN'] : ''); $service_id = array_key_exists('service_id', $_POST) ? $_POST['service_id'] : (array_key_exists('PAYNL_SERVICE_ID', $conf) ? $conf['PAYNL_SERVICE_ID'] : ''); $description_prefix = array_key_exists('description_prefix', $_POST) ? $_POST['description_prefix'] : (array_key_exists('PAYNL_DESCRIPTION_PREFIX', $conf) ? $conf['PAYNL_DESCRIPTION_PREFIX'] : ''); $wait = array_key_exists('wait', $_POST) ? $_POST['wait'] : (array_key_exists('PAYNL_WAIT', $conf) ? $conf['PAYNL_WAIT'] : '11'); $success = array_key_exists('success', $_POST) ? $_POST['success'] : (array_key_exists('PAYNL_SUCCESS', $conf) ? $conf['PAYNL_SUCCESS'] : '2'); $amountnotvalid = array_key_exists('amountnotvalid', $_POST) ? $_POST['amountnotvalid'] : (array_key_exists('PAYNL_AMOUNTNOTVALID', $conf) ? $conf['PAYNL_AMOUNTNOTVALID'] : '1'); $cancel = array_key_exists('cancel', $_POST) ? $_POST['cancel'] : (array_key_exists('PAYNL_CANCEL', $conf) ? $conf['PAYNL_CANCEL'] : '6'); $minAmount = array_key_exists('PAYNL_PAYMENT_MIN', $conf) ? $conf['PAYNL_PAYMENT_MIN'] : ''; $maxAmount = array_key_exists('PAYNL_PAYMENT_MAX', $conf) ? $conf['PAYNL_PAYMENT_MAX'] : ''; if ($minAmount) { $minAmount = unserialize($minAmount); } else { $minAmount = array(); } if ($maxAmount) { $maxAmount = unserialize($maxAmount); } else { $maxAmount = array(); } // Get states $states = OrderState::getOrderStates($this->context->language->id); $osWait = '<select name="wait">'; foreach ($states as $state) { if ($state['logable'] == 0) { $selected = $state['id_order_state'] == $wait ? ' selected' : ''; $osWait .= '<option value="' . $state['id_order_state'] . '"' . $selected . '>' . $state['name'] . '</option>'; } } $osWait .= '</select>'; $osSuccess = '<select name="success">'; foreach ($states as $state) { if ($state['logable'] == 1) { $selected = $state['id_order_state'] == $success ? ' selected' : ''; $osSuccess .= '<option value="' . $state['id_order_state'] . '"' . $selected . '>' . $state['name'] . '</option>'; } } $osSuccess .= '</select>'; $osCancel = '<select name="cancel">'; foreach ($states as $state) { if ($state['logable'] == 0) { $selected = $state['id_order_state'] == $cancel ? ' selected' : ''; $osCancel .= '<option value="' . $state['id_order_state'] . '"' . $selected . '>' . $state['name'] . '</option>'; } } $osCancel .= '</select>'; $countries = DB::getInstance()->ExecuteS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module = ' . (int) $this->id); foreach ($countries as $country) { $this->country[$country['id_country']] = $country['id_country']; } $exceptions = ''; try { $token = Configuration::get('PAYNL_TOKEN'); $serviceId = Configuration::get('PAYNL_SERVICE_ID'); $serviceApi = new Pay_Api_Getservice(); $serviceApi->setApiToken($token); $serviceApi->setServiceId($serviceId); $profiles = $serviceApi->doRequest(); $profiles = $profiles['paymentOptions']; $countries = Country::getCountries($this->context->language->id); $forceProfilesEnable = false; $profilesEnable = array_key_exists('PAYNL_COUNTRY_EXCEPTIONS', $conf) ? $conf['PAYNL_COUNTRY_EXCEPTIONS'] : ''; if (strlen($profilesEnable) == 0) { $profilesEnable = array(); $forceProfilesEnable = true; } else { $profilesEnable = @unserialize($profilesEnable); if ($profilesEnable == false) { $forceProfilesEnable = true; $profilesEnable = array(); } } $profilesOrder = array_key_exists('PAYNL_PAYMENT_METHOD_ORDER', $conf) ? $conf['PAYNL_PAYMENT_METHOD_ORDER'] : ''; $extraCosts = array_key_exists('PAYNL_PAYMENT_EXTRA_COSTS', $conf) ? $conf['PAYNL_PAYMENT_EXTRA_COSTS'] : ''; $validateOnStart = array_key_exists('PAYNL_VALIDATE_ON_START', $conf) ? $conf['PAYNL_VALIDATE_ON_START'] : ''; if (strlen($profilesOrder) == 0) { $profilesOrder = array(); } else { $profilesOrder = @unserialize($profilesOrder); if ($profilesOrder == false) { $profilesOrder = array(); } } if (strlen($extraCosts) == 0) { $extraCosts = array(); } else { $extraCosts = @unserialize($extraCosts); if ($extraCosts == false) { $extraCosts = array(); } } if (strlen($validateOnStart) == 0) { $validateOnStart = array(); } else { $validateOnStart = @unserialize($validateOnStart); if ($validateOnStart == false) { $validateOnStart = array(); } } $exceptions = '<br /><h2 class="space">' . $this->l('Payment restrictions') . '</h2>'; $exceptions .= '<table border="1"><tr><th>' . $this->l('Country') . '</th><th colspan="' . count($profiles) . '">' . $this->l('Payment methods') . '</th></tr>'; $exceptions .= '<tr><td> </td>'; foreach ($profiles as $profile) { $exceptions .= '<td>' . $profile['name'] . '</td>'; } $exceptions .= '</tr>'; foreach ($countries as $countryid => $country) { if (!isset($this->country[$countryid])) { continue; } $exceptions .= "<tr><td>" . $country['name'] . "</td>"; foreach ($profiles as $profile) { $exceptions .= "<td>"; if (!$forceProfilesEnable) { $exceptions .= '<input type="checkbox" name="enaC[' . $countryid . '][' . $profile['id'] . ']" value="' . $profile['name'] . '"' . (isset($profilesEnable[$countryid][$profile['id']]) ? ' checked="checked"' : '') . ' />'; } else { $exceptions .= '<input type="checkbox" name="enaC[' . $countryid . '][' . $profile['id'] . ']" value="' . $profile['name'] . '" checked="checked" />'; } $exceptions .= '</td>'; } $exceptions .= "</tr>"; } $exceptions .= "</table>"; $exceptions .= '<br /><h2 class="space">' . $this->l('Payment priority') . '</h2>'; $exceptions .= '<p>' . $this->l('Lower priority is more important') . '</p>'; $exceptions .= '<table border="1"><tr><th>' . $this->l('Payment method') . '</th><th>' . $this->l('Order') . '</th>'; $exceptions .= '<th>' . $this->l('Min. amount') . '</th>'; $exceptions .= '<th>' . $this->l('Max. amount') . '</th>'; $exceptions .= '<th>' . $this->l('Extra costs fixed') . '</th>'; $exceptions .= '<th>' . $this->l('Extra costs percentage') . '</th>'; $exceptions .= '<th>' . $this->l('Extra costs max') . '</th>'; $exceptions .= '<th>' . $this->l('Validate on transaction start') . '</th>'; $exceptions .= '</tr>'; $names = array_key_exists('PAYNL_PAYMENT_METHOD_NAME', $conf) ? $conf['PAYNL_PAYMENT_METHOD_NAME'] : ''; $names = unserialize($names); foreach ($profiles as $profile) { $name = $profile['name']; if (is_array($names) && !empty($names[$profile['id']])) { $name = $names[$profile['id']]; } $exceptions .= '<tr><td><input type="text" name="profileName[' . $profile['id'] . ']" value="' . $name . '" /></td><td>'; $exceptions .= '<select name="enaO[' . $profile['id'] . ']">'; $value = ''; if (isset($profilesOrder[$profile['id']])) { $value = $profilesOrder[$profile['id']]; } $valueAmount = count($profiles); for ($i = 0; $i < $valueAmount; $i++) { $selected = ''; if ($value == $i) { $selected = 'selected="selected"'; } $exceptions .= '<option value="' . $i . '" ' . $selected . '>' . $this->l('Priority') . ' ' . ($i + 1) . '</option>'; } $exceptions .= '</select>'; $exceptions .= '</td>'; $fixed = @$extraCosts[$profile['id']]['fixed']; $percentage = @$extraCosts[$profile['id']]['percentage']; $max = @$extraCosts[$profile['id']]['max']; $exceptions .= '<td><input name="minAmount[' . $profile['id'] . ']" type="text" value="' . $minAmount[$profile['id']] . '" /></td>'; $exceptions .= '<td><input name="maxAmount[' . $profile['id'] . ']" type="text" value="' . $maxAmount[$profile['id']] . '" /></td>'; $exceptions .= '<td><input name="payExtraCosts[' . $profile['id'] . '][fixed]" type="text" value="' . $fixed . '" /></td>'; $exceptions .= '<td><input name="payExtraCosts[' . $profile['id'] . '][percentage]" type="text" value="' . $percentage . '" /></td>'; $exceptions .= '<td><input name="payExtraCosts[' . $profile['id'] . '][max]" type="text" value="' . $max . '" /></td>'; $validateOnStartChecked = ''; if (isset($validateOnStart[$profile['id']]) && $validateOnStart[$profile['id']] == 1) { $validateOnStartChecked = "checked='checked'"; } $exceptions .= '<td><input type="hidden" name="validateOnStart[' . $profile['id'] . ']" value="0" /><input ' . $validateOnStartChecked . ' name="validateOnStart[' . $profile['id'] . ']" type="checkbox" value="1" /></td>'; $exceptions .= '</tr>'; } $exceptions .= '</table>'; } catch (Exception $ex) { $exceptions = '<br /><h2 class="space">' . $this->l('Payment restrictions') . '</h2>' . '<br />' . $this->l('Payment restrictions available after connecting to Pay.nl'); } $this->_html .= ' <form action="' . $_SERVER['REQUEST_URI'] . '" method="post"> <fieldset> <legend><img src="../img/admin/contact.gif" />' . $this->l('Settings') . '</legend> <label>' . $this->l('Token') . '</label> <div class="margin-form"><input type="text" size="33" name="paynltoken" value="' . htmlentities($paynltoken, ENT_COMPAT, 'UTF-8') . '" /></div> <label>' . $this->l('Service ID') . '</label> <div class="margin-form"><input type="text" size="33" name="service_id" value="' . htmlentities($service_id, ENT_COMPAT, 'UTF-8') . '" /></div> <label>' . $this->l('Order description prefix') . '</label> <div class="margin-form"><input type="text" size="33" name="description_prefix" value="' . htmlentities($description_prefix, ENT_COMPAT, 'UTF-8') . '" /></div> <br> <hr> <br> <label>' . $this->l('Pending') . '</label> <div class="margin-form">' . $osWait . ' Alleen van toepassing op betalingen waarbij extra kosten worden gerekend, de status gaat daarna meteen naar success</div> <label>' . $this->l('Success') . '</label> <div class="margin-form">' . $osSuccess . '</div> <label>' . $this->l('Cancel') . '</label> <div class="margin-form">' . $osCancel . '</div> <br />' . $exceptions . '<br /><center><input type="submit" name="submitPaynl" value="' . $this->l('Update settings') . '" class="button" /></center> </fieldset> </form><br /><br />'; }