Skip to content

Commit

Permalink
Merge pull request #19 from wirecard/missedErrors
Browse files Browse the repository at this point in the history
Errormanagement for failed payments
  • Loading branch information
jpy authored Sep 15, 2017
2 parents 05cadd6 + a6f3fa2 commit 129ba82
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 66 deletions.
16 changes: 15 additions & 1 deletion Controller/Checkout/Back.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class Back extends \Magento\Framework\App\Action\Action
*/
protected $_quoteManagement;

/**
* @var \Magento\Quote\Api\CartRepositoryInterface
*/
protected $_quoteRepository;

/**
* @var \Magento\Framework\View\Result\PageFactory
*/
Expand All @@ -102,6 +107,7 @@ class Back extends \Magento\Framework\App\Action\Action
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Quote\Api\CartManagementInterface $quoteManagement
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
* @param \Wirecard\CheckoutSeamless\Model\OrderManagement $orderManagement
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand All @@ -115,6 +121,7 @@ public function __construct(
\Psr\Log\LoggerInterface $logger,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Quote\Api\CartManagementInterface $quoteManagement,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Wirecard\CheckoutSeamless\Model\OrderManagement $orderManagement
) {
parent::__construct($context);
Expand All @@ -126,6 +133,7 @@ public function __construct(
$this->_logger = $logger;
$this->_checkoutSession = $checkoutSession;
$this->_quoteManagement = $quoteManagement;
$this->_quoteRepository = $quoteRepository;
$this->_orderManagement = $orderManagement;
$this->_order = $order;
}
Expand Down Expand Up @@ -213,7 +221,7 @@ public function execute()
if ($returnedData['errors'] != 1) {
$consumerMessage .= $i + 1;
}
$consumerMessage .= $returnedData['error_' . ($i + 1) . '_consumerMessage'];
$consumerMessage .= htmlspecialchars_decode($returnedData['error_' . ($i + 1) . '_consumerMessage']);
if ($returnedData['errors'] != 1) {
$consumerMessage .= "<br>";
}
Expand All @@ -227,6 +235,12 @@ public function execute()
if ($orderCreation == 'before') {
$quote = $this->_orderManagement->reOrder($quoteId);
$this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
} else {
$quote = $this->_quoteRepository->get($quoteId);
// remove errorinformation from active quote
$quote->getPayment()->unsAdditionalInformation();
$quote->save();
$paymentInfo->unsetData(null);
}

break;
Expand Down
27 changes: 16 additions & 11 deletions Controller/Checkout/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,22 @@ public function execute()
$return = \WirecardCEE_QMore_ReturnFactory::getInstance($this->_request->getPost()->toArray(),
$this->_dataHelper->getConfigData('basicdata/secret'));

if (!$return->validate()) {
throw new \Exception('Validation error: invalid response');
}

if (!strlen($return->mage_orderId)) {
throw new \Exception('Magento OrderId is missing');
}

if (!strlen($return->mage_quoteId)) {
throw new \Exception('Magento QuoteId is missing');
}
$error = "";
if (!$return->validate()) {
$error = 'Validation error: invalid response';
}

if (!strlen($return->mage_orderId)) {
$error = 'Magento OrderId is missing';
}

if (!strlen($return->mage_quoteId)) {
$error = 'Magento QuoteId is missing';
}

if (strlen($error)) {
die( \WirecardCEE_QMore_ReturnFactory::generateConfirmResponseString($error) );
}

$this->_orderManagement->processOrder($return);

Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{

protected $_pluginVersion = '1.0.2';
protected $_pluginVersion = '1.0.6';
protected $_pluginName = 'Wirecard/CheckoutSeamless';

/**
Expand Down
89 changes: 39 additions & 50 deletions Model/OrderManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,56 +349,45 @@ public function confirmOrder($order, $return, $fraudDetected)
$order->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING);
$message = $this->_dataHelper->__('The payment has been successfully completed.');

// invoice payment
if ($order->canInvoice()) {

$invoice = $order->prepareInvoice();

$invoice->register();

/* capture invoice if toolkit is not availble */
if (!$this->_dataHelper->isBackendAvailable()) {
$doCapture = true;
} else {
$hasBackedOps = false;

$orderDetails = $paymentInstance->getOrderDetails($payment->getAdditionalInformation('orderNumber'));
foreach ($orderDetails->getOrder()->getPayments() as $wdPayment) {
/** @var \WirecardCEE_QMore_Response_Backend_Order_Payment $wdPayment */

$this->_logger->debug(
__METHOD__ . ':payment-state:' . $wdPayment->getState(
) . ' allowed operations:' . implode(
',',
$wdPayment->getOperationsAllowed()
)
);

if (count($wdPayment->getOperationsAllowed())) {
$hasBackedOps = true;
break;
}
}

if (count($orderDetails->getOrder()->getOperationsAllowed())) {
$this->_logger->debug(__METHOD__ . ':order allowed operations: ' . implode(',',
$orderDetails->getOrder()->getOperationsAllowed()));
$hasBackedOps = true;
}

/* no backend ops allowed anymore, assume final state of payment, capture invoice */
if (!$hasBackedOps) {
$doCapture = true;
}

}

if ($doCapture && !$fraudDetected) {
$invoice->capture();
}

$order->addRelatedObject($invoice);
}
// invoice payment
if ( $order->canInvoice() ) {
$invoice = $order->prepareInvoice();
$invoice->register();

/* backend operation check for capturing if toolkit is available */
if ( $this->_dataHelper->isBackendAvailable() ) {
$hasBackedOps = false;

$orderDetails = $paymentInstance->getOrderDetails( $payment->getAdditionalInformation( 'orderNumber' ) );
foreach ( $orderDetails->getOrder()->getPayments() as $wdPayment ) {
/** @var \WirecardCEE_QMore_Response_Backend_Order_Payment $wdPayment */

$this->_logger->debug(
__METHOD__ . ':payment-state:' . $wdPayment->getState() . ' allowed operations:' . implode(
',',
$wdPayment->getOperationsAllowed()
)
);
$operations = $wdPayment->getOperationsAllowed();

if ( ! in_array( 'DEPOSIT', $operations ) ) {
$hasBackedOps = true;
break;
}
}

/* if no deposit available in backendops, capture invoice */
if ( $hasBackedOps ) {
$doCapture = true;
}
}

if ( $doCapture && ! $fraudDetected ) {
$invoice->capture();
}

$order->addRelatedObject( $invoice );
}

$this->_orderSender->send($order);
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wirecard/magento2-wcs",
"description": "Wirecard Checkout Seamless",
"type": "magento2-module",
"version": "1.0.5",
"version": "1.0.6",
"license": [
"MIT"
],
Expand All @@ -12,7 +12,7 @@
"magento/module-sales": "*",
"magento/module-payment": "*",
"magento/module-quote": "*",
"wirecard/checkout-client-library": "3.3.4"
"wirecard/checkout-client-library": "3.3.5"
},
"autoload": {
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</head>
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" template="Wirecard_CheckoutSeamless::back.phtml" name="checkout.back" />
<block class="Magento\Framework\View\Element\Template" template="Wirecard_CheckoutSeamless::back.phtml" name="checkout.back" cacheable="false"/>
</referenceContainer>
<referenceBlock name="footer_links" remove="true"/>
<referenceBlock name="catalog.topnav" remove="true"/>
Expand Down

0 comments on commit 129ba82

Please sign in to comment.