public function get_form_method_parameters_fields_detailed($structure_definition, $mandatory_arr, $hide_keys_arr, $post_arr, $form_arr, $params = false) { if (empty($params) or !is_array($params)) { $params = array(); } if (empty($params['path'])) { $params['path'] = ''; } if (empty($params['read_path'])) { $params['read_path'] = ''; } if (empty($params['name'])) { $params['name'] = ''; } if (!isset($params['blob_array_index'])) { $params['blob_array_index'] = false; } if (!isset($params['blob_array_index_read'])) { $params['blob_array_index_read'] = false; } if (empty($params['level'])) { $params['level'] = -1; } if (empty($params['blob_array_index_read']) and !empty($params['blob_array_index'])) { $params['blob_array_index_read'] = $params['blob_array_index']; } if (empty($mandatory_arr) or !is_array($mandatory_arr)) { $mandatory_arr = array(); } if (empty($hide_keys_arr) or !is_array($hide_keys_arr)) { $hide_keys_arr = array(); } if (empty($structure_definition) or !is_array($structure_definition) or array_key_exists($structure_definition['name'], $hide_keys_arr) and !is_array($hide_keys_arr[$structure_definition['name']])) { return ''; } $params['path'] .= (!empty($params['path']) ? '.' : '') . ($params['blob_array_index'] !== false ? $params['blob_array_index'] . '.' : '') . $structure_definition['name']; $params['read_path'] .= (!empty($params['read_path']) ? '.' : '') . ($params['blob_array_index_read'] !== false ? $params['blob_array_index_read'] . '.' : '') . $structure_definition['name']; $params['name'] .= ($params['blob_array_index'] !== false ? '[' . $params['blob_array_index'] . ']' : '') . '[' . $structure_definition['name'] . ']'; $params['level']++; if (empty($structure_definition['structure']) or !is_array($structure_definition['structure'])) { // display single element... $field_id = str_replace(array('.', '[', ']'), '_', $params['path']); $field_name = 'mparams' . $params['name']; $field_value = self::extract_field_value($post_arr['mparams'], $params['read_path']); if ($field_value === null) { if (!empty($structure_definition['check_constant']) and defined($structure_definition['check_constant'])) { $field_value = constant($structure_definition['check_constant']); } else { $field_value = ''; } } $field_mandatory = false; if (array_key_exists($structure_definition['name'], $mandatory_arr)) { $field_mandatory = true; } ob_start(); ?> <div class="form_field"> <label for="<?php echo $field_id; ?> " title="<?php echo (!empty($structure_definition['display_name']) ? $structure_definition['display_name'] . ' - ' : '') . self::form_str($params['path']); ?> " class="<?php echo !empty($field_mandatory) ? 'mandatory' : ''; ?> "><?php echo $structure_definition['name']; ?> </label> <div class="form_input"><?php if (empty($structure_definition['value_source']) or !S2P_SDK_Values_Source::valid_type($structure_definition['value_source']) or !($value_source_obj = new S2P_SDK_Values_Source($structure_definition['value_source'])) or $value_source_obj->remote_calls(self::ALLOW_REMOTE_CALLS) and false or !($options_value = $value_source_obj->get_option_values()) or !is_array($options_value)) { $options_value = array(); } if ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_BOOL) { ?> <input type="checkbox" id="<?php echo $field_id; ?> " name="<?php echo $field_name; ?> " value="1" <?php echo !empty($field_value) ? 'checked="checked"' : ''; ?> /><?php } elseif ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_DATETIME) { ?> <input type="text" id="<?php echo $field_id; ?> " name="<?php echo $field_name; ?> " value="<?php echo self::form_str($field_value); ?> " class="datepicker" /><?php } elseif ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_ARRAY) { if (empty($field_value) or !is_array($field_value)) { $field_value = array(); } if (empty($field_value['keys']) or !is_array($field_value['keys'])) { $field_value['keys'] = array(); } if (empty($field_value['vals']) or !is_array($field_value['vals'])) { $field_value['vals'] = array(); } ?> <input type="hidden" name="mparams_arrays[]" value="<?php echo self::form_str($params['path']); ?> " /> <div id="<?php echo $field_id; ?> ___container"> <?php foreach ($field_value['vals'] as $key => $val) { $field_key = ''; if (!empty($field_value['keys'][$key])) { $field_key = $field_value['keys'][$key]; } ?> <div class="form_input_array"> <?php if (empty($structure_definition['array_numeric_keys'])) { ?> <input type="text" name="<?php echo $field_name; ?> [keys][]" value="<?php echo self::form_str($field_key); ?> " placeholder="<?php echo self::form_str(self::s2p_t('Key')); ?> " /><?php } $options_params = array(); $options_params['field_id'] = false; $options_params['field_name'] = $field_name . '[vals][]'; $options_params['field_value'] = $val; if (!empty($options_value) and ($select_buf = self::display_select_options($options_value, $options_params)) !== false) { echo $select_buf; } else { if (empty($structure_definition['array_type']) or !($field_type_arr = S2P_SDK_Scope_Variable::valid_type($structure_definition['array_type']))) { $field_type_arr = array('title' => 'string'); } ?> <input type="text" name="<?php echo $field_name; ?> [vals][]" value="<?php echo self::form_str($val); ?> " placeholder="<?php echo self::form_str(self::s2p_t('Value')); ?> " /> (<?php echo $field_type_arr['title']; ?> ) <?php } ?> <a href="javascript:void(0);" onclick="remove_methods_array_element( $(this), '<?php echo $field_id; ?> ' )"><?php echo self::s2p_t('Remove'); ?> </a> </div> <?php } ?> </div> <div class="form_input_array input_disabler_container" id="<?php echo $field_id; ?> ___template" style="display: none;"> <?php if (empty($structure_definition['array_numeric_keys'])) { ?> <input type="text" name="<?php echo $field_name; ?> [keys][]" value="" placeholder="<?php echo self::form_str(self::s2p_t('Key')); ?> " /><?php } $options_params = array(); $options_params['field_id'] = false; $options_params['field_name'] = $field_name . '[vals][]'; $options_params['field_value'] = ''; if (!empty($options_value) and ($select_buf = self::display_select_options($options_value, $options_params)) !== false) { echo $select_buf; } else { if (empty($structure_definition['array_type']) or !($field_type_arr = S2P_SDK_Scope_Variable::valid_type($structure_definition['array_type']))) { $field_type_arr = array('title' => 'string'); } ?> <input type="text" name="<?php echo $field_name; ?> [vals][]" value="" placeholder="<?php echo self::form_str(self::s2p_t('Value')); ?> " /> (<?php echo $field_type_arr['title']; ?> ) <?php } ?> <a href="javascript:void(0);" onclick="remove_methods_array_element( $(this), '<?php echo $field_id; ?> ' )"><?php echo self::s2p_t('Remove'); ?> </a> </div> <div id="<?php echo $field_id; ?> " class="field_adder_container"><a href="javascript:void(0);" onclick="add_methods_array_element( '<?php echo $field_id; ?> ' )"><?php echo self::s2p_t('Add value'); ?> </a></div> <?php } else { $options_params = array(); $options_params['field_id'] = $field_id; $options_params['field_name'] = $field_name; $options_params['field_value'] = $field_value; if (!empty($options_value) and ($select_buf = self::display_select_options($options_value, $options_params)) !== false) { echo $select_buf; } else { if (!($field_type_arr = S2P_SDK_Scope_Variable::valid_type($structure_definition['type']))) { $field_type_arr = array('title' => '[undefined]'); } ?> <input type="text" id="<?php echo $field_id; ?> " name="<?php echo $field_name; ?> " value="<?php echo self::form_str($field_value); ?> " /><?php echo ' (' . $field_type_arr['title'] . ')'; } } if ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_DATETIME) { echo ' - yyyymmddhhmmss'; } if (!empty($structure_definition['regexp'])) { echo ' <span class="form_input_regexp"><a href="javascript:void(0);" onclick="toggle_regexp( $(this) )" tabindex="10000">RExp</a><span class="form_input_regexp_exp">' . $structure_definition['regexp'] . '</span></span>'; } ?> </div> </div> <?php $buf = ob_get_clean(); return $buf; } $field_id = str_replace('.', '_', $params['path']); ob_start(); ?> <fieldset id="mparam_<?php echo $field_id; ?> "> <label for="mparam_<?php echo $field_id; ?> "><a href="javascript:void(0);" onclick="toggle_container( 'mparam_container_<?php echo $field_id; ?> ' )"><strong><?php echo $params['path']; ?> </strong></a></label> <div id="mparam_container_<?php echo $field_id; ?> " style="display: block;"> <?php $new_mandatory_arr = array(); if (array_key_exists($structure_definition['name'], $mandatory_arr)) { $new_mandatory_arr = $mandatory_arr[$structure_definition['name']]; } $new_hide_keys_arr = array(); if (array_key_exists($structure_definition['name'], $hide_keys_arr)) { $new_hide_keys_arr = $hide_keys_arr[$structure_definition['name']]; } if ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_BLOB_ARRAY) { $blob_array_count = 0; if ($blob_array_value = self::extract_field_value($post_arr['mparams'], $params['path']) and is_array($blob_array_value)) { $elements_params = $params; $elements_params['blob_array_index'] = 0; $elements_params['blob_array_index_read'] = 0; foreach ($blob_array_value as $element_key => $element_arr) { $elements_params['blob_array_index_read'] = $element_key; ?> <div class="form_input_blob_array"><?php foreach ($structure_definition['structure'] as $element_definition) { if ($element_buffer = $this->get_form_method_parameters_fields_detailed($element_definition, $new_mandatory_arr, $new_hide_keys_arr, $post_arr, $form_arr, $elements_params)) { echo $element_buffer; } } ?> <a href="javascript:void(0);" onclick="remove_methods_blob_array_element( $(this), '<?php echo $field_id; ?> ' )"><?php echo self::s2p_t('Remove'); ?> </a> </div> <?php $elements_params['blob_array_index']++; $blob_array_count++; } } ?> </div> <div id="mparam_container_<?php echo $field_id; ?> ___template" class="form_input_blob_array input_disabler_container" style="display: none;"> <?php } if ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_BLOB_ARRAY) { $params['name'] .= '[{*BLOB_ARRAY_INDEX*}]'; } foreach ($structure_definition['structure'] as $element_definition) { if ($element_buffer = $this->get_form_method_parameters_fields_detailed($element_definition, $new_mandatory_arr, $new_hide_keys_arr, $post_arr, $form_arr, $params)) { echo $element_buffer; } } if ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_BLOB_ARRAY) { ?> <a href="javascript:void(0);" onclick="remove_methods_blob_array_element( $(this), '<?php echo $field_id; ?> ' )"><?php echo self::s2p_t('Remove'); ?> </a> <?php } ?> </div><?php if ($structure_definition['type'] == S2P_SDK_Scope_Variable::TYPE_BLOB_ARRAY) { ?> <div class="field_adder_container"><a href="javascript:void(0);" onclick="add_methods_blob_array_element( '<?php echo $field_id; ?> ' )"><?php echo self::s2p_t('Add value'); ?> </a></div> <?php } ?> </fieldset><?php $structure_buffer = ob_get_clean(); return $structure_buffer; }
public static function validate_get_variable_definition($definition_arr) { self::st_reset_error(); if (empty($definition_arr) or !is_array($definition_arr) or empty($definition_arr['name'])) { self::st_set_error(self::ERR_GET_VARIABLES, self::s2p_t('Name or structure invalid for get variable.')); return false; } $default_definition = self::default_get_variables_definition(); $new_definition_arr = array(); foreach ($default_definition as $key => $def_value) { if (!array_key_exists($key, $definition_arr)) { $new_definition_arr[$key] = $def_value; } else { $new_definition_arr[$key] = $definition_arr[$key]; } } if (empty($new_definition_arr['external_name'])) { $new_definition_arr['external_name'] = $new_definition_arr['name']; } if (empty($new_definition_arr['type']) or !S2P_SDK_Scope_Variable::valid_type($new_definition_arr['type'])) { self::st_set_error(self::ERR_GET_VARIABLES, self::s2p_t('Invalid type for variable %s.', $new_definition_arr['name'])); return false; } if (!empty($new_definition_arr['array_type']) and !S2P_SDK_Scope_Variable::valid_type($new_definition_arr['array_type'])) { self::st_set_error(self::ERR_GET_VARIABLES, self::s2p_t('Invalid array type for variable %s.', $new_definition_arr['name'])); return false; } if (!empty($new_definition_arr['value_source']) and !S2P_SDK_Values_Source::valid_type($new_definition_arr['value_source'])) { self::st_set_error(self::ERR_GET_VARIABLES, self::s2p_t('Invalid values source for variable %s.', $new_definition_arr['name'])); return false; } return $new_definition_arr; }
/** * Returns buffer of sample PHP code for specific method and functionality * @param S2P_SDK_Method $method_obj * @param string $func * * @return string Example buffer */ public function display_method_function_example($method_obj, $func) { if (empty($method_obj) or !is_object($method_obj) or !$method_obj instanceof S2P_SDK_Method or !($func_details = $method_obj->valid_functionality($func))) { return ''; } ob_start(); echo '<' . '?php' . "\n"; ?> include( 'bootstrap.php' ); // Tells SDK we work on debugging mode or not S2P_SDK\S2P_SDK_Module::st_debugging_mode( true ); // Tells SDK errors should be thrown instead of retrieving them with $obj->get_error() or S2P_SDK\S2P_SDK_Module::st_get_error() S2P_SDK\S2P_SDK_Module::st_throw_errors( false ); $api_parameters = array(); // Uncomment line below if you want to override Site ID set in config.inc.php // $api_parameters['site_id'] = '{PROVIDED_SITE_ID}'; // Uncomment line below if you want to override API Key set in config.inc.php // $api_parameters['api_key'] = '{PROVIDED_APIKEY}'; // Uncomment line below if you want to override environment set in config.inc.php // $api_parameters['environment'] = 'test'; // test or live $api_parameters['method'] = '<?php echo $method_obj->get_method(); ?> '; $api_parameters['func'] = '<?php echo $func; ?> '; $api_parameters['get_variables'] = array(<?php if (!empty($func_details['get_variables']) and is_array($func_details['get_variables'])) { echo "\n"; foreach ($func_details['get_variables'] as $var_arr) { $var_str = "\t" . '\'' . $var_arr['name'] . '\' => '; if (!($type_arr = S2P_SDK_Scope_Variable::valid_type($var_arr['type']))) { $type_arr = array('title' => '(Unknown_var_type)'); } if ($var_arr['type'] == S2P_SDK_Scope_Variable::TYPE_STRING or is_string($var_arr['default'])) { $var_str .= '\'' . $var_arr['default'] . '\''; } else { $var_str .= $var_arr['default']; } $var_str .= ','; if (!empty($var_arr['mandatory']) or !empty($var_arr['display_name'])) { $var_str .= ' //'; if (!empty($var_arr['display_name'])) { $var_str .= ' ' . $var_arr['display_name']; } if (!empty($var_arr['mandatory'])) { $var_str .= ' ' . strtoupper(self::s2p_t('mandatory')); } } echo $var_str . "\n"; } } ?> ); $api_parameters['method_params'] = array(<?php if (!empty($func_details['request_structure'])) { /** @var S2P_SDK_Scope_Structure $structure_obj */ $structure_obj = $func_details['request_structure']; $extraction_arr = array(); $extraction_arr['nullify_full_object'] = true; $extraction_arr['skip_regexps'] = true; if ($method_input_arr = $structure_obj->extract_info_from_response_array(array('foobar' => 1), $extraction_arr)) { $mandatory_arr = array(); if (empty($func_details['mandatory_in_request']) or !($mandatory_arr = $structure_obj->transfrom_keys_to_internal_names($func_details['mandatory_in_request']))) { $mandatory_arr = array(); } $hide_keys_arr = array(); if (empty($func_details['hide_in_request']) or !($hide_keys_arr = $structure_obj->transfrom_keys_to_internal_names($func_details['hide_in_request']))) { $hide_keys_arr = array(); } echo "\n" . $this->display_method_params($method_input_arr, $mandatory_arr, $hide_keys_arr, array('structure_obj' => $structure_obj)); } } ?> ); $call_params = array(); $finalize_params = array(); $finalize_params['redirect_now'] = false; if( !($call_result = S2P_SDK\S2P_SDK_Module::quick_call( $api_parameters, $call_params, $finalize_params )) ) { echo 'API call error: '; if( ($error_arr = S2P_SDK\S2P_SDK_Module::st_get_error()) and !empty( $error_arr['display_error'] ) ) echo $error_arr['display_error']; else echo 'Unknown error.'; } else { echo 'API call time: '.$call_result['call_microseconds'].'ms<br/>'."\n"; if( !empty( $call_result['finalize_result']['should_redirect'] ) and !empty( $call_result['finalize_result']['redirect_to'] ) ) echo '<br/>'."\n". 'Go to <a href="'.$call_result['finalize_result']['redirect_to'].'">'.$call_result['finalize_result']['redirect_to'].'</a> to complete transaction<br/>'."\n". '<br/>'."\n"; echo 'Call result:<br>'."\n". '<pre>'; var_dump( $call_result['call_result'] ); echo '</pre>'; } <?php $buf = ob_get_clean(); $buf = htmlspecialchars($buf); return $buf; }