private function get_method_details() { if (!($this->_method_details = S2P_SDK_Method::get_all_methods())) { if (self::st_has_error()) { $this->copy_static_error(); } else { $this->set_error(self::ERR_METHODS, 'Couldn\'t obtain methods information.'); } return false; } return true; }
private function get_form_common_fields($post_arr, $form_arr) { $post_arr = self::validate_post_data($post_arr); if (empty($form_arr['hidden_form'])) { $form_arr['hidden_form'] = false; } else { $form_arr['hidden_form'] = empty($form_arr['hidden_form']) ? false : true; } if (empty($post_arr['foobar'])) { $api_config_arr = self::get_api_configuration(); // form defaults if (empty($post_arr['api_key']) and !empty($api_config_arr['api_key'])) { $post_arr['api_key'] = $api_config_arr['api_key']; } if (empty($post_arr['site_id']) and !empty($api_config_arr['site_id'])) { $post_arr['site_id'] = $api_config_arr['site_id']; } if (empty($post_arr['environment']) and !empty($api_config_arr['environment'])) { $post_arr['environment'] = $api_config_arr['environment']; } } ob_start(); if (!empty($form_arr['hidden_form'])) { ?> <input type="hidden" id="site_id" name="site_id" value="<?php echo self::form_str($post_arr['site_id']); ?> " /> <input type="hidden" id="api_key" name="api_key" value="<?php echo self::form_str($post_arr['api_key']); ?> " /> <input type="hidden" id="environment" name="environment" value="<?php echo self::form_str($post_arr['environment']); ?> " /> <input type="hidden" id="method" name="method" value="<?php echo self::form_str($post_arr['method']); ?> " /> <?php } else { ?> <div class="form_field"> <label for="api_key"><?php echo self::s2p_t('API Key'); ?> </label> <div class="form_input"> <input type="text" id="api_key" name="api_key" value="<?php echo self::form_str($post_arr['api_key']); ?> " style="width: 350px;" /> </div> </div> <div class="form_field"> <label for="site_id"><?php echo self::s2p_t('Site ID'); ?> </label> <div class="form_input"> <input type="text" id="site_id" name="site_id" value="<?php echo self::form_str($post_arr['site_id']); ?> " style="width: 150px;" /> </div> </div> <div class="form_field"> <label for="environment"><?php echo self::s2p_t('Environment'); ?> </label> <div class="form_input"><select id="environment" name="environment"> <option value="test" <?php echo $post_arr['environment'] == 'test' ? 'selected="selected"' : ''; ?> >Test</option> <option value="live" <?php echo $post_arr['environment'] == 'live' ? 'selected="selected"' : ''; ?> >Live</option> </select></div> </div> <div class="form_field"> <label for="method"><?php echo self::s2p_t('Method'); ?> </label> <div class="form_input"> <select id="method" name="method" onchange="document.<?php echo $form_arr['form_name']; ?> .submit()"> <option value=""> - <?php echo self::s2p_t('Choose an option'); ?> -</option><?php if ($all_methods = S2P_SDK_Method::get_all_methods() and is_array($all_methods)) { foreach ($all_methods as $method_id => $method_details) { if (empty($method_details['instance'])) { continue; } /** @var S2P_SDK_Method $instance */ $instance = $method_details['instance']; ?> <option value="<?php echo $method_id; ?> " <?php echo $post_arr['method'] == $method_id ? 'selected="selected"' : ''; ?> ><?php echo $method_id . ' - ' . $instance->get_name(); ?> </option><?php } } ?> </select></div> </div> <?php } if (!empty($this->_method) and $method_functionalities = $this->_method->get_functionalities() and is_array($method_functionalities)) { if (!empty($form_arr['hidden_form'])) { ?> <input type="hidden" id="func" name="func" value="<?php echo self::form_str($post_arr['func']); ?> " /> <?php } else { ?> <div class="form_field"> <label for="func"><?php echo self::s2p_t('Functionality'); ?> </label> <div class="form_input"> <select id="func" name="func" onchange="document.<?php echo $form_arr['form_name']; ?> .submit()"> <option value=""> - <?php echo self::s2p_t('Choose an option'); ?> -</option><?php foreach ($method_functionalities as $functionality_name => $functionality_arr) { if (empty($method_details['instance'])) { continue; } /** @var S2P_SDK_Method $instance */ $instance = $method_details['instance']; ?> <option value="<?php echo $functionality_name; ?> " <?php echo $post_arr['func'] == $functionality_name ? 'selected="selected"' : ''; ?> ><?php echo $functionality_name . ' - ' . $functionality_arr['name']; ?> </option><?php } ?> </select></div> </div> <?php } } $buf = ob_get_clean(); return $buf; }
public function extract_parameters() { static $extracted = null; if ($extracted !== null) { return true; } $extracted = true; if (!($this->_notification_buffer = S2P_SDK_Helper::get_php_input())) { $this->set_error(self::ERR_BODY, self::s2p_t('Notification body is empty.')); return false; } if (!($notification_arr = @json_decode($this->_notification_buffer, true))) { $this->set_error(self::ERR_JSON, self::s2p_t('Notification body is not a JSON.')); return false; } if ($methods_arr = S2P_SDK_Method::get_all_methods() and is_array($methods_arr)) { foreach ($methods_arr as $method_name => $method_arr) { /** @var S2P_SDK_Method $instance */ if (!($instance = $method_arr['instance']) or !($notification_check = $instance->check_notification($notification_arr))) { continue; } if (!empty($notification_check['notification_array'])) { $this->_notification_array = $notification_check['notification_array']; } switch ($notification_check['notification_type']) { case 'Payment': $this->_type = self::TYPE_PAYMENT; break; case 'Preapproval': $this->_type = self::TYPE_PREAPPROVAL; break; case 'Refund': $this->_type = self::TYPE_REFUND; break; } return true; } } return true; }