Skip to content

Commit

Permalink
Fix probably-unused core payment processors to throw extensions
Browse files Browse the repository at this point in the history
These 2 processors are probably entirely unused and are not enabled on new installs. However, as they are still in core,
and removing them will take a plan + time, we should have them model 'good behaviour' - ie throwing exceptions
rather than returning errors
  • Loading branch information
eileenmcnaughton committed Jun 5, 2020
1 parent 98215be commit 602de06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 96 deletions.
55 changes: 14 additions & 41 deletions CRM/Core/Payment/FirstData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Payment\Exception\PaymentProcessorException;

/**
* Note that in order to use FirstData / LinkPoint you need a certificate (.pem) file issued by them
* and a store number. You can configure the path to the certificate and the store number
Expand Down Expand Up @@ -52,21 +54,16 @@
* **************************
*/
class CRM_Core_Payment_FirstData extends CRM_Core_Payment {
// (not used, implicit in the API, might need to convert?)
const CHARSET = 'UFT-8';

/**
* Constructor.
*
* @param string $mode
* The mode of operation: live or test.
*
* @param $paymentProcessor
*
* @return \CRM_Core_Payment_FirstData *******************************************************
* @param array $paymentProcessor
*/
public function __construct($mode, &$paymentProcessor) {
// live or test
$this->_mode = $mode;
$this->_paymentProcessor = $paymentProcessor;
}
Expand All @@ -87,9 +84,9 @@ public function mapProcessorFieldstoParams($params) {
/*concatenate full customer name first - code from EWAY gateway
*/

$credit_card_name = $params['first_name'] . " ";
$credit_card_name = $params['first_name'] . ' ';
if (strlen($params['middle_name']) > 0) {
$credit_card_name .= $params['middle_name'] . " ";
$credit_card_name .= $params['middle_name'] . ' ';
}
$credit_card_name .= $params['last_name'];

Expand Down Expand Up @@ -182,7 +179,7 @@ public function doDirectPayment(&$params) {
// Check to see if we have a duplicate before we send
//----------------------------------------------------------------------------------------------------
if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) {
return self::errorExit(9003, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt from eWAY. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.');
throw new PaymentProcessorException('It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt from eWAY. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.', 9003);
}
//----------------------------------------------------------------------------------------------------
// Convert to XML using function provided by payment processor
Expand All @@ -196,7 +193,7 @@ public function doDirectPayment(&$params) {

$ch = curl_init($host);
if (!$ch) {
return self::errorExit(9004, 'Could not initiate connection to payment gateway');
throw new PaymentProcessorException('Could not initiate connection to payment gateway', 9004);
}

curl_setopt($ch, CURLOPT_POST, 1);
Expand Down Expand Up @@ -236,10 +233,10 @@ public function doDirectPayment(&$params) {
$errorDesc = "Connection to payment gateway failed";
}
if ($errorNum == 60) {
return self::errorExit($errorNum, "Curl error - " . $errorDesc . " Try this link for more information http://curl.haxx.se/docs/sslcerts.html");
throw new PaymentProcessorException("Curl error - " . $errorDesc . ' Try this link for more information http://curl.haxx.se/docs/sslcerts.html', $errorNum);
}

return self::errorExit($errorNum, "Curl error - " . $errorDesc . " your key is located at " . $key . " the url is " . $host . " xml is " . $requestxml . " processor response = " . $processorResponse);
throw new PaymentProcessorException('Curl error - ' . $errorDesc . ' your key is located at ' . $key . ' the url is ' . $host . ' xml is ' . $requestxml . ' processor response = ' . $processorResponse, $errorNum);
}

//----------------------------------------------------------------------------------------------------
Expand All @@ -249,14 +246,14 @@ public function doDirectPayment(&$params) {
// any reason, the return value will be the boolean false.
//----------------------------------------------------------------------------------------------------
if (($responseData === FALSE) || (strlen($responseData) == 0)) {
return self::errorExit(9006, "Error: Connection to payment gateway failed - no data returned.");
throw new PaymentProcessorException('Error: Connection to payment gateway failed - no data returned.', 9006);
}

//----------------------------------------------------------------------------------------------------
// If gateway returned no data - tell 'em and bail out
//----------------------------------------------------------------------------------------------------
if (empty($responseData)) {
return self::errorExit(9007, "Error: No data returned from payment gateway.");
throw new PaymentProcessorException('Error: No data returned from payment gateway.', 9007);
}

//----------------------------------------------------------------------------------------------------
Expand All @@ -271,8 +268,8 @@ public function doDirectPayment(&$params) {
$processorResponse = lphp::decodeXML($responseData);

// transaction failed, print the reason
if ($processorResponse["r_approved"] != "APPROVED") {
return self::errorExit(9009, "Error: [" . $processorResponse['r_error'] . "] - from payment processor");
if ($processorResponse['r_approved'] !== "APPROVED") {
throw new PaymentProcessorException('Error: [' . $processorResponse['r_error'] . '] - from payment processor', 9009);
}
else {

Expand Down Expand Up @@ -302,28 +299,6 @@ public function doDirectPayment(&$params) {
}
}

// end function doDirectPayment

/**
* Produces error message and returns from class.
*
* @param int $errorCode
* @param string $errorMessage
*
* @return object
*/
public function &errorExit($errorCode = NULL, $errorMessage = NULL) {
$e = CRM_Core_Error::singleton();

if ($errorCode) {
$e->push($errorCode, 0, NULL, $errorMessage);
}
else {
$e->push(9000, 0, NULL, 'Unknown System Error.');
}
return $e;
}

/**
* This public function checks to see if we have the right processor config values set.
*
Expand Down Expand Up @@ -352,9 +327,7 @@ public function checkConfig() {
if (!empty($errorMsg)) {
return implode('<p>', $errorMsg);
}
else {
return NULL;
}
return NULL;
}

}
Expand Down
72 changes: 17 additions & 55 deletions CRM/Core/Payment/PayJunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*
*/

use Civi\Payment\Exception\PaymentProcessorException;

/**
*
* @package CRM
Expand All @@ -28,9 +30,7 @@ class CRM_Core_Payment_PayJunction extends CRM_Core_Payment {
* @param string $mode
* The mode of operation: live or test.
*
* @param $paymentProcessor
*
* @return \CRM_Core_Payment_PayJunction
* @param array $paymentProcessor
*/
public function __construct($mode, &$paymentProcessor) {
$this->_mode = $mode;
Expand Down Expand Up @@ -58,16 +58,16 @@ public function doDirectPayment(&$params) {
$pjpgCustInfo->setEmail($params['email']);

$billing = [
"logon" => $logon,
"password" => $password,
"url_site" => $url_site,
"first_name" => $params['first_name'],
"last_name" => $params['last_name'],
"address" => $params['street_address'],
"city" => $params['city'],
"province" => $params['state_province'],
"postal_code" => $params['postal_code'],
"country" => $params['country'],
'logon' => $logon,
'password' => $password,
'url_site' => $url_site,
'first_name' => $params['first_name'],
'last_name' => $params['last_name'],
'address' => $params['street_address'],
'city' => $params['city'],
'province' => $params['state_province'],
'postal_code' => $params['postal_code'],
'country' => $params['country'],
];
$pjpgCustInfo->setBilling($billing);

Expand Down Expand Up @@ -96,8 +96,8 @@ public function doDirectPayment(&$params) {
$pjpgTxn->setCustInfo($pjpgCustInfo);

// empty installments convert to 999 because PayJunction do not allow open end donation
if ($params['installments'] == "") {
$params['installments'] = "999";
if ($params['installments'] == '') {
$params['installments'] = '999';
}

// create recurring object
Expand Down Expand Up @@ -144,14 +144,7 @@ public function doDirectPayment(&$params) {
$pjpgResponse = $pjpgHttpPost->getPJpgResponse();

if (self::isError($pjpgResponse)) {
return self::error($pjpgResponse);
}

/* Check for application errors */

$result = self::checkResult($pjpgResponse);
if (is_a($result, 'CRM_Core_Error')) {
return $result;
throw new PaymentProcessorException($pjpgResponse);
}

// Success
Expand Down Expand Up @@ -182,16 +175,6 @@ public function isError(&$response) {
}
}

/**
* ignore for now, more elaborate error handling later.
* @param $response
*
* @return mixed
*/
public function &checkResult(&$response) {
return $response;
}

/**
* Get the value of a field if set.
*
Expand All @@ -211,25 +194,6 @@ public function _getParam($field) {
}
}

/**
* @param null $error
*
* @return object
*/
public function &error($error = NULL) {
$e = CRM_Core_Error::singleton();
if ($error) {
$e->push($error['dc_response_code'],
0, NULL,
$error['dc_response_message']
);
}
else {
$e->push(9001, 0, NULL, "Unknown System Error.");
}
return $e;
}

/**
* Set a field to the specified value. Value must be a scalar (int,
* float, string, or boolean)
Expand Down Expand Up @@ -272,9 +236,7 @@ public function checkConfig() {
if (!empty($error)) {
return implode('<p>', $error);
}
else {
return NULL;
}
return NULL;
}

}
Expand Down

0 comments on commit 602de06

Please sign in to comment.