Пример #1
0
 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;
 }
Пример #2
0
 public function method_functionality($func)
 {
     if (empty($this->_method)) {
         $this->set_error(self::ERR_METHOD, self::s2p_t('Method not set'));
         return false;
     }
     if (!$this->_method->method_functionality($func)) {
         if ($this->_method->has_error()) {
             $this->copy_error($this->_method);
         } else {
             $this->set_error(self::ERR_METHOD_FUNC, self::s2p_t('Invalid method functionality'), sprintf('Invalid method functionality [%s]', $func));
         }
         return false;
     }
     return true;
 }
Пример #3
0
    private function get_form_method_parameters_fields($post_arr, $form_arr)
    {
        if (empty($this->_method) or empty($form_arr) or !is_array($form_arr) or empty($form_arr['form_name']) or empty($post_arr['func']) or !($func_details = $this->_method->valid_functionality($post_arr['func'])) or empty($func_details['request_structure'])) {
            return '';
        }
        $post_arr = self::validate_post_data($post_arr);
        /** @var S2P_SDK_Scope_Structure $structure_obj */
        $structure_obj = $func_details['request_structure'];
        if ($method_definition = $structure_obj->get_validated_definition()) {
            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();
            }
            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();
            }
            ob_start();
            ?>
            <fieldset id="method_parameters">
            <label for="method_parameters"><a href="javascript:void(0);" onclick="toggle_container( 'method_parameters_container' )"><strong><?php 
            echo self::s2p_t('Method parameters');
            ?>
</strong></a></label>
            <div id="method_parameters_container" style="display: block;">

            <?php 
            echo $this->get_form_method_parameters_fields_detailed($method_definition, $mandatory_arr, $hide_keys_arr, $post_arr, $form_arr);
            ?>

            </div>
            </fieldset>
            <?php 
            $buf = ob_get_clean();
            return $buf;
        }
        return '';
    }
Пример #4
0
 public function do_finalize($params = false)
 {
     if (empty($this->_api)) {
         $this->set_error(self::ERR_API_OBJECT, self::s2p_t('Couldn\'t finalize, API object is empty.'));
         return false;
     }
     if (empty($params) or !is_array($params)) {
         $params = array();
     }
     // If redirect is required, send redirect headers now...
     if (!isset($params['redirect_now'])) {
         $params['redirect_now'] = true;
     }
     if (!($finalize_result = $this->_api->do_finalize($params)) or !($finalize_result = S2P_SDK_Method::validate_finalize_result($finalize_result))) {
         if ($this->_api->has_error()) {
             $this->copy_error($this->_api);
         } else {
             $this->set_error(self::ERR_API_CALL, self::s2p_t('Couldn\'t finialize API action.'));
         }
         return false;
     }
     if (!empty($params['redirect_now']) and !empty($finalize_result['should_redirect']) and !empty($finalize_result['redirect_to']) and empty($finalize_result['redirect_headers_set'])) {
         if (!@headers_sent()) {
             @header('Location: ' . $finalize_result['redirect_to']);
             $finalize_result['redirect_headers_set'] = true;
         }
     }
     $this->_finalize_result = $finalize_result;
     return $this->_finalize_result;
 }
Пример #5
0
 /**
  * Entry point when making Smart2Pay API calls
  *
  * @param array $api_parameters Parameters passed to API object which contains request details
  * @param array|false $call_params Additional parameters sent to S2P_SDK\S2P_SDK_API::do_call()
  * @param array|false $finalize_params Array with parameters sent to
  *
  * @return array|false Returns false on error (error available with S2P_SDK\S2P_SDK_Module::st_get_error())
  *
  * @see S2P_SDK\S2P_SDK_Module::st_get_error()
  * @see S2P_SDK\S2P_SDK_API::do_call()
  */
 public static function quick_call($api_parameters, $call_params = false, $finalize_params = false)
 {
     self::st_reset_error();
     if (empty($api_parameters) or !is_array($api_parameters)) {
         self::st_set_error(self::ERR_API_QUICK_CALL, self::s2p_t('Invalid API parameters.'));
         return false;
     }
     if (empty($finalize_params) or !is_array($finalize_params)) {
         $finalize_params = array();
     }
     if (!isset($finalize_params['redirect_now'])) {
         $finalize_params['redirect_now'] = true;
     } else {
         $finalize_params['redirect_now'] = !empty($finalize_params['redirect_now']) ? true : false;
     }
     $return_arr = array();
     // Time of call (in microseconds)
     $return_arr['call_microseconds'] = 0;
     // Result of API call
     $return_arr['call_result'] = false;
     // API call details (request + response)
     $return_arr['call_details'] = false;
     // In case we want to finish transaction in same call we pass $finalize_params['redirect_now'] to true and SDK
     // will try to also make the redirect automatically (if headers not sent already)
     $return_arr['finalize_result'] = S2P_SDK_Method::default_finalize_result();
     try {
         /** @var S2P_SDK_API $api */
         if (!($api = self::get_instance('S2P_SDK_API', $api_parameters))) {
             if (!self::st_has_error()) {
                 self::st_set_error(self::ERR_API_QUICK_CALL, self::s2p_t('Failed initializing API object.'));
             }
             return false;
         }
         if (!($return_arr['call_details'] = $api->do_call($call_params))) {
             if (!$api->has_error()) {
                 self::st_set_error(self::ERR_API_QUICK_CALL, self::s2p_t('Failed initializing API object.'));
             } else {
                 self::st_copy_error($api);
             }
             return false;
         }
         if (!($return_arr['call_result'] = $api->get_result())) {
             if (!$api->has_error()) {
                 self::st_set_error(self::ERR_API_QUICK_CALL, self::s2p_t('Failed obtaining API call result.'));
             } else {
                 self::st_copy_error($api);
             }
             return false;
         }
         // You should call $api->do_finalize() before sending headers if you want to be redirected to payment page...
         if (!($return_arr['finalize_result'] = $api->do_finalize($finalize_params))) {
             if (!$api->has_error()) {
                 self::st_set_error(self::ERR_API_QUICK_CALL, self::s2p_t('Failed finalizing transaction after API call.'));
             } else {
                 self::st_copy_error($api);
             }
             return false;
         }
         $return_arr['call_microseconds'] = $api->get_call_time();
     } catch (\Exception $ex) {
         self::st_set_error(self::ERR_API_QUICK_CALL, self::s2p_t('Call error: [%s].', $ex->getMessage()));
         return false;
     }
     return $return_arr;
 }
Пример #6
0
 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;
 }