3namespace Sale\Handlers\PaySystem;
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\Request;
7use Bitrix\Sale\PaySystem;
8use Bitrix\Sale\Payment;
10Loc::loadMessages(__FILE__);
24 return new PaySystem\ServiceResult();
44 $collection =
$payment->getCollection();
47 $order = $collection->getOrder();
50 $propertyCollection =
$order->getPropertyCollection();
53 $delivery = $propertyCollection->getDeliveryLocation();
58 $location = \CSaleLocation::GetByID($delivery->getValue());
62 $params = $this->service->getField(
'TARIF');
64 $tarifs = self::extractFromField(
$params);
65 $tarifs = isset($tarifs[$regId]) ? $tarifs[$regId] : $tarifs[0];
69 if ($fullPrice <= 1000)
71 elseif ($fullPrice <= 5000)
73 elseif ($fullPrice <= 20000)
75 elseif ($fullPrice <= 500000)
78 if (isset($tariffNum) && isset($tarifs[
"TARIFS"][$tariffNum]))
81 if ($tarifs[
"TARIFS"][$tariffNum][
"UPPER_SUMM"] <
$payment->getSum())
82 $percent = floatval($tarifs[
"TARIFS"][$tariffNum][
"PERCENT"]) * floatval(
$payment->getSum()) / 100;
83 $result = floatval($tarifs[
"TARIFS"][$tariffNum][
"FIX"]) + $percent;
93 private static function extractFromField(
$params)
96 $tarifs = unserialize(
$params, [
'allowed_classes' =>
false]);
98 if (!is_array($tarifs))
101 $arRegIds = array_keys($tarifs);
102 $regNames = @\CSaleLocation::GetRegionsNamesByIds($arRegIds);
105 if (isset($tarifs[0]))
107 $csvTariffs = self::getTariffArrayCSV($tarifs[0]);
111 'TARIFS' => $csvTariffs,
112 'REG_NAME' => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_TARIF_DEFAULT')
115 foreach ($regNames as $regId => $regName)
117 if (in_array($regId, $arRegIds))
119 $result[$regId][
"TARIFS"] = self::getTariffArrayCSV($tarifs[$regId]);
120 $result[$regId][
"REG_NAME"] = $regName;
131 private static function getTariffArrayCSV($tarifs)
135 if(is_array($tarifs) &&
count($tarifs) == 12)
140 "FIX" => $tarifs[
$i*3],
141 "PERCENT" => $tarifs[
$i*3+1],
142 "UPPER_SUMM" => $tarifs[
$i*3+2]
154 public static function getValues($paySystemId = 0)
160 $data = PaySystem\Manager::getById($paySystemId);
166 $result = \CSaleHelper::getOptionOrImportValues(
167 'ps_payment_forward_calc_tarifs',
168 array(get_called_class(),
'getAllCMTarifsFromCsv')
179 public static function prepareToField($tariff)
183 if (is_array($tariff))
185 foreach ($tariff as $id => $value)
191 for (
$i = 0;
$i < 12; ++
$i)
196 $tariffIds = explode(
'_', $id);
198 if (isset($tariffIds[2]))
200 $regionId = $tariffIds[2];
213 public static function getStructure($paySystemId = 0)
217 $arCmTarifs = self::getValues($paySystemId);
219 foreach ($arCmTarifs as $regionId => $arRegInfo)
223 'TYPE' =>
'TEXT_CENTERED',
224 'TITLE' => $arRegInfo[
"REG_NAME"],
225 'BLOCK_HIDEABLE' =>
'Y',
230 $arResult[$regionId.
'REG_ID'][
'BLOCK_DELETABLE'] =
'Y';
232 self::setTariffConfig(
'TARIF_1_'.$regionId, Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_LESS_1K'), $arRegInfo[
"TARIFS"][0],
$arResult);
233 self::setTariffConfig(
'TARIF_2_'.$regionId, Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_LESS_5K'), $arRegInfo[
"TARIFS"][1],
$arResult);
234 self::setTariffConfig(
'TARIF_3_'.$regionId, Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_LESS_20K'), $arRegInfo[
"TARIFS"][2],
$arResult);
235 self::setTariffConfig(
'TARIF_4_'.$regionId, Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_LESS_500K'), $arRegInfo[
"TARIFS"][3],
$arResult);
239 'TYPE' =>
'DROPDOWN',
240 'TITLE' => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_ADD_REGION'),
241 'VALUES' => self::getRegionsList(),
242 'ONCHANGE' =>
"document.forms['pay_sys_form'].elements['apply'].click();"
254 private static function setTariffConfig($tariffId, $tariffTitle, $arTarifs, &$arConfig)
256 $arConfig[$tariffId.
'_NAME'] =
array(
'TYPE' =>
'MULTI_CONTROL_STRING',
'MCS_ID' => $tariffId,
'TITLE' => $tariffTitle);
257 $arConfig[$tariffId.
'_FIX'] =
array(
'TYPE' =>
'STRING',
'MCS_ID' => $tariffId,
'POST_TEXT' => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_RUB'),
'SIZE' => 4,
'VALUE' => $arTarifs[
'FIX']);
258 $arConfig[$tariffId.
'_PERCENT'] =
array(
'TYPE' =>
'STRING',
'MCS_ID' => $tariffId,
'PRE_TEXT' =>
' + ',
'POST_TEXT' =>
' % ',
'SIZE' => 3,
'VALUE' => $arTarifs[
'PERCENT']);
259 $arConfig[$tariffId.
'_UPPER_SUMM'] =
array(
'TYPE' =>
'STRING',
'MCS_ID' => $tariffId,
'PRE_TEXT' => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_SUMM_MORE'),
'POST_TEXT' => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_RUB'),
'SIZE' => 7,
'VALUE' => $arTarifs[
'UPPER_SUMM']);
262 private static function getRegionsList()
264 $result =
array(0 => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_CHOOSE_REGION'));
267 $dbRes = \CSaleLocation::GetRegionList();
278 public function getCMTarifsByRegionFromCsv($regionNameLang)
280 if(trim($regionNameLang) ==
'')
283 $csvFile = \CSaleHelper::getCsvObject(__DIR__.
'/lang/ru/cm_tarif.csv');
288 while (
$arRes = $csvFile->Fetch())
290 if(mb_strtoupper(trim($regionNameLang)) ===
$arRes[$COL_REG_NAME])
297 $arTarifsResult = self::getTariffArrayCSV($arTarifs);
299 return $arTarifsResult;
305 public static function getAllCMTarifsFromCsv()
307 $csvFile = \CSaleHelper::getCsvObject(__DIR__.
'/lang/ru/cm_tarif.csv');
312 while (
$arRes = $csvFile->Fetch())
314 $arRegName = array_shift(
$arRes);
315 $tarifs[$arRegName] =
$arRes;
317 if($arRegName !=
'default')
318 $regNames[] = $arRegName;
321 if(isset($tarifs[
'default']))
324 "TARIFS" => self::getTariffArrayCSV($tarifs[
'default']),
325 "REG_NAME" => Loc::getMessage(
'SALE_HPS_CASH_ON_DELIVERY_TARIF_DEFAULT')
329 $regInfo = \CSaleLocation::GetRegionsIdsByNames($regNames);
331 foreach ($regInfo as $regName => $regId)
333 $result[$regInfo[$regName]][
"TARIFS"] = self::getTariffArrayCSV($tarifs[$regName]);
334 $result[$regInfo[$regName]][
"REG_NAME"] = $regName;
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
getPrice(Payment $payment)
if(!function_exists(__NAMESPACE__.'\\___972068685'))
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']