/** * Sets appropriate parameters for checking out to Ogone * * @param array $params name value pair of contribution datat * * @return void * @access public * */ function doTransferCheckout($params, $component) { $config = CRM_Core_Config::singleton(); CRM_Core_Error::debug_var('doTransferCheckOut - params', $params); CRM_Core_Error::debug_var('doTransferCheckOut - component', $component); if ($component != 'contribute' && $component != 'event') { CRM_Core_Error::fatal(ts('Component is invalid')); } // Start building our parameters // - Algemene parameters // PSPID // orderID // amount // currency // language // CN // EMAIL // ownerZIP // owneraddress // ownercty // ownertown // ownertelno // - Controle voor betaling // SHASign // - Feedback na betaling // accepturl // declineurl // exceptionurl // cancelurl // // In order to calculate SHA1 hash: // * parameters sorted in alphabetical order, // * parameter names in uppercase // * name=value pairs separated with SHA passphrase (defined in Ogone > Technical info settings) // $OgoneParams['PSPID'] = $this->_paymentProcessor['user_name']; //TODO: from Ogone tech spec // Although our system can accept up to 30 characters, the norm for most acquirers is 10 or 12. // The exact accepted length and data validation format depend on the acquirer/bank. // If the orderID does not comply to the ref2 rules set by the acquirer, we’ll send our PAYID as ref2 to the acquirer instead. // Avoid using spaces or special characters in the orderID. // // We need to encode following values in orderID to allow further processing in OgoneIPN.php // getContext() in OgoneIPN.php // contributionId // eventID // newOrderNotify() in OgoneIPN.php // contactID // contributionId // eventID // participantID // membershipID // invoiceID - SKIP THIS AND MODIFY newOrderNotify() to ignore this. // invoiceID is too long and causes Ogone orderid to exceed its maximum value of 30 chars. // $orderID = array(CRM_Utils_Array::value('contactID', $params), CRM_Utils_Array::value('contributionID', $params), CRM_Utils_Array::value('contributionTypeID', $params), CRM_Utils_Array::value('eventID', $params), CRM_Utils_Array::value('participantID', $params), CRM_Utils_Array::value('membershipID', $params)); $OgoneParams['orderID'] = implode('-', $orderID); $OgoneParams['amount'] = sprintf("%d", (double) $params['amount'] * 100); $OgoneParams['currency'] = 'EUR'; if (isset($params['preferred_language'])) { $OgoneParams['language'] = $params['preferred_language']; } else { $OgoneParams['language'] = 'nl_NL'; } if (isset($params['first_name']) || isset($params['last_name'])) { $OgoneParams['CN'] = $params['first_name'] . ' ' . $params['last_name']; } if (isset($params['email'])) { $OgoneParams['EMAIL'] = $params['email']; } if (isset($params['postal_code-1'])) { $OgoneParams['ownerZIP'] = $params['postal_code-1']; } if (isset($params['street_address-1'])) { $OgoneParams['owneraddress'] = $params['street_address-1']; } if (isset($params['country-1'])) { $OgoneParams['ownercty'] = $params['country-1']; } if (isset($params['city-1'])) { $OgoneParams['ownertown'] = $params['city-1']; } if (isset($params['phone-1'])) { $OgoneParams['ownertelno'] = $params['phone']; } $notifyURL = $config->userFrameworkResourceURL . "extern/OgoneNotify.php"; $notifyURL .= "?qfKey=" . $params['qfKey']; $OgoneParams['accepturl'] = $notifyURL; $OgoneParams['declineurl'] = $notifyURL; $OgoneParams['exceptionurl'] = $notifyURL; $OgoneParams['cancelurl'] = $notifyURL; // ogone was failing with "unknown order/1/s/" due to non ascii7 char. This is an ugly workaround foreach ($OgoneParams as &$str) { $from = 'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'; $to = 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY'; $keys = array(); $values = array(); preg_match_all('/./u', $from, $keys); preg_match_all('/./u', $to, $values); $mapping = array_combine($keys[0], $values[0]); $str = strtr($str, $mapping); } $shaSign = calculateSHA1($OgoneParams, $this->_paymentProcessor['password']); $OgoneParams['SHASign'] = $shaSign; //CRM_Core_Error::debug_var('doTransferCheckout - OgoneParams', $OgoneParams); // Allow further manipulation of the arguments via custom hooks .. CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $OgoneParams); // Build our query string; $query_string = ''; foreach ($OgoneParams as $name => $value) { $query_string .= $name . '=' . $value . '&'; } // Remove extra & $query_string = rtrim($query_string, '&'); // Redirect the user to the payment url. CRM_Utils_System::redirect($this->_paymentProcessor['url_site'] . '?' . $query_string); exit; }
/** * This method handles the response that will be invoked (from OgoneNotify.php) every time * a notification or request is sent by the Ogone Server. * */ static function main($qfKey) { require_once 'CRM/Utils/Request.php'; $config = CRM_Core_Config::singleton(); //unset($ogoneParams['qfKey']); $ogoneParams = array(); foreach ($_GET as $param => $val) { $ogoneParams[$param] = $val; } $shaSign = $ogoneParams['SHASIGN']; unset($ogoneParams['SHASIGN']); // remove qfKey from list of parameters created by Ogone unset($ogoneParams['qfKey']); // decode orderID $order_array = explode('-', $ogoneParams['orderID']); //$privateData['invoiceID'] = (isset($order_array[0])) ? $order_array[0] : ''; $privateData['contactID'] = isset($order_array[0]) ? $order_array[0] : ''; $privateData['contributionID'] = isset($order_array[1]) ? $order_array[1] : ''; $privateData['contributionTypeID'] = isset($order_array[2]) ? $order_array[2] : ''; $privateData['eventID'] = isset($order_array[3]) ? $order_array[3] : ''; $privateData['participantID'] = isset($order_array[4]) ? $order_array[4] : ''; $privateData['membershipID'] = isset($order_array[5]) ? $order_array[5] : ''; //CRM_Core_Error::debug_var('privateData', $privateData); list($mode, $component, $paymentProcessorID, $duplicateTransaction) = self::getContext($privateData); $mode = $mode ? 'test' : 'live'; $paymentProcessorID = intval($paymentProcessorID); //CRM_Core_Error::debug_var('mode', $mode); //CRM_Core_Error::debug_var('component', $component); //CRM_Core_Error::debug_var('paymentProcessorID', $paymentProcessorID); //CRM_Core_Error::debug_var('duplicateTransaction', $duplicateTransaction); //require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Financial/BAO/PaymentProcessor.php'; //$paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode); $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode); //CRM_Core_Error::debug_var('paymentProcessor', $paymentProcessor); $shaCalc = calculateSHA1($ogoneParams, $paymentProcessor['signature']); if (strcmp($shaSign, $shaCalc)) { CRM_Core_Error::debug_log_message("Failure: SHA1-out signature does not match calculated value. Request parameters might be forged."); exit; } CRM_Core_Error::debug_log_message("SHA1-out signature matches."); // Process the transaction. if ($duplicateTransaction == 0) { // Process the transaction. $ipn =& self::singleton($mode, $component, $paymentProcessor); $ipn->newOrderNotify($ogoneParams['STATUS'], $privateData, $component, $ogoneParams['amount'], $ogoneParams['PAYID']); } // Redirect our users to the correct url. if ($ogoneParams['STATUS'] == '2' || $ogoneParams['STATUS'] == '1' || $ogoneParams['STATUS'] == '0') { // Order is declined (status = 2), cancelled (status = 1) or invalid (status = 0) CRM_Core_Error::debug_log_message("Ogone payment is declined, cancelled or invalid."); if ($component == "event") { $finalURL = CRM_Utils_System::url('civicrm/event/confirm', "reset=1&cc=fail&participantId={$privateData['participantID']}", false, null, false); } elseif ($component == "contribute") { $finalURL = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Main_display=1&cancel=1&qfKey={$qfKey}", false, null, false); } } else { if ($component == "event") { $finalURL = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$qfKey}", false, null, false); } elseif ($component == "contribute") { $finalURL = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$qfKey}", false, null, false); } } CRM_Utils_System::redirect($finalURL); }