Skip to content

Commit

Permalink
Change eWAY processor to use guzzle, fix style issues and update info…
Browse files Browse the repository at this point in the history
….xml and add in test of eWAY single Currency payment processor

Update README
  • Loading branch information
seamuslee001 committed Sep 4, 2020
1 parent a6ccfe6 commit 63bb954
Show file tree
Hide file tree
Showing 10 changed files with 1,471 additions and 1,253 deletions.
4 changes: 2 additions & 2 deletions CRM/Upgrade/Incremental/php/FiveThirtyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
* @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');
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('enableeWAYSingleCurrencyExtension', 'enableEwaySingleExtension');
}

public static function enableEwaySingleExtension(CRM_Queue_TaskContext $ctx) {
Expand Down
75 changes: 26 additions & 49 deletions ext/ewaysingle/CRM/Core/Payment/eWAY.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
*/
class CRM_Core_Payment_eWAY extends CRM_Core_Payment {

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

/**
* *******************************************************
* Constructor
Expand All @@ -106,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 @@ -246,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 @@ -308,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
28 changes: 8 additions & 20 deletions ext/ewaysingle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,31 @@

![Screenshot](/images/screenshot.png)

(*FIXME: In one or two paragraphs, describe what the extension does and why one would download it. *)
This extension is aimed at containing the original Core eWAY (Single Currency) Payment Processor Type that is legacy. See known issues below

The extension is licensed under [AGPL-3.0](LICENSE.txt).

## Requirements

* PHP v7.0+
* CiviCRM (*FIXME: Version number*)
* PHP v7.1+
* CiviCRM 5.31

## Installation (Web UI)

This extension has not yet been published for installation via the web UI.
Navigate to the Extensions Page and install the extension.

## Installation (CLI, Zip)
## Installation (CLI)

Sysadmins and developers may download the `.zip` file for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).
To enable this extension in the CLI do the following

```bash
cd <extension-dir>
cv dl ewaysingle@https://github.com/FIXME/ewaysingle/archive/master.zip
```

## Installation (CLI, Git)

Sysadmins and developers may clone the [Git](https://en.wikipedia.org/wiki/Git) repo for this extension and
install it with the command-line tool [cv](https://github.com/civicrm/cv).

```bash
git clone https://github.com/FIXME/ewaysingle.git
cv en ewaysingle
```

## Usage

(* FIXME: Where would a new user navigate to get started? What changes would they see? *)
The eWAY (Single Currency) Payment Processor Type will show up as one of the options when your adding in a PaymentProcessor.

## Known Issues

(* FIXME *)
This Payment Processor does not do any kind of recurring payments at all for that you would need another extension e.g. [Agileware Eway Recurring](https://github.com/agileware/au.com.agileware.ewayrecurring)
14 changes: 7 additions & 7 deletions ext/ewaysingle/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
<email>[email protected]</email>
</maintainer>
<urls>
<url desc="Main Extension Page">http://FIXME</url>
<url desc="Documentation">http://FIXME</url>
<url desc="Support">http://FIXME</url>
<url desc="Main Extension Page">https://github.com/civicrm/civicrm-core/blob/master/ext/ewayrecurring</url>
<url desc="Documentation">https://github.com/civicrm/civicrm-core/blob/master/ext/ewayrecurring</url>
<url desc="Support">https://github.com/civicrm/civicrm-core/blob/master/ext/ewayrecurring</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-09-04</releaseDate>
<releaseDate>2020-10-07</releaseDate>
<version>1.0</version>
<develStage>alpha</develStage>
<develStage>stable</develStage>
<compatibility>
<ver>5.0</ver>
<ver>5.31</ver>
</compatibility>
<comments>This is a new, undeveloped module</comments>
<comments>This is an extension to contain the eWAY Single Currency Payment Processor</comments>
<classloader>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
Expand Down
Loading

0 comments on commit 63bb954

Please sign in to comment.