Skip to content

Commit

Permalink
5.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrovv committed Dec 12, 2016
1 parent 5899fa1 commit 72e919c
Show file tree
Hide file tree
Showing 26 changed files with 715 additions and 57 deletions.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*Put a short and clear description of the bug or issue here, if needed*

**This is for features**:

TODO:

* [ ] Some feature TODO
* [ ] Another feature TODO

**This is for bugs**

**Steps to Reproduce**

* Step 1
* Step 2
* Step 3, etc

**Expected Results**

**Actual Results**

**Browser/Operating System**

**Additional Comments**
18 changes: 18 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
* Description of changes 1
* Description of changes 2
* Description of changes 3, etc

Fixes eMerchantPay/xcart-ecp-plugin#number

-----------------

Before merging the PR make sure the following are checked:

* [ ] [Good commit messages][1] are used.
* [ ] Commit message starts with `{f|b}{year}{month}{day}{num}`, e.g. f2016071101
* [ ] Necessary specs are added.
* [ ] All specs are passing.
* [ ] All automated or manual PR comments are resolved or proper explanation is included for the given change
* [ ] The PR relates to **only** one subject with a clear title

[1]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a Payment Module for X-Cart, that gives you the ability to process payme
Requirements
------------

* X-Cart 5.2.x (you can get this plugin to work on older 5.X versions simply by tweaking ```Main.php```)
* X-Cart 5.3.x (you can get this plugin to work on older 5.2 versions simply by changing the __Major Version__ to ```5.2``` in ```Main.php```)
* [GenesisPHP v1.4](https://github.com/GenesisGateway/genesis_php) - (Integrated in Module)
* PCI-certified server in order to use ```E-ComProcessing Direct```

Expand Down
38 changes: 36 additions & 2 deletions classes/XLite/Module/EComProcessing/Genesis/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function getModuleName()
*/
public static function getMajorVersion()
{
return '5.2';
return '5.3';
}

/**
Expand All @@ -78,7 +78,7 @@ public static function getMajorVersion()
*/
public static function getMinorVersion()
{
return '3';
return '2';
}

/**
Expand Down Expand Up @@ -180,4 +180,38 @@ public static function isStoreOverSecuredConnection()
{
return \XLite\Core\Config::getInstance()->Security->customer_security;
}

/**
* Retrieves the X-Cart Core Version
*
* @return string
*/
public static function getCurrentCoreVersion()
{
return \XLite::getInstance()->getVersion();
}

/**
* Detects if the X-Cart Core Version is 5.2
*
* @return bool
*/
public static function getIsCoreVersion52()
{
return
version_compare(self::getCurrentCoreVersion(), '5.2', '>=') &&
version_compare(self::getCurrentCoreVersion(), '5.3', '<=');
}

/**
* Detects if the X-Cart Core Version is 5.3
*
* @return bool
*/
public static function getIsCoreVersion53()
{
return
version_compare(self::getCurrentCoreVersion(), '5.3', '>=') &&
version_compare(self::getCurrentCoreVersion(), '5.4', '<=');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,39 @@ public function doCapture(\XLite\Model\Payment\BackendTransaction $transaction)

$capture->execute();

$result = true;
$gatewayResponseObject = $capture->response()->getResponseObject();

$status = \XLite\Model\Payment\Transaction::STATUS_SUCCESS;
$status =
$gatewayResponseObject->status == \Genesis\API\Constants\Transaction\States::APPROVED
? \XLite\Model\Payment\Transaction::STATUS_SUCCESS
: \XLite\Model\Payment\Transaction::STATUS_FAILED;

$transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(
\XLite\Model\Order\Status\Payment::STATUS_PAID
);
$result = $status == \XLite\Model\Payment\Transaction::STATUS_SUCCESS;

if ($result) {
$transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(
\XLite\Model\Order\Status\Payment::STATUS_PAID
);

$this->updateTransactionData($transaction, $capture->response()->getResponseObject());
$this->updateTransactionData($transaction, $gatewayResponseObject);

\XLite\Core\TopMessage::getInstance()
->addInfo(
$capture->response()->getResponseObject()->message
\XLite\Core\TopMessage::getInstance()->addInfo(
$gatewayResponseObject->message
);
} else {
$this->updateTransactionData($transaction, $gatewayResponseObject);
\XLite\Core\TopMessage::addError(
$gatewayResponseObject->message
);
}
} catch (\Exception $e) {
$result = false;

$status = \XLite\Model\Payment\Transaction::STATUS_FAILED;

\XLite\Core\TopMessage::getInstance()->addError($e->getMessage());
\XLite\Core\TopMessage::getInstance()->addError(
$e->getMessage()
);
}

$transaction->setStatus($status);
Expand Down Expand Up @@ -307,27 +320,39 @@ public function doRefund(\XLite\Model\Payment\BackendTransaction $transaction)

$refund->execute();

$result = true;
$gatewayResponseObject = $refund->response()->getResponseObject();

$status = \XLite\Model\Payment\Transaction::STATUS_SUCCESS;
$status =
$gatewayResponseObject->status == \Genesis\API\Constants\Transaction\States::APPROVED
? \XLite\Model\Payment\Transaction::STATUS_SUCCESS
: \XLite\Model\Payment\Transaction::STATUS_FAILED;

$transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(
\XLite\Model\Order\Status\Payment::STATUS_REFUNDED
);
$result = $status == \XLite\Model\Payment\Transaction::STATUS_SUCCESS;

if ($result) {
$transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(
\XLite\Model\Order\Status\Payment::STATUS_REFUNDED
);

$this->updateTransactionData($transaction, $refund->response()->getResponseObject());
$this->updateTransactionData($transaction, $gatewayResponseObject);

\XLite\Core\TopMessage::getInstance()
->addInfo(
$refund->response()->getResponseObject()->message
\XLite\Core\TopMessage::getInstance()->addInfo(
$gatewayResponseObject->message
);
} else {
$this->updateTransactionData($transaction, $gatewayResponseObject);
\XLite\Core\TopMessage::addError(
$gatewayResponseObject->message
);
}
} catch (\Exception $e) {
$result = false;

$status = \XLite\Model\Payment\Transaction::STATUS_FAILED;

\XLite\Core\TopMessage::getInstance()
->addError($e->getMessage());
\XLite\Core\TopMessage::getInstance()->addError(
$e->getMessage()
);
}

$transaction->setStatus($status);
Expand Down Expand Up @@ -376,28 +401,39 @@ protected function doVoid(\XLite\Model\Payment\BackendTransaction $transaction)

$void->execute();

$result = true;
$gatewayResponseObject = $void->response()->getResponseObject();

$status = \XLite\Model\Payment\Transaction::STATUS_SUCCESS;
$status =
$gatewayResponseObject->status == \Genesis\API\Constants\Transaction\States::APPROVED
? \XLite\Model\Payment\Transaction::STATUS_SUCCESS
: \XLite\Model\Payment\Transaction::STATUS_FAILED;

$transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(
\XLite\Model\Order\Status\Payment::STATUS_DECLINED
);
$result = $status == \XLite\Model\Payment\Transaction::STATUS_SUCCESS;

if ($result) {
$transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(
\XLite\Model\Order\Status\Payment::STATUS_DECLINED
);

$this->updateTransactionData($transaction, $void->response()->getResponseObject());
$this->updateTransactionData($transaction, $gatewayResponseObject);

\XLite\Core\TopMessage::getInstance()
->addInfo(
$void->response()->getResponseObject()->message
\XLite\Core\TopMessage::getInstance()->addInfo(
$gatewayResponseObject->message
);
} else {
$this->updateTransactionData($transaction, $gatewayResponseObject);
\XLite\Core\TopMessage::addError(
$gatewayResponseObject->message
);
}
} catch (\Exception $e) {
$result = false;

$status = \XLite\Model\Payment\Transaction::STATUS_FAILED;

\XLite\Core\TopMessage::getInstance()
->addError($e->getMessage());

\XLite\Core\TopMessage::getInstance()->addError(
$e->getMessage()
);
}

$transaction->setStatus($status);
Expand Down Expand Up @@ -1089,4 +1125,24 @@ protected static function log($data)
\XLite\Logger::logCustom('E-ComProcessing', (string)$data);
}
}

/**
* Detects if the X-Cart Core Version is 5.2
*
* @return bool
*/
protected function getIsCoreVersion52()
{
return \XLite\Module\EComProcessing\Genesis\Main::getIsCoreVersion52();
}

/**
* Detects if the X-Cart Core Version is 5.3
*
* @return bool
*/
protected function getIsCoreVersion53()
{
return \XLite\Module\EComProcessing\Genesis\Main::getIsCoreVersion53();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,38 @@ protected function doInitialPayment()

$genesis->execute();

$status = self::PROLONGATION;
$gatewayResponseObject = $genesis->response()->getResponseObject();

$this->redirectToURL($genesis->response()->getResponseObject()->redirect_url);
if (isset($gatewayResponseObject->redirect_url)) {
$status = self::PROLONGATION;

$this->redirectToURL($genesis->response()->getResponseObject()->redirect_url);
} else {
$errorMessage =
isset($gatewayResponseObject->message)
? $gatewayResponseObject->message
: '';

throw new \Exception ($errorMessage);
}
} catch (\Genesis\Exceptions\ErrorAPI $e) {
$errorMessage = $e->getMessage() ?: static::t('Invalid data, please check your input.');
$this->transaction->setDataCell(
'status',
$e->getMessage() ?: static::t('Invalid data, please check your input.'),
$errorMessage,
null,
static::FAILED
);
} catch (\Exception $exception) {
$this->transaction->setNote($errorMessage);
} catch (\Exception $e) {
$errorMessage = static::t('Failed to initialize payment session, please contact support. ' .$e->getMessage());
$this->transaction->setDataCell(
'status',
static::t('Failed to initialize payment session, please contact support.'),
$errorMessage,
null,
static::FAILED
);
$this->transaction->setNote($errorMessage);
}

return $status;
Expand Down Expand Up @@ -345,10 +360,16 @@ protected function getCheckoutTransactionTypes()
*
* $param \XLite\Model\Payment\Method $method
*
* @return string
* @return string|null
*/
public function getCheckoutTemplate(\XLite\Model\Payment\Method $method)
{
return parent::getCheckoutTemplate($method) . 'ecomprocessingCheckout.tpl';
if ($this->getIsCoreVersion52()) {
return parent::getCheckoutTemplate($method) . 'ecomprocessingCheckout.tpl';
} elseif ($this->getIsCoreVersion53()) {
return parent::getCheckoutTemplate($method) . 'ecomprocessingCheckout.twig';
}

return null;
}
}
Loading

0 comments on commit 72e919c

Please sign in to comment.