Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v 2 payments #69

Merged
merged 51 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1822c86
Revert "Using rvvup backend cache for methods available (#53)"
andrii-onufriichuk Oct 11, 2023
7db1a3f
Merge branch 'main' of github.com:rvvup/magento-plugin into main
andrii-onufriichuk Oct 11, 2023
64b59b3
Merge branch 'main' of github.com:rvvup/magento-plugin into main
andrii-onufriichuk Oct 31, 2023
9d36b07
Merge branch 'main' of github.com:rvvup/magento-plugin into main
andrii-onufriichuk Nov 9, 2023
0b5b492
Merge branch 'main' of github.com:rvvup/magento-plugin into main
andrii-onufriichuk Nov 21, 2023
08745d3
mend
andrii-onufriichuk Dec 6, 2023
69a693d
Added V2 payment handling
andrii-onufriichuk Dec 27, 2023
0df8885
Added payment capture call
andrii-onufriichuk Dec 27, 2023
782b98e
Added void authoratization on plugin order fail
andrii-onufriichuk Jan 2, 2024
827ed64
mend
andrii-onufriichuk Jan 2, 2024
6991de9
Code refactoring
andrii-onufriichuk Jan 2, 2024
765db3f
Added mock commandpool
andrii-onufriichuk Jan 2, 2024
9afb42e
Added cart reload on success page
andrii-onufriichuk Jan 2, 2024
9975a6d
mend
andrii-onufriichuk Jan 3, 2024
b3c6330
Merge main branch
andrii-onufriichuk Jan 3, 2024
eb9d732
mend
andrii-onufriichuk Jan 3, 2024
d7095c2
Fixed rvvup pay by card
andrii-onufriichuk Jan 3, 2024
ff04f51
Moved paypal express to v2 payments
andrii-onufriichuk Jan 8, 2024
effa37f
mend
andrii-onufriichuk Jan 8, 2024
3ff7755
Removed voiding payment on capture failure
andrii-onufriichuk Jan 8, 2024
5552290
mend
andrii-onufriichuk Jan 9, 2024
eedd10c
mend
andrii-onufriichuk Jan 9, 2024
2025458
mend
andrii-onufriichuk Jan 9, 2024
75435a6
mend
andrii-onufriichuk Jan 9, 2024
10a9df5
Implemented webhook order handling
andrii-onufriichuk Jan 14, 2024
6080c6e
Code cleanup
andrii-onufriichuk Jan 14, 2024
c4e37d3
Code cleanup
andrii-onufriichuk Jan 14, 2024
cd6df3d
mend
andrii-onufriichuk Jan 14, 2024
ccfe802
Fixed message overriding
andrii-onufriichuk Jan 14, 2024
f661bf6
Renaming of order service
andrii-onufriichuk Jan 14, 2024
db8e1d7
Fix multiple orders issue
andrii-onufriichuk Jan 15, 2024
ed73f0d
Change messaging
andrii-onufriichuk Jan 15, 2024
6cd447e
mend
andrii-onufriichuk Jan 16, 2024
9fdae8a
mend
andrii-onufriichuk Jan 16, 2024
1eeecfb
mend
andrii-onufriichuk Jan 16, 2024
31f0768
mend
andrii-onufriichuk Jan 16, 2024
25dc3b3
fix: Added missing parameter to clear cache call
valentin-rvvup Jan 16, 2024
2097855
Merge branch 'main' into feature/v-2-payments
andrii-onufriichuk Jan 17, 2024
6eabf5f
Merge of tsa-713-missing-param
andrii-onufriichuk Jan 18, 2024
b69c518
Fix payment methods issue
andrii-onufriichuk Jan 18, 2024
abaec33
Fixed processed order on redirect/in
Jan 18, 2024
3336859
Fix for multiple models openning up
andrii-onufriichuk Jan 22, 2024
f010d78
Fixed multiple modals being opened at the same time
andrii-onufriichuk Jan 22, 2024
5d0cae6
mend
andrii-onufriichuk Jan 22, 2024
5c52b5a
Added reload on payment cancel
andrii-onufriichuk Jan 23, 2024
cfac4b0
Fix for error on thank you page
andrii-onufriichuk Jan 23, 2024
7e643d1
mend
andrii-onufriichuk Jan 23, 2024
6599464
mend
andrii-onufriichuk Jan 23, 2024
8db065f
Adding verbose output to phpstan
andrii-onufriichuk Jan 24, 2024
2af04b5
mend
andrii-onufriichuk Jan 24, 2024
e4917a1
mend
andrii-onufriichuk Jan 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Api/Data/ProcessOrderResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ public function getCustomerMessage(): ?string;
* @return void
*/
public function setCustomerMessage(string $customerMessage): void;

/**
* @param string|null $messageGroup
* @return void
*/
public function setSessionMessage(
?string $messageGroup = null
): void;
}
66 changes: 66 additions & 0 deletions Block/Order/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Rvvup\Payments\Block\Order;

use Magento\Checkout\Model\Session;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template\Context as TemplateContext;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Address\Renderer as AddressRenderer;

class Info extends \Magento\Sales\Block\Order\Info
{
/** @var Order */
private $order;

/** @var Session */
private $session;

/**
* @param TemplateContext $context
* @param Registry $registry
* @param PaymentHelper $paymentHelper
* @param AddressRenderer $addressRenderer
* @param Session $session
* @param Order $order
* @param array $data
*/
public function __construct(
TemplateContext $context,
Registry $registry,
PaymentHelper $paymentHelper,
AddressRenderer $addressRenderer,
Session $session,
Order $order,
array $data = []
) {
$this->session = $session;
$this->order = $order;
parent::__construct($context, $registry, $paymentHelper, $addressRenderer, $data);
}

/**
* @inheritDoc
* @return void
* @throws LocalizedException
*/
protected function _prepareLayout(): void
{
$orderId = $this->getOrder()->getRealOrderId();
$payment = $this->getOrder()->getPayment();
if (!$orderId) {
$orderId = $this->session->getLastRealOrderId();
}
if (!$payment) {
$order = $this->order->loadByIncrementId($orderId);
$payment = $order->getPayment();
}
$this->pageConfig->getTitle()->set(__('Order # %1', $orderId));
$infoBlock = $this->paymentHelper->getInfoBlock($payment, $this->getLayout());
$this->setChild('payment_info', $infoBlock);
}
}
66 changes: 66 additions & 0 deletions Block/Order/View.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Rvvup\Payments\Block\Order;

use Klarna\Core\Api\OrderRepositoryInterface;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Http\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Payment\Helper\Data;
use Magento\Sales\Model\Order;

class View extends \Magento\Sales\Block\Order\View
{
/** @var Session */
private $session;

/** @var Order */
private $order;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param Registry $registry
* @param Context $httpContext
* @param Data $paymentHelper
* @param Session $session
* @param Order $order
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
Registry $registry,
Context $httpContext,
Data $paymentHelper,
Session $session,
Order $order,
array $data = []
) {
$this->session = $session;
$this->order = $order;
parent::__construct($context, $registry, $httpContext, $paymentHelper, $data);
}

/**
* @inheritDoc
* @return void
* @throws LocalizedException
*/
protected function _prepareLayout(): void
{
$orderId = $this->getOrder()->getRealOrderId();
$payment = $this->getOrder()->getPayment();
if (!$orderId) {
$orderId = $this->session->getLastRealOrderId();
}
if (!$payment) {
$order = $this->order->loadByIncrementId($orderId);
$payment = $order->getPayment();
}
$this->pageConfig->getTitle()->set(__('Order # %1', $orderId));
$infoBlock = $this->_paymentHelper->getInfoBlock($payment, $this->getLayout());
$this->setChild('payment_info', $infoBlock);
}
}
61 changes: 30 additions & 31 deletions Controller/CardPayments/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Data\Form\FormKey\Validator;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Rvvup\Payments\Gateway\Method;
use Rvvup\Payments\Model\SdkProxy;
use Rvvup\Sdk\Exceptions\ApiError;

Expand All @@ -32,67 +34,64 @@ class Confirm implements HttpPostActionInterface, CsrfAwareActionInterface
*/
private $orderRepository;

/** @var Validator */
/** @var Validator */
private $formKeyValidator;

/**
* @var SessionManagerInterface
*/
private $checkoutSession;

/**
* @param ResultFactory $resultFactory
* @param SdkProxy $sdkProxy
* @param RequestInterface $request
* @param OrderRepositoryInterface $orderRepository
* @param Validator $formKeyValidator
* @param SessionManagerInterface $checkoutSession $
*/
public function __construct(
ResultFactory $resultFactory,
SdkProxy $sdkProxy,
RequestInterface $request,
OrderRepositoryInterface $orderRepository,
Validator $formKeyValidator
Validator $formKeyValidator,
SessionManagerInterface $checkoutSession
) {
$this->resultFactory = $resultFactory;
$this->sdkProxy = $sdkProxy;
$this->request = $request;
$this->orderRepository = $orderRepository;
$this->formKeyValidator = $formKeyValidator;
$this->checkoutSession = $checkoutSession;
}

public function execute()
{
$response = $this->resultFactory->create($this->resultFactory::TYPE_JSON);

try {
$orderId = $this->request->getParam('order_id', false);
$order = $this->orderRepository->get((int)$orderId);

if ($order) {
$rvvupOrderId = (string) $order->getPayment()->getAdditionalInformation('rvvup_order_id');
$rvvupOrder = $this->sdkProxy->getOrder($rvvupOrderId);
$rvvupPaymentId = $rvvupOrder['payments'][0]['id'];

$authorizationResponse = $this->request->getParam('auth', false);
$threeDSecureResponse = $this->request->getParam('three_d', null);

$this->sdkProxy->confirmCardAuthorization(
$rvvupPaymentId,
$rvvupOrderId,
$authorizationResponse,
$threeDSecureResponse
);

$response->setData([
'success' => true,
]);
} else {
$response->setData([
'success' => false,
'error_message' => 'Order not found during card authorization',
'retryable' => false,
]);
}
$quote = $this->checkoutSession->getQuote();
$rvvupOrderId = (string)$quote->getPayment()->getAdditionalInformation('transaction_id');
$rvvupPaymentId = $quote->getPayment()->getAdditionalInformation(Method::PAYMENT_ID);

$authorizationResponse = $this->request->getParam('auth', false);
$threeDSecureResponse = $this->request->getParam('three_d');

$this->sdkProxy->confirmCardAuthorization(
$rvvupPaymentId,
$rvvupOrderId,
$authorizationResponse,
$threeDSecureResponse
);

$response->setData([
'success' => true,
]);

$response->setHttpResponseCode(200);
return $response;
} catch (\Exception $exception) {

$data = [
'success' => false,
'error_message' => $exception->getMessage()
Expand Down
19 changes: 9 additions & 10 deletions Controller/Express/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Rvvup\Payments\Gateway\Method;
use Rvvup\Payments\Model\SdkProxy;

class Cancel implements HttpGetActionInterface
Expand Down Expand Up @@ -39,16 +40,14 @@ public function __construct(
public function execute()
{
$payment = $this->checkoutSession->getQuote()->getPayment();
if ($payment->getAdditionalInformation('is_rvvup_express_payment')) {
$rvvupOrderId = $payment->getAdditionalInformation('rvvup_order_id');
$order = $this->sdkProxy->getOrder($rvvupOrderId);
if ($order && isset($order['payments'])) {
$paymentId = $order['payments'][0]['id'];
$this->sdkProxy->cancelPayment($paymentId, $rvvupOrderId);
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$result->setData(['success' => true]);
return $result;
}
if ($payment->getAdditionalInformation(Method::EXPRESS_PAYMENT_KEY)) {
$rvvupOrderId = $payment->getAdditionalInformation(Method::ORDER_ID);
$paymentId = $payment->getAdditionalInformation(Method::PAYMENT_ID);

$this->sdkProxy->cancelPayment($paymentId, $rvvupOrderId);
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$result->setData(['success' => true]);
return $result;
}

$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rvvup\Payments\Controller\CardPayments;
namespace Rvvup\Payments\Controller\Payment;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\Action\HttpPostActionInterface;
Expand All @@ -12,11 +12,11 @@
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Data\Form\FormKey\Validator;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Rvvup\Payments\Gateway\Method;
use Rvvup\Payments\Service\Order;
use Psr\Log\LoggerInterface;
use Rvvup\Payments\Gateway\Method;
use Rvvup\Payments\Model\SdkProxy;

class Cancel implements HttpPostActionInterface, CsrfAwareActionInterface
{
Expand All @@ -29,36 +29,36 @@ class Cancel implements HttpPostActionInterface, CsrfAwareActionInterface
/** @var Session */
private $session;

/** @var Order */
private $orderService;

/** @var LoggerInterface */
private $logger;

/** @var OrderRepositoryInterface */
private $orderRepository;

/** @var SdkProxy */
private $sdkProxy;

/**
* @param ResultFactory $resultFactory
* @param Validator $formKeyValidator
* @param Session $session
* @param Order $orderService
* @param OrderRepositoryInterface $orderRepository
* @param SdkProxy $sdkProxy
* @param LoggerInterface $logger
*/
public function __construct(
ResultFactory $resultFactory,
Validator $formKeyValidator,
Session $session,
Order $orderService,
OrderRepositoryInterface $orderRepository,
SdkProxy $sdkProxy,
LoggerInterface $logger
) {
$this->resultFactory = $resultFactory;
$this->formKeyValidator = $formKeyValidator;
$this->session = $session;
$this->orderService = $orderService;
$this->orderRepository = $orderRepository;
$this->sdkProxy = $sdkProxy;
$this->logger = $logger;
}

Expand All @@ -71,11 +71,7 @@ public function execute(): ResultInterface

try {
if ($quote->getId()) {
$orders = $this->orderService->getAllOrdersByQuote($quote);
/** @var OrderInterface $order */
foreach ($orders as $order) {
$this->cancelRvvupOrder($order);
}
$this->cancelRvvupOrder($quote->getPayment());
}
} catch (\Exception $e) {
$this->logger->warning('Rvvup order cancellation failed with message : ' . $e->getMessage());
Expand All @@ -87,20 +83,14 @@ public function execute(): ResultInterface
}

/**
* @param OrderInterface $order
* @param PaymentInterface $payment
* @return void
*/
private function cancelRvvupOrder(OrderInterface $order): void
private function cancelRvvupOrder(PaymentInterface $payment): void
{
$payment = $order->getPayment();
if ($payment->getMethod()) {
if (strpos($payment->getMethod(), Method::PAYMENT_TITLE_PREFIX) === 0) {
if ($order->canCancel()) {
$order->cancel();
$this->orderRepository->save($order);
}
}
}
$rvvupOrderId = $payment->getAdditionalInformation(Method::ORDER_ID);
$paymentId = $payment->getAdditionalInformation(Method::PAYMENT_ID);
$this->sdkProxy->cancelPayment($paymentId, $rvvupOrderId);
}

/**
Expand Down
Loading
Loading