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; }
/** * This method should be overridden by methods which have actions to be taken after we receive response from server * * @param array $call_result * @param array $params * * @return array Returns array with finalize action details */ public function finalize($call_result, $params) { $return_arr = self::default_finalize_result(); if (!($call_result = S2P_SDK_Rest_API::validate_call_result($call_result)) or empty($call_result['response']['func'])) { return $return_arr; } switch ($call_result['response']['func']) { case self::FUNC_INIT_PREAPPROVAL: if (!empty($call_result['response']['response_array']['preapproval']) and !empty($call_result['response']['response_array']['preapproval']['redirecturl'])) { $return_arr['should_redirect'] = true; $return_arr['redirect_to'] = $call_result['response']['response_array']['preapproval']['redirecturl']; } break; } return $return_arr; }
/** * This method should be overridden by methods which have actions to be taken after we receive response from server * * @param array $call_result * @param array $params * * @return array Returns array with finalize action details */ public function finalize($call_result, $params) { $return_arr = self::default_finalize_result(); if (!($call_result = S2P_SDK_Rest_API::validate_call_result($call_result)) or empty($call_result['response']['func'])) { return $return_arr; } switch ($call_result['response']['func']) { case self::FUNC_METHOD_DETAILS: if (!empty($call_result['response']['response_array']['method'])) { $return_arr['custom_validators'] = array(); $return_arr['custom_validators']['payment'] = array(); $return_arr['custom_validators']['recurrent'] = array(); $pay_request_obj = new S2P_SDK_Structure_Payment_Request(); $variable_obj = new S2P_SDK_Scope_Variable($pay_request_obj->get_definition()); $payment_request_arr = $variable_obj->nullify(null, array('check_external_names' => false, 'nullify_full_object' => true)); $we_have_validators = false; if (!empty($call_result['response']['response_array']['method']['validatorspayin']) and is_array($call_result['response']['response_array']['method']['validatorspayin'])) { $custom_validators = array(); foreach ($call_result['response']['response_array']['method']['validatorspayin'] as $validator_arr) { if ($custom_validator = self::extract_method_validator($validator_arr, $payment_request_arr)) { if (!($transform_result = $variable_obj->transform_keys(array('Payment' => $custom_validator['sources']), null, array('check_external_names' => true))) or !is_array($transform_result) or empty($transform_result['payment']) or !is_array($transform_result['payment'])) { continue; } $custom_validator['sources'] = $transform_result['payment']; $custom_validators[] = $custom_validator; } } if (!empty($custom_validators)) { $return_arr['custom_validators']['payment'] = $custom_validators; $we_have_validators = true; } } if (!empty($call_result['response']['response_array']['method']['validatorsrecurrent']) and is_array($call_result['response']['response_array']['method']['validatorsrecurrent'])) { $custom_validators = array(); foreach ($call_result['response']['response_array']['method']['validatorsrecurrent'] as $validator_arr) { if ($custom_validator = self::extract_method_validator($validator_arr, $payment_request_arr)) { if (!($transform_result = $variable_obj->transform_keys(array('Payment' => $custom_validator['sources']), null, array('check_external_names' => true))) or !is_array($transform_result) or empty($transform_result['payment']) or !is_array($transform_result['payment'])) { continue; } $custom_validator['sources'] = $transform_result['payment']; $custom_validators[] = $custom_validator; } } if (!empty($custom_validators)) { $return_arr['custom_validators']['recurrent'] = $custom_validators; $we_have_validators = true; } } if (empty($we_have_validators)) { $return_arr['custom_validators'] = false; } } break; } return $return_arr; }