first commit
This commit is contained in:
77
plugins/stPrzelewy24Plugin/lib/helper/stPrzelewy24Helper.php
Normal file
77
plugins/stPrzelewy24Plugin/lib/helper/stPrzelewy24Helper.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
function st_przelewy24_payment_methods_select_tag($name, $value, array $options = [])
|
||||
{
|
||||
$selectOptions = [];
|
||||
$api = new stPrzelewy24();
|
||||
$culture = sfContext::getInstance()->getUser()->getCulture();
|
||||
|
||||
try
|
||||
{
|
||||
$response = $api->getPaymentMethods($culture);
|
||||
|
||||
if (false !== $response)
|
||||
{
|
||||
foreach ($response as $paymentMethod)
|
||||
{
|
||||
if ($paymentMethod->status)
|
||||
{
|
||||
$selectOptions[$paymentMethod->id] = $paymentMethod->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asort($selectOptions, SORT_NATURAL);
|
||||
}
|
||||
catch (stPrzelewyException $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
$options['multiple'] = true;
|
||||
$options['selected'] = $value;
|
||||
|
||||
return select_tag($name, $selectOptions, $options);
|
||||
}
|
||||
|
||||
function st_przelewy24_highlighted_payments_select_tag($name, $value, array $options = [])
|
||||
{
|
||||
$selectOptions = [];
|
||||
$culture = sfContext::getInstance()->getUser()->getCulture();
|
||||
|
||||
$options['selected'] = $value;
|
||||
$options['multiple'] = true;
|
||||
|
||||
try
|
||||
{
|
||||
$api = new stPrzelewy24();
|
||||
$paymentMethods = $api->getPaymentMethods($culture);
|
||||
|
||||
if (!empty($paymentMethods))
|
||||
{
|
||||
foreach (stPrzelewy24::HIGHLIGHTED as $type => $fieldParams)
|
||||
{
|
||||
$id = $fieldParams['id'];
|
||||
|
||||
if (isset($paymentMethods[$id]) && $paymentMethods[$id]->status)
|
||||
{
|
||||
$selectOptions[$type] = $fieldParams['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (stPrzelewyException $e)
|
||||
{
|
||||
}
|
||||
|
||||
return select_tag($name, $selectOptions, $options);
|
||||
}
|
||||
|
||||
function object_st_przelewy24_highlighted_payments_select_tag($object, $method, $options = array(), $default_value = null)
|
||||
{
|
||||
$options = _parse_attributes($options);
|
||||
$value = _get_object_value($object, $method, $default_value);
|
||||
$name = _convert_method_to_name($method, $options);
|
||||
|
||||
return st_przelewy24_highlighted_payments_select_tag($name, $value, $options);
|
||||
}
|
||||
Reference in New Issue
Block a user