Skip to content

Commit

Permalink
1.3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dyd committed Oct 25, 2024
1 parent 490a203 commit 0fb6f0f
Show file tree
Hide file tree
Showing 21 changed files with 601 additions and 116 deletions.
34 changes: 33 additions & 1 deletion Controller/Ipn/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,44 @@

namespace EMerchantPay\Genesis\Controller\Ipn;

use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;

/**
* Unified IPN controller for all supported EMerchantPay Payment Methods
* Class Index
*/
class Index extends \EMerchantPay\Genesis\Controller\AbstractAction
class Index extends \EMerchantPay\Genesis\Controller\AbstractAction implements CsrfAwareActionInterface
{
/**
* Skip CSRF validation for the received request from the Gateway
*
* @param RequestInterface $request
*
* @return bool|null
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function validateForCsrf(RequestInterface $request): ?bool
{
return true;
}

/**
* No validation required
*
* @param RequestInterface $request
*
* @return InvalidRequestException|null
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
{
return null;
}

/**
* Get the name of the IPN Class, used to handle the posted Notification. It is separated per Payment Method
*
Expand Down
35 changes: 21 additions & 14 deletions Model/Ipn/CheckoutIpn.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@

use EMerchantPay\Genesis\Helper\Data;
use EMerchantPay\Genesis\Model\Method\Checkout;
use EMerchantPay\Genesis\Model\Service\MultiCurrencyProcessingService;
use Exception;
use Genesis\Api\Constants\Transaction\States;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
use Magento\Sales\Model\OrderFactory;
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\OrderFactory;
use Psr\Log\LoggerInterface;
use stdClass;

Expand All @@ -46,6 +47,11 @@ class CheckoutIpn extends AbstractIpn
*/
protected $orderRepository;

/**
* @var MultiCurrencyProcessingService
*/
protected $multiCurrencyProcessingService;

/**
* @param Context $context
* @param OrderFactory $orderFactory
Expand All @@ -55,6 +61,7 @@ class CheckoutIpn extends AbstractIpn
* @param Data $moduleHelper
* @param OrderRepositoryInterface $orderRepository
* @param OrderStatusHistoryRepositoryInterface $orderStatusHistoryRepository
* @param MultiCurrencyProcessingService $multiCurrencyProcessingService
* @param array $data
*
* @throws NoSuchEntityException
Expand All @@ -68,6 +75,7 @@ public function __construct(
Data $moduleHelper,
OrderRepositoryInterface $orderRepository,
OrderStatusHistoryRepositoryInterface $orderStatusHistoryRepository,
MultiCurrencyProcessingService $multiCurrencyProcessingService,
array $data = []
) {
parent::__construct(
Expand All @@ -81,7 +89,9 @@ public function __construct(
$data
);

$this->orderRepository = $orderRepository;
$this->orderRepository = $orderRepository;
$this->multiCurrencyProcessingService = $multiCurrencyProcessingService;
$this->multiCurrencyProcessingService->setMethodCode($this->getPaymentMethodCode());
}

/**
Expand Down Expand Up @@ -196,18 +206,15 @@ protected function registerPaymentNotification(
) {
$transactionType = $payment_transaction->transaction_type;

if ($this->getModuleHelper()->getShouldCreateAuthNotification($transactionType)) {
$payment->registerAuthorizationNotification(
$payment_transaction->amount
);
$amount = $this->multiCurrencyProcessingService->getWpfAmount($payment->getOrder());

return;
}

if ($this->getModuleHelper()->getShouldCreateCaptureNotification($transactionType)) {
$payment->registerCaptureNotification(
$payment_transaction->amount
);
switch (true) {
case $this->getModuleHelper()->getShouldCreateAuthNotification($transactionType):
$payment->registerAuthorizationNotification($amount);
break;
case $this->getModuleHelper()->getShouldCreateCaptureNotification($transactionType):
$payment->registerCaptureNotification($amount);
break;
}
}
}
70 changes: 51 additions & 19 deletions Model/Method/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use EMerchantPay\Genesis\Helper\Data;
use EMerchantPay\Genesis\Logger\Logger;
use EMerchantPay\Genesis\Model\Service\MultiCurrencyProcessingService;
use EMerchantpay\Genesis\Helper\Threeds;
use Exception;
use Genesis\Api\Constants\Transaction\Parameters\Threeds\V2\CardHolderAccount\PasswordChangeIndicators;
Expand Down Expand Up @@ -52,6 +53,7 @@
use Magento\Payment\Model\MethodInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Store\Model\StoreManagerInterface;
use stdClass;

Expand Down Expand Up @@ -85,6 +87,11 @@ class Checkout extends Base
*/
protected $_customerRepositoryInterface;

/**
* @var MultiCurrencyProcessingService
*/
protected $_multiCurrencyProcessingService;

/**
* Checkout constructor.
*
Expand All @@ -99,6 +106,7 @@ class Checkout extends Base
* @param CustomerRepositoryInterface $customerRepositoryInterface
* @param Threeds $threedsHelper
* @param OrderPaymentRepositoryInterface $paymentRepository
* @param MultiCurrencyProcessingService $multiCurrencyProcessingService
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
Expand All @@ -117,6 +125,7 @@ public function __construct(
CustomerRepositoryInterface $customerRepositoryInterface,
Threeds $threedsHelper,
OrderPaymentRepositoryInterface $paymentRepository,
MultiCurrencyProcessingService $multiCurrencyProcessingService,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = []
Expand All @@ -134,16 +143,18 @@ public function __construct(
$data
);

$this->_actionContext = $actionContext;
$this->_storeManager = $storeManager;
$this->_checkoutSession = $checkoutSession;
$this->_moduleHelper = $moduleHelper;
$this->_threedsHelper = $threedsHelper;
$this->_customerRepositoryInterface = $customerRepositoryInterface;
$this->_configHelper =
$this->_actionContext = $actionContext;
$this->_storeManager = $storeManager;
$this->_checkoutSession = $checkoutSession;
$this->_moduleHelper = $moduleHelper;
$this->_threedsHelper = $threedsHelper;
$this->_customerRepositoryInterface = $customerRepositoryInterface;
$this->_configHelper =
$this->getModuleHelper()->getMethodConfig(
$this->getCode()
);
$this->_multiCurrencyProcessingService = $multiCurrencyProcessingService;
$this->_multiCurrencyProcessingService->setMethodCode($this->getCode());
}

/**
Expand Down Expand Up @@ -222,7 +233,12 @@ public function getCheckoutTransactionTypes()
*
* @return stdClass
*
* @throws WebapiException
* @throws ErrorParameter
* @throws InvalidArgument
* @throws InvalidMethod
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws Exception
*/
protected function checkout($data)
{
Expand Down Expand Up @@ -592,6 +608,8 @@ protected function isErrorResponse($response)
* @return $this
*
* @throws LocalizedException|InvalidArgument
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function order(InfoInterface $payment, $amount)
{
Expand All @@ -604,32 +622,32 @@ public function order(InfoInterface $payment, $amount)

// @codingStandardsIgnoreStart
$data = [
'transaction_id' =>
'transaction_id' =>
$this->getModuleHelper()->genTransactionId(
$orderId
),
'transaction_types' =>
$this->getConfigHelper()->getTransactionTypes(),
'order' => [
'currency' => $order->getBaseCurrencyCode(),
'language' => $this->getModuleHelper()->getLocale(),
'amount' => $amount,
'usage' => $this->getModuleHelper()->buildOrderUsage(),
'order' => [
'currency' => $this->_multiCurrencyProcessingService->getOrderCurrency($order),
'language' => $this->getModuleHelper()->getLocale(),
'amount' => $this->_multiCurrencyProcessingService->getOrderAmount($order, $amount),
'usage' => $this->getModuleHelper()->buildOrderUsage(),
'description' => $this->getModuleHelper()->buildOrderDescriptionText(
$order
),
'customer' => [
'customer' => [
'id' => $order->getCustomerId(),
'email' => $this->getCheckoutSession()->getQuote()->getCustomerEmail(),
],
'billing' =>
'billing' =>
$order->getBillingAddress(),
'shipping' =>
'shipping' =>
$order->getShippingAddress(),
'orderObject' => $order
],
'urls' => [
'notify' =>
'urls' => [
'notify' =>
$this->getModuleHelper()->getNotificationUrl(
$this->getCode()
),
Expand Down Expand Up @@ -744,6 +762,7 @@ public function capture(InfoInterface $payment, $amount)
}

try {
$amount = $this->_multiCurrencyProcessingService->convertAmount($amount, $order);
$this->doCapture($payment, $amount, $authTransaction);
} catch (Exception $e) {
$this->getLogger()->error(
Expand Down Expand Up @@ -945,4 +964,17 @@ protected function getSelectedTransactionTypes()
array_diff($selectedTypes, $selectedCreditCardTypes)
);
}

/**
* Convert amount according to the order currency
*
* @param float $amount
* @param Order $order
*
* @return float|null
*/
protected function convertAmount($amount, $order)
{
return $this->_multiCurrencyProcessingService->convertAmount($amount, $order);
}
}
Loading

0 comments on commit 0fb6f0f

Please sign in to comment.