+--------------------------------------------------------------------+
*/
-
/*
+--------------------------------------------------------------------+
| eWAY Core Payment Module for CiviCRM version 5 & 1.9 |
* -----------------------------------------------------------------------------------------------
*/
+use Civi\Payment\Exception\PaymentProcessorException;
+
// require Standard eWAY API libraries
require_once 'eWAY/eWAY_GatewayRequest.php';
require_once 'eWAY/eWAY_GatewayResponse.php';
* Class CRM_Core_Payment_eWAY.
*/
class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
- // (not used, implicit in the API, might need to convert?)
- const CHARSET = 'UTF-8';
/**
* *******************************************************
$eWAYRequest = new GatewayRequest();
if (($eWAYRequest == NULL) || (!($eWAYRequest instanceof GatewayRequest))) {
- return self::errorExit(9001, "Error: Unable to create eWAY Request object.");
+ throw new PaymentProcessorException('Error: Unable to create eWAY Request object.', 9001);
}
$eWAYResponse = new GatewayResponse();
if (($eWAYResponse == NULL) || (!($eWAYResponse instanceof GatewayResponse))) {
- return self::errorExit(9002, "Error: Unable to create eWAY Response object.");
+ throw new PaymentProcessorException(9002, 'Error: Unable to create eWAY Response object.', 9002);
}
/*
$fullAddress = $params['street_address'] . ", " . $params['city'] . ", " . $params['state_province'] . ".";
$expireYear = substr($params['year'], 2, 2);
$expireMonth = sprintf('%02d', (int) $params['month']);
- // CiviCRM V1.9 - Picks up reasonable description
- //$description = $params['amount_level'];
- // CiviCRM V2.0 - Picks up description
$description = $params['description'];
$txtOptions = "";
// 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);
}
//----------------------------------------------------------------------------------------------------
$submit = curl_init($gateway_URL);
if (!$submit) {
- return self::errorExit(9004, 'Could not initiate connection to payment gateway');
+ throw new PaymentProcessorException('Could not initiate connection to payment gateway', 9004);
}
curl_setopt($submit, CURLOPT_POST, TRUE);
// Paranoia - in the unlikley event that 'curl' error fails
if (strlen($errorDesc) == 0) {
- $errorDesc = "Connection to eWAY payment gateway failed";
+ $errorDesc = 'Connection to eWAY payment gateway failed';
}
- return self::errorExit($errorNum, $errorDesc);
+ throw new PaymentProcessorException($errorDesc, $errorNum);
}
//----------------------------------------------------------------------------------------------------
// 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);
}
//----------------------------------------------------------------------------------------------------
if (self::isError($eWAYResponse)) {
$eWayTrxnError = $eWAYResponse->Error();
CRM_Core_Error::debug_var('eWay Error', $eWayTrxnError, TRUE, TRUE);
- if (substr($eWayTrxnError, 0, 6) == "Error:") {
- return self::errorExit(9008, $eWayTrxnError);
+ if (substr($eWayTrxnError, 0, 6) === 'Error:') {
+ throw new PaymentProcessorException($eWayTrxnError, 9008);
}
$eWayErrorCode = substr($eWayTrxnError, 0, 2);
$eWayErrorDesc = substr($eWayTrxnError, 3);
- return self::errorExit(9008, "Error: [" . $eWayErrorCode . "] - " . $eWayErrorDesc . ".");
- }
-
- //-----------------------------------------------------------------------------------------------------
- // Cross-Check - the unique 'TrxnReference' we sent out should match the just received 'TrxnReference'
- //
- // PLEASE NOTE: If this occurs (which is highly unlikely) its a serious error as it would mean we have
- // received an OK status from eWAY, but their Gateway has not returned the correct unique
- // token - ie something is broken, BUT money has been taken from the client's account,
- // so we can't very well error-out as CiviCRM will then not process the registration.
- // There is an error message commented out here but my preferred response to this unlikley
- // possibility is to email 'support@eWAY.com.au'
- //-----------------------------------------------------------------------------------------------------
- $eWayTrxnReference_OUT = $eWAYRequest->GetTransactionNumber();
- $eWayTrxnReference_IN = $eWAYResponse->InvoiceReference();
-
- if ($eWayTrxnReference_IN != $eWayTrxnReference_OUT) {
- // return self::errorExit( 9009, "Error: Unique Trxn code was not returned by eWAY Gateway. This is extremely unusual! Please contact the administrator of this site immediately with details of this transaction.");
-
- }
-
- /*
- //----------------------------------------------------------------------------------------------------
- // Test mode always returns trxn_id = 0 - so we fix that here
- //
- // NOTE: This code was taken from the AuthorizeNet payment processor, however it now appears
- // unnecessary for the eWAY gateway - Left here in case it proves useful
- //----------------------------------------------------------------------------------------------------
- if ( $this->_mode == 'test' ) {
- $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test%'";
- $p = array( );
- $trxn_id = strval( CRM_Core_Dao::singleValueQuery( $query, $p ) );
- $trxn_id = str_replace( 'test', '', $trxn_id );
- $trxn_id = intval($trxn_id) + 1;
- $params['trxn_id'] = sprintf('test%08d', $trxn_id);
- }
- else {
- $params['trxn_id'] = $eWAYResponse->TransactionNumber();
+ throw new PaymentProcessorException('Error: [' . $eWayErrorCode . "] - " . $eWayErrorDesc . '.', 9008);
}
- */
//=============
// Success !
//=============
$beaglestatus = $eWAYResponse->BeagleScore();
if (!empty($beaglestatus)) {
- $beaglestatus = ": " . $beaglestatus;
+ $beaglestatus = ': ' . $beaglestatus;
}
$params['trxn_result_code'] = $eWAYResponse->Status() . $beaglestatus;
$params['gross_amount'] = $eWAYResponse->Amount();
return $params;
}
- // end function doDirectPayment
-
/**
* Checks the eWAY response status - returning a boolean false if status != 'true'.
*
public function isError(&$response) {
$status = $response->Status();
- if ((stripos($status, "true")) === FALSE) {
+ if ((stripos($status, 'true')) === FALSE) {
return TRUE;
}
return FALSE;
}
/**
- * 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
*
* NOTE: Called by Events and Contribute to check config params are set prior to trying
* register any credit card details
*
* @return null|string
- * @internal param string $mode the mode we are operating in (live or test) - not used but could be
- * to check that the 'test' mode CustomerID was equal to '87654321' and that the URL was
- * set to https://www.eway.com.au/gateway_cvn/xmltest/TestPage.asp
- *
- * returns string $errorMsg if any errors found - null if OK
- *
- * *****************************************************************************************
+ * returns string $errorMsg if any errors found - null if OK
*/
public function checkConfig() {
$errorMsg = [];
if (!empty($errorMsg)) {
return implode('<p>', $errorMsg);
}
- else {
- return NULL;
- }
+ return NULL;
}
}
-// end class CRM_Core_Payment_eWAY