Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Eway(Single Currency) Payment Processor Type out into its own… #18349

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!/ext/sequentialcreditnotes
!/ext/flexmailer
!/ext/eventcart
!/ext/ewaysingle
!/ext/search
!/ext/financialacls
backdrop/
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/DAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Event/Event.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:164ee1a507b9244536114d1569ccff1e)
* (GenCodeChecksum:82ba48cbb804cf6f4b26fa50f07d44db)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 Why is this in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is there I'll spin that off separately

*/

/**
Expand Down
37 changes: 34 additions & 3 deletions CRM/Upgrade/Incremental/php/FiveThirtyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,39 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_5_31_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('enableeWAYSingleCurrencyExtension', 'enableEwaySingleExtension');
}

public static function enableEwaySingleExtension(CRM_Queue_TaskContext $ctx) {
$eWAYPaymentProcessorType = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_payment_processor_type WHERE class_name = 'Payment_eWAY'");
if ($eWAYPaymentProcessorType) {
$insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([
'type' => 'module',
'full_name' => 'ewaysingle',
'name' => 'eway Single currency extension',
'label' => 'eway Single currency extension',
'file' => 'ewaysingle',
'schema_version' => NULL,
'is_active' => 1,
]);
CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL());
$managedEntity = CRM_Utils_SQL_Insert::into('civicrm_managed')->row([
'name' => 'eWAY',
'module' => 'ewaysingle',
'entity_type' => 'PaymentProcessorType',
'entity_id' => $eWAYPaymentProcessorType,
'cleanup' => NULL,
]);
CRM_Core_DAO::executeQuery($managedEntity->usingReplace()->toSQL());
}
return TRUE;
}

}
1 change: 1 addition & 0 deletions distmaker/dists/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function dm_core_exts() {
echo ext/sequentialcreditnotes
echo ext/flexmailer
echo ext/eventcart
echo ext/ewaysingle
echo ext/financialacls
}

Expand Down
24 changes: 24 additions & 0 deletions ext/ewaysingle/CRM/Core/Payment/eWAY.mgd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
// This file declares a managed database record of type "ReportTemplate".
// The record will be automatically inserted, updated, or deleted from the
// database as appropriate. For more details, see "hook_civicrm_managed" at:
// http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference
return array(
0 => array(
'name' => 'eWAY',
'entity' => 'PaymentProcessorType',
'params' => array(
'version' => 3,
'name' => 'eWAY',
'title' => 'eWAY (Single Currency)',
'description' => '',
'user_name_label' => 'Customer ID',
'class_name' => 'Payment_eWAY',
'billing_mode' => 1,
'url_site_default' => 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp',
'payment_type' => 1,
'is_recur' => 0,
'url_site_test_default' => 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp',
),
),
);
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@
*/

use Civi\Payment\Exception\PaymentProcessorException;
use CRM_Ewaysingle_ExtensionUtil as E;

// require Standard eWAY API libraries
require_once 'eWAY/eWAY_GatewayRequest.php';
require_once 'eWAY/eWAY_GatewayResponse.php';
require_once E::path('lib/eWAY/eWAY_GatewayRequest.php');
require_once E::path('lib/eWAY/eWAY_GatewayResponse.php');

/**
* Class CRM_Core_Payment_eWAY.
*/
class CRM_Core_Payment_eWAY extends CRM_Core_Payment {

/**
* @var GuzzleHttp\Client
*/
protected $guzzleClient;

/**
* *******************************************************
* Constructor
Expand All @@ -105,6 +111,20 @@ public function __construct($mode, &$paymentProcessor) {
$this->_paymentProcessor = $paymentProcessor;
}

/**
* @return \GuzzleHttp\Client
*/
public function getGuzzleClient(): \GuzzleHttp\Client {
return $this->guzzleClient ?? new \GuzzleHttp\Client();
}

/**
* @param \GuzzleHttp\Client $guzzleClient
*/
public function setGuzzleClient(\GuzzleHttp\Client $guzzleClient) {
$this->guzzleClient = $guzzleClient;
}

/**
* Sends request and receive response from eWAY payment process.
*
Expand Down Expand Up @@ -245,50 +265,13 @@ public function doDirectPayment(&$params) {
//----------------------------------------------------------------------------------------------------
$requestxml = $eWAYRequest->ToXML();

$submit = curl_init($gateway_URL);

if (!$submit) {
throw new PaymentProcessorException('Could not initiate connection to payment gateway', 9004);
}

curl_setopt($submit, CURLOPT_POST, TRUE);
// return the result on success, FALSE on failure
curl_setopt($submit, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($submit, CURLOPT_POSTFIELDS, $requestxml);
curl_setopt($submit, CURLOPT_TIMEOUT, 36000);
// if open_basedir or safe_mode are enabled in PHP settings CURLOPT_FOLLOWLOCATION won't work so don't apply it
// it's not really required CRM-5841
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
// ensures any Location headers are followed
curl_setopt($submit, CURLOPT_FOLLOWLOCATION, 1);
}

// Send the data out over the wire
//--------------------------------
$responseData = curl_exec($submit);

//----------------------------------------------------------------------------------------------------
// See if we had a curl error - if so tell 'em and bail out
//
// NOTE: curl_error does not return a logical value (see its documentation), but
// a string, which is empty when there was no error.
//----------------------------------------------------------------------------------------------------
if ((curl_errno($submit) > 0) || (strlen(curl_error($submit)) > 0)) {
$errorNum = curl_errno($submit);
$errorDesc = curl_error($submit);

// Paranoia - in the unlikley event that 'curl' errno fails
if ($errorNum == 0) {
$errorNum = 9005;
}

// Paranoia - in the unlikley event that 'curl' error fails
if (strlen($errorDesc) == 0) {
$errorDesc = 'Connection to eWAY payment gateway failed';
}

throw new PaymentProcessorException($errorDesc, $errorNum);
}
$responseData = (string) $this->getGuzzleClient()->post($this->_paymentProcessor['url_site'], [
'body' => $requestxml,
'curl' => [
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => Civi::settings()->get('verifySSL'),
],
])->getBody();

//----------------------------------------------------------------------------------------------------
// If null data returned - tell 'em and bail out
Expand All @@ -307,11 +290,6 @@ public function doDirectPayment(&$params) {
throw new PaymentProcessorException('Error: No data returned from payment gateway.', 9007);
}

//----------------------------------------------------------------------------------------------------
// Success so far - close the curl and check the data
//----------------------------------------------------------------------------------------------------
curl_close($submit);

//----------------------------------------------------------------------------------------------------
// Payment successfully sent to gateway - process the response now
//----------------------------------------------------------------------------------------------------
Expand Down
Loading