/** * Make sure params are as expected * * @param array array of params to check to ensure proper formatting * @param array array of required params * @return mixed Will return TRUE if all pass. Will return an object if a param is bad. */ public static function validate($method, $params, $required_params) { //Append _method to method name $method = $method . "_method"; //We'll need this later $lang = Payment_Utility::load('lang', 'english/response_details'); //Ensure no invalid methods were passed include_once 'payment_methods/' . $method . '.php'; $m = new $method(); $method_params = $m->get_params(); $bad_params = array(); foreach ($params as $k => $v) { if (!isset($method_params[$k])) { $bad_params[] = "{$k} " . $lang['is_not_a_param']; } } if (count($bad_params) > 0) { return Payment_Response::instance()->local_response('failure', 'invalid_input', implode(', ', $bad_params)); } //Ensure no required params are missing $missing = array(); foreach ($required_params as $k => $v) { if (!array_key_exists($v, $params) or empty($params[$v]) or is_null($params[$v]) or $params[$v] == ' ') { $key = 'missing_' . $v; if (isset($lang[$key])) { $missing[] = $lang[$key]; } else { error_log("{$key} does not exist in response message language file."); $missing[] = "{$v} is required but was not provided"; } } } if (count($missing) > 0) { return Payment_Response::instance()->local_response('failure', 'required_params_missing', implode(', ', $missing)); } //Ensure dates match MMYYYY format if (array_key_exists('cc_exp', $params)) { $exp_date = $params['cc_exp']; $m1 = $exp_date[0]; if (strlen($exp_date) != 6 or !is_numeric($exp_date) or $m1 > 1) { return Payment_Response::instance()->local_response('failure', 'invalid_input', 'invalid_date_format'); } } //Ensure billing period is submitted in normalized form if (array_key_exists('billing_period', $params)) { $accepted_billing_period = array('Month', 'Day', 'Week', 'Year'); if (!in_array($params['billing_period'], $accepted_billing_period)) { return Payment_Response::instance()->local_response('failure', 'invalid_input', 'invalid_billing_period'); } } return TRUE; }
/** * Make a call to a gateway. Uses other helper methods to make the request. * * @param string The payment method to use * @param array $params[0] is the gateway, $params[1] are the params for the request. $params[2] is a config array for the driver. * @return object Should return a success or failure, along with a response. */ public function __call($method, $params) { $gateway = $params[0] . '_Driver'; $args = $params[1]; $config = isset($params[2]) ? $params[2] : @Payment_Utility::load('config', 'drivers/' . $params[0]); //Load the driver config if not passed in constructor $config['mode'] = isset($this->config['mode']) && $this->config['mode'] === 'test' ? 'test' : 'production'; try { $driver = new $gateway($config); } catch (Exception $e) { return Payment_Response::instance()->local_response('failure', 'not_a_module', $e->getMessage()); } $method_map = $driver->method_map(); if (!isset($method_map[$method])) { return Payment_Response::instance()->local_response('failure', 'not_a_method'); } //Make sure params are in expected format, make sure required have been provided $validation_check = Payment_Validator::validate($method, $args, $method_map[$method]['required']); return $validation_check === true ? $driver->{$method}($args) : $validation_check; }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($response) { $details = (object) array(); if (isset($response->id)) { $details->identifier = $response->id; } $details->timestamp = $response->created; $details->gateway_response = $response; return Payment_Response::instance()->gateway_response('success', $this->_lib_method . '_success', $details); }
/** * Parses an XML response and creates an object using SimpleXML * * @param string raw xml string * @return object response SimpleXMLElement object */ public static function parse_xml($xml_str) { $xml_str = trim($xml_str); $xml_str = preg_replace('/xmlns="(.+?)"/', '', $xml_str); if ($xml_str[0] != '<') { $xml_str = explode('<', $xml_str); if (count($xml_str) > 1) { unset($xml_str[0]); $xml_str = '<' . implode('<', $xml_str); } else { $xml_str = $xml_str[0]; } } try { $xml = @new SimpleXMLElement($xml_str); } catch (Exception $e) { return Payment_Response::instance()->local_response('failure', 'invalid_xml', $xml_str); } return $xml; }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($response) { if ($response === FALSE) { return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure'); } $results = explode('&', urldecode($response)); foreach ($results as $result) { list($key, $value) = explode('=', $result); $gateway_response[$key] = $value; } $details = (object) array('gateway_response' => (object) array()); foreach ($gateway_response as $k => $v) { $details->gateway_response->{$k} = $v; } if (isset($gateway_response['L_LONGMESSAGE0'])) { $details->reason = $gateway_response['L_LONGMESSAGE0']; } if (isset($gateway_response['TIMESTAMP'])) { $details->timestamp = $gateway_response['TIMESTAMP']; } if (isset($gateway_response['TRANSACTIONID'])) { $details->identifier = $gateway_response['TRANSACTIONID']; } if (isset($gateway_response['PROFILEID'])) { $details->identifier = $gateway_response['PROFILEID']; } if ($gateway_response['ACK'] == 'Success') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($xml) { //If it failed when being parsed as XML, go ahead and return it if (isset($xml->status) && $xml->status == 'failure') { return $xml; } $details = (object) array(); $as_array = Payment_Utility::arrayize_object($xml); $result = $as_array['messages']['resultCode']; if (isset($as_array['transactionResponse'])) { $identifier = $as_array['transactionResponse']['transId']; } if (isset($as_array['subscriptionId'])) { $identifier = $as_array['subscriptionId']; } $timestamp = gmdate('c'); $details->timestamp = $timestamp; $details->gateway_response = $as_array; if (isset($identifier) and strlen($identifier) > 1) { $details->identifier = $identifier; } if ($result == 'Ok') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } if ($result == 'Error') { if (isset($as_array['transactionResponse']['errors']['error']['errorText'])) { $message = $as_array['transactionResponse']['errors']['error']['errorText']; } if (isset($as_array['messages']['message']['text'])) { $message = $as_array['messages']['message']['text']; } if (isset($message)) { $details->reason = $message; } return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }
/** * Parse the Response * * @param array Raw response * @return object Payment_Response */ protected function _parse_response($response) { if ($this->_is_button) { return Payment_Response::instance()->local_response('success', $this->_lib_method . '_success', $response); } }
/** * Parse the Response and then Delegate to the Response Object * * @param object * @return object */ protected function _parse_response($response) { if ($this->_is_button) { return Payment_Response::instance()->local_response('success', $this->_lib_method . '_success', $response); } else { /*return Payment_Response::instance()->gateway_response( 'success', $this->_lib_method.'_success', $response );*/ //Will be integrated when testing details are received var_dump($response); exit; } }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($response) { $details = (object) array(); if (isset($response->transaction->id)) { $details->identifier = $response->transaction->id; } $details->timestamp = $response->created; $details->gateway_response = $response; if (isset($response->transaction->processorResponseText)) { $details->reason = $response->transaction->processorResponseText; } $indicator = $response->success === true ? 'success' : 'failure'; return Payment_Response::instance()->gateway_response($indicator, $this->_lib_method . '_' . $indicator, $details); }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($xml) { $details = (object) array(); $as_array = Payment_Utility::arrayize_object($xml); $signon = isset($as_array['SignonMsgsRs']) ? $as_array['SignonMsgsRs'] : ''; $response = isset($as_array['QBMSXMLMsgsRs']) ? $as_array['QBMSXMLMsgsRs'] : ''; $result = ''; $message = ''; $identifier = ''; if (isset($response['CustomerCreditCardChargeRs'])) { $result = $response['CustomerCreditCardChargeRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardChargeRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardChargeRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardAuthRs'])) { $result = $response['CustomerCreditCardAuthRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardAuthRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardAuthRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardCaptureRs'])) { $result = $response['CustomerCreditCardCaptureRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardCaptureRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardCaptureRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardTxnVoidRs'])) { $result = $response['CustomerCreditCardTxnVoidRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardTxnVoidRs']['@attributes']['statusMessage']; $identifier = $response['CustomerCreditCardTxnVoidRs']['CreditCardTransID']; } if (isset($response['CustomerCreditCardTxnVoidOrRefundRs'])) { $result = $response['CustomerCreditCardTxnVoidOrRefundRs']['@attributes']['statusCode']; $message = $response['CustomerCreditCardTxnVoidOrRefundRs']['@attributes']['statusMessage']; if (isset($response['CustomerCreditCardTxnVoidOrRefundRs']['CreditCardTransID'])) { $identifier = $response['CustomerCreditCardTxnVoidOrRefundRs']['CreditCardTransID']; } } $details->gateway_response = $as_array; if ($result === '0') { //Transaction was successful $details->identifier = $identifier; $details->timestamp = isset($signon['ServerDateTime']) ? $signon['ServerDateTime'] : ''; return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { //Transaction failed $details->reason = $message; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }
/** * Parse the response from the server * * @param array * @return object */ private function _parse_response($response) { $details = (object) array(); if (is_object($response)) { if ($response->code == '1') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { $details->reason = $response->message; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } } elseif (strstr($response, '<response>')) { $response = Payment_Utility::parse_xml($response); $response = Payment_Utility::arrayize_object($response); $details->gateway_response = $response; if ($response['code'] == '1') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { $details->reason = $response['message']; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } } else { $results = explode('&', urldecode($response)); foreach ($results as $result) { list($key, $value) = explode('=', $result); $gateway_response[$key] = $value; } $details->gateway_response = $gateway_response; $details->timestamp = isset($gateway_response['trnDate']) ? $gateway_response['trnDate'] : gmdate('c'); if (isset($gateway_response['trnApproved']) && $gateway_response['trnApproved'] == '1') { $details->identifier = isset($gateway_response['trnId']) ? $gateway_response['trnId'] : null; if (isset($gateway_response['rbAccountId'])) { $details->identifier = $gateway_response['rbAccountId']; } return Payment_Response::instance()->gateway_response('success', $this->_lib_method . '_success', $details); } else { $details->reason = isset($gateway_response['messageText']) ? $gateway_response['messageText'] : null; return Payment_Response::instance()->gateway_response('failure', $this->_lib_method . '_gateway_failure', $details); } } }
/** * Parse the response from the server * * @param object Always includes timestamp, gateway_response, reason * @return object */ protected function _parse_response($data) { // Since this module currently uses POST to make the gateway request // We know our current object can be simply typecasted back to an array. // IF THIS EVER CHANGES, USE $this->payments->arrayize_object($data); $results = explode('&', urldecode($data)); foreach ($results as $result) { list($key, $value) = explode('=', $result); $gateway_response[$key] = $value; } $details = (object) array(); $details->timestamp = gmdate('c'); $details->gateway_response = $gateway_response; // Full Gateway Response //Set response types $response_types = array('E' => $this->_lib_method . '_gateway_failure', '1' => $this->_lib_method . '_success', '0' => $this->_lib_method . '_local_failure'); // Default to Failure if data is not what is expected $status = 'failure'; // Setup Final Response if (isset($gateway_response['MESSAGE'])) { $details->reason = $gateway_response['MESSAGE']; } if (isset($gateway_response['STATUS'])) { $details->status = $gateway_response['STATUS']; // The request can be successful, yet have the card be declined } // Setup additional properties if successful if (isset($gateway_response['TRANS_ID'])) { $details->identifier = $gateway_response['TRANS_ID']; } // Return Local Response, because we didn't get an expected response from server if (!isset($gateway_response['STATUS'], $gateway_response['MESSAGE'])) { // @todo - Don't know if this should be a different response than "gateway" return Payment_Response::instance()->gateway_response($status, $response_types['E'], $details); } // Possible Responses are 1 = Approved, 0 = Decline, 'E' = Error $is_success = $data['STATUS'] === '1'; // Setup Response $status = $is_success ? 'success' : 'failure'; $response = $response_types[$gateway_response['STATUS']]; // Send it back! return Payment_Response::instance()->gateway_response($status, $response, $details); }
/** * Parse the response from the server * * @param array * @return object */ protected function _parse_response($xml) { $details = (object) array(); $as_array = Payment_Utility::arrayize_object($xml); $result = $as_array['Approved']; if (isset($as_array['OrderID']) && !empty($as_array['OrderID'])) { $identifier = $as_array['OrderID']; } if (isset($as_array['TransRefNumber'])) { $identifier2 = $as_array['TransRefNumber']; } $details->timestamp = $as_array['TransTime']; $details->gateway_response = $as_array; if (isset($identifier)) { $identifier = (string) $identifier; if (strlen($identifier) > 1) { $details->identifier = $identifier; } } if (isset($identifier2)) { $identifier2 = (string) $identifier2; if (strlen($identifier2) > 1) { $details->identifier2 = $identifier2; } } if ($result == 'APPROVED') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } if ($result == 'ERROR' or $result == 'DECLINED') { if (isset($as_array['ErrMsg'])) { $message = $as_array['ErrMsg']; $message = explode(':', $message); $message = $message[1]; } if (isset($message)) { $details->reason = $message; } return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } }