Skip to content

Commit

Permalink
v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dimosKougiou committed Aug 8, 2024
1 parent 97c002a commit c3225ba
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 58 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

## Changelog

- **1.0.5**
- Fixed guest checkout bug.

- **1.0.4**
- Minor bug fixes.

Expand Down Expand Up @@ -98,7 +101,7 @@ If you are using Plesk and nginx in proxy mode, under ``Apache & nginx Setting f
proxy_cookie_path / "/; SameSite=None; Secure";
```

Also add the following configuration lines for Apache in the ``Additional Apache directives`` section on the same page. By default, Plesk has the Apache ``mod_headers`` module installed and active however, verify that this is the case for your Plesk installation.
If you are only using Apache, add the following configuration lines in the ``Additional Apache directives`` section on the same page. By default, Plesk has the Apache ``mod_headers`` module installed and active however, verify that this is the case for your Plesk installation.

```
<IfModule mod_headers.c>
Expand Down
15 changes: 15 additions & 0 deletions app/code/Cardlink/Checkout/Controller/Payment/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
*/
class Redirect extends Action
{
const METHOD_GUEST = 'guest';
const METHOD_REGISTER = 'register';
const METHOD_CUSTOMER = 'customer';

/**
* @var Logger
*/
Expand Down Expand Up @@ -95,8 +99,19 @@ public function execute()
try {
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->collectTotals();

if ($quote->getCheckoutMethod() == null) {
$quote->setCheckoutMethod(self::METHOD_GUEST);
}
if ($quote->getCustomerEmail() == null) {
$billingAddress = $quote->getBillingAddress();
$quote->setCustomerEmail($billingAddress->getEmail());
}
$quote->save();
} catch (\Exception $ex) {
header('Content-Type: text/plain');
var_dump($ex->getMessage());
die();
}

// Retrieve the order and compile the API request data array.
Expand Down
31 changes: 13 additions & 18 deletions app/code/Cardlink/Checkout/Controller/Payment/Response-v2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Magento\Framework\UrlInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;
use Magento\Sales\Model\OrderFactory;

/**
* Controller action used to handle responses from the payment gateway.
Expand Down Expand Up @@ -57,6 +60,8 @@ class Response extends Action
*/
protected $resultRedirectFactory;

protected $orderFactory;

/**
* Controller constructor.
*
Expand All @@ -76,7 +81,8 @@ public function __construct(
RedirectFactory $resultRedirectFactory,
Logger $logger,
Data $dataHelper,
Payment $paymentHelper
Payment $paymentHelper,
OrderFactory $orderFactory

) {
$this->checkoutSession = $checkoutSession;
Expand All @@ -87,6 +93,7 @@ public function __construct(

$this->dataHelper = $dataHelper;
$this->paymentHelper = $paymentHelper;
$this->orderFactory = $orderFactory;

return parent::__construct($context);
}
Expand Down Expand Up @@ -148,28 +155,16 @@ public function execute()
throw new \Exception('Quote not found');
}

$billingAddress = $quote->getBillingAddress();
$quote->setCustomerEmail($billingAddress->getEmail());

// Convert quote to order
$order = $quoteManagement->submit($quote);

// Save the order
$order->save();

$orderId = $order->getIncrementId();
$orderId = $quoteManagement->placeOrder($quoteId);
$order = $this->orderFactory->create()->loadByIncrementId($orderId);

// Mark the payment as successful and remove the quote from the customer's session.
$this->paymentHelper->markSuccessfulPayment($order, $responseData);

$this->checkoutSession->unsQuoteId();
$this->checkoutSession->setLastQuoteId($order->getQuoteId());
$this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
$this->checkoutSession->setLastOrderId($order->getId());
$this->checkoutSession->setLastRealOrderId($order->getIncrementId());
$this->checkoutSession->setLastOrderStatus($order->getStatus());

$message = $responseData[ApiFields::Message];
$message = array_key_exists(ApiFields::Message, $responseData)
? $responseData[ApiFields::Message]
: '';
$success = true;
} else if (
// The payment was either canceled by the customer, refused by the payment gateway or an error occured.
Expand Down
34 changes: 14 additions & 20 deletions app/code/Cardlink/Checkout/Controller/Payment/Response-v2.3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Cardlink\Checkout\Helper\Data;
use Cardlink\Checkout\Helper\Payment;
use Magento\Checkout\Model\Session;

use Magento\Framework\App\CsrfAwareActionInterface;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
Expand All @@ -16,7 +19,7 @@
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Sales\Model\OrderFactory;

/**
* Controller action used to handle responses from the payment gateway.
Expand Down Expand Up @@ -60,6 +63,8 @@ class Response extends Action implements CsrfAwareActionInterface
*/
protected $resultRedirectFactory;

protected $orderFactory;

/**
* Controller constructor.
*
Expand All @@ -79,7 +84,8 @@ public function __construct(
RedirectFactory $resultRedirectFactory,
Logger $logger,
Data $dataHelper,
Payment $paymentHelper
Payment $paymentHelper,
OrderFactory $orderFactory

) {
$this->checkoutSession = $checkoutSession;
Expand All @@ -90,6 +96,7 @@ public function __construct(

$this->dataHelper = $dataHelper;
$this->paymentHelper = $paymentHelper;
$this->orderFactory = $orderFactory;

return parent::__construct($context);
}
Expand Down Expand Up @@ -151,28 +158,16 @@ public function execute()
throw new \Exception('Quote not found');
}

$billingAddress = $quote->getBillingAddress();
$quote->setCustomerEmail($billingAddress->getEmail());

// Convert quote to order
$order = $quoteManagement->submit($quote);

// Save the order
$order->save();

$orderId = $order->getIncrementId();
$orderId = $quoteManagement->placeOrder($quoteId);
$order = $this->orderFactory->create()->loadByIncrementId($orderId);

// Mark the payment as successful and remove the quote from the customer's session.
$this->paymentHelper->markSuccessfulPayment($order, $responseData);

$this->checkoutSession->unsQuoteId();
$this->checkoutSession->setLastQuoteId($order->getQuoteId());
$this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
$this->checkoutSession->setLastOrderId($order->getId());
$this->checkoutSession->setLastRealOrderId($order->getIncrementId());
$this->checkoutSession->setLastOrderStatus($order->getStatus());

$message = $responseData[ApiFields::Message];
$message = array_key_exists(ApiFields::Message, $responseData)
? $responseData[ApiFields::Message]
: '';
$success = true;
} else if (
// The payment was either canceled by the customer, refused by the payment gateway or an error occured.
Expand Down Expand Up @@ -245,5 +240,4 @@ public function createCsrfValidationException(RequestInterface $request): Invali
{
return null;
}

}
31 changes: 13 additions & 18 deletions app/code/Cardlink/Checkout/Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Magento\Framework\UrlInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;
use Magento\Sales\Model\OrderFactory;

/**
* Controller action used to handle responses from the payment gateway.
Expand Down Expand Up @@ -57,6 +60,8 @@ class Response extends Action
*/
protected $resultRedirectFactory;

protected $orderFactory;

/**
* Controller constructor.
*
Expand All @@ -76,7 +81,8 @@ public function __construct(
RedirectFactory $resultRedirectFactory,
Logger $logger,
Data $dataHelper,
Payment $paymentHelper
Payment $paymentHelper,
OrderFactory $orderFactory

) {
$this->checkoutSession = $checkoutSession;
Expand All @@ -87,6 +93,7 @@ public function __construct(

$this->dataHelper = $dataHelper;
$this->paymentHelper = $paymentHelper;
$this->orderFactory = $orderFactory;

return parent::__construct($context);
}
Expand Down Expand Up @@ -148,28 +155,16 @@ public function execute()
throw new \Exception('Quote not found');
}

$billingAddress = $quote->getBillingAddress();
$quote->setCustomerEmail($billingAddress->getEmail());

// Convert quote to order
$order = $quoteManagement->submit($quote);

// Save the order
$order->save();

$orderId = $order->getIncrementId();
$orderId = $quoteManagement->placeOrder($quoteId);
$order = $this->orderFactory->create()->loadByIncrementId($orderId);

// Mark the payment as successful and remove the quote from the customer's session.
$this->paymentHelper->markSuccessfulPayment($order, $responseData);

$this->checkoutSession->unsQuoteId();
$this->checkoutSession->setLastQuoteId($order->getQuoteId());
$this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
$this->checkoutSession->setLastOrderId($order->getId());
$this->checkoutSession->setLastRealOrderId($order->getIncrementId());
$this->checkoutSession->setLastOrderStatus($order->getStatus());

$message = $responseData[ApiFields::Message];
$message = array_key_exists(ApiFields::Message, $responseData)
? $responseData[ApiFields::Message]
: '';
$success = true;
} else if (
// The payment was either canceled by the customer, refused by the payment gateway or an error occured.
Expand Down
2 changes: 1 addition & 1 deletion app/code/Cardlink/Checkout/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">

<module name="Cardlink_Checkout" setup_version="1.0.4" schema_version="0.1.0">
<module name="Cardlink_Checkout" setup_version="1.0.5" schema_version="0.1.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit c3225ba

Please sign in to comment.