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

Vipps 434: Prepare for MobilePay. #177

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
14c20df
VIPPS-417: Improve performance of GetShippingDetails service
Oct 31, 2022
3cc3201
Merge branch '2.4' of github.com:vippsas/vipps-magento into 2.4
Oct 31, 2022
2f2f753
VIPPS-417: Added backward compatibility with Magento 2.4.3
Nov 3, 2022
ea6af43
Merge pull request #148 from vippsas/publication-2.4.37
voleye Nov 3, 2022
efc0870
VIPPS-417: Added backward compatibility with Magento 2.4.3
Nov 3, 2022
bf50d71
Merge pull request #149 from vippsas/publication-2.4.38
voleye Nov 3, 2022
52645c6
VIPPS-419: Added support for configurable items for send receipt service
Nov 9, 2022
8ef8320
Merge pull request #152 from vippsas/publication-2.4.39
voleye Nov 9, 2022
47976fb
VIPPS-420: Receipt requests: Incorrect totals for rows and 400 errors…
Nov 16, 2022
eddfffc
Merge pull request #155 from vippsas/2.4.40-p1
voleye Nov 25, 2022
1e99ea4
Fixed issue when order id already is in used
Jan 12, 2023
ad6dc3e
Increase module version
Jan 12, 2023
b13224d
Merge pull request #156 from vippsas/2.4.41
voleye Jan 12, 2023
ad1c787
Mixed up credentials with multi-website? #157
Mar 6, 2023
206329d
Increase module version
Mar 6, 2023
420434e
Merge pull request #159 from vippsas/publication-2.4.42
voleye Mar 6, 2023
0e8d86d
Mixed up credentials with multi-website? #157
Mar 8, 2023
339ae79
Merge branch '2.4' of github.com:vippsas/vipps-magento into 2.4
Mar 8, 2023
96317bd
Mixed up credentials with multi-website? #157
Mar 8, 2023
005a5fb
Mixed up credentials with multi-website? #157
Mar 8, 2023
7a68259
Mixed up credentials with multi-website? #157
Mar 8, 2023
d4c5228
Mixed up credentials with multi-website? #157
Mar 8, 2023
fb3c218
Mixed up credentials with multi-website? #157
Mar 8, 2023
ad1b975
Magento 2.4.6 and PHP 8.2 compatibility #160
Mar 22, 2023
f714bdb
Increased module version
Mar 22, 2023
da56b9f
Merge pull request #161 from vippsas/publication-2.4.43
voleye Mar 22, 2023
14193be
Fixed: test connection feature does not work
Apr 18, 2023
551b497
VIPPS-426: Issue - unknown version for plugin
Apr 25, 2023
8f51710
Merge pull request #162 from vippsas/publication-2.4.45
voleye Apr 25, 2023
cfb2cd8
VIPPS-429: Received invalid message format "The Name field is required"
Sep 14, 2023
aa365cd
VIPPS-433: Migrate to ecomm api.
olegmalichenkoatvaimo Oct 23, 2023
0b66eab
VIPPS-433: Migrate to ecomm api.
olegmalichenkoatvaimo Oct 23, 2023
fc07da7
VIPPS-433: Complete migration.
olegmalichenkoatvaimo Dec 12, 2023
d442b57
VIPPS-434: Switcher from ecomm api to epayment.
olegmalichenkoatvaimo Dec 21, 2023
8c15407
VIPPS-434: Switcher from ecomm api to epayment.
olegmalichenkoatvaimo Dec 21, 2023
061fe6f
VIPPS-434: Update labels for mobile ecomm, allow NOK, EUR currencies.
olegmalichenkoatvaimo Jan 17, 2024
8699c7f
VIPPS-435: Extend graphql for pwa mobilepay.
olegmalichenkoatvaimo Jan 23, 2024
f8a6151
VIPPS-434: Add license.
olegmalichenkoatvaimo Jan 24, 2024
fa5a96d
VIPPS-434: Update mobilepay logo.
olegmalichenkoatvaimo Jan 30, 2024
112e5dd
VIPPS-434: Update unit tests.
olegmalichenkoatvaimo Jan 30, 2024
0109e45
VIPPS-434: Update phpcs config.
olegmalichenkoatvaimo Jan 30, 2024
52f1065
VIPPS-442: Always capture when mobilepay is selected.
olegmalichenkoatvaimo Feb 15, 2024
9d7a89d
VIPPS-442: Add hint.
olegmalichenkoatvaimo Feb 16, 2024
7d48c83
VIPPS-434: Fix for url assebmling.
olegmalichenkoatvaimo Feb 16, 2024
028f848
VIPPS-434: Update labels to use Vipps/MobilePayment.
olegmalichenkoatvaimo Feb 23, 2024
b80bdaf
VIPPS-446: Update links and notes at configuration.
olegmalichenkoatvaimo Apr 24, 2024
31913e4
VIPPS-448: Unlock authorize and capture for mobilepay.
olegmalichenkoatvaimo May 7, 2024
e94a1b5
VIPPS-448: Fix implicit convert to int.
olegmalichenkoatvaimo May 16, 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
27 changes: 27 additions & 0 deletions Api/Fallback/AuthoriseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

/**
* Copyright 2023 Vipps
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
namespace Vipps\Payment\Api\Fallback;

use Magento\Framework\App\RequestInterface;
use Vipps\Payment\Api\Data\QuoteInterface;

interface AuthoriseInterface
{
public function do(RequestInterface $request, QuoteInterface $vippsQuote): void;

public function getOrderId(RequestInterface $request): string;
}
77 changes: 77 additions & 0 deletions Api/Payment/CommandManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php declare(strict_types=1);

/**
* Copyright 2023 Vipps
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

namespace Vipps\Payment\Api\Payment;

use Magento\Payment\Gateway\Command\ResultInterface;
use Magento\Payment\Model\InfoInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Vipps\Payment\Gateway\Exception\VippsException;

/**
* Interface PaymentCommandManagerInterface
* @package Vipps\Payment\Api
* @api
*/
interface CommandManagerInterface
{
/**
* @param string $reference
* @param array $arguments
*
* @return mixed
*/
public function getPayment($reference, $arguments = []);

/**
* @param string $orderId
* @param array $arguments
*
* @return mixed
*/
public function getPaymentEventLog($orderId, $arguments = []);

/**
* Send Receipt.
*
* @param array $arguments
*
* @return mixed
* @throws VippsException
*/
public function sendReceipt(OrderInterface $order, $arguments = []);

/**
* Method to execute cancel Command.
*
* @param InfoInterface $payment
* @param array $arguments
*
* @return mixed
*/
public function cancel(InfoInterface $payment, $arguments = []);

/**
* Initiate payment action.
*
* @param InfoInterface $payment
* @param array $arguments
*
* @return ResultInterface|null
*/
public function initiatePayment(InfoInterface $payment, $arguments);
}
10 changes: 10 additions & 0 deletions Api/Transaction/PaymentDetailsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Vipps\Payment\Api\Transaction;

interface PaymentDetailsInterface
{
public function get(string $orderId);
}
12 changes: 8 additions & 4 deletions Block/Express/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

namespace Vipps\Payment\Block\Express;

use Magento\Framework\View\Element\Template;
Expand All @@ -21,6 +22,7 @@
use Magento\Framework\Math\Random;
use Magento\Payment\Gateway\ConfigInterface;
use Magento\Catalog\Block\ShortcutInterface;
use Vipps\Payment\Model\Config\Source\Version;

/**
* Class Button
Expand Down Expand Up @@ -67,9 +69,9 @@ class Button extends Template implements ShortcutInterface
*/
public function __construct(
Template\Context $context,
Random $mathRandom,
ConfigInterface $config,
array $data = []
Random $mathRandom,
ConfigInterface $config,
array $data = []
) {
$this->config = $config;
$this->assetRepo = $context->getAssetRepository();
Expand All @@ -87,7 +89,9 @@ public function __construct(
protected function _toHtml() //@codingStandardsIgnoreLine
{
if (!$this->config->getValue('active')
|| !$this->config->getValue('express_checkout')) {
|| !$this->config->getValue('express_checkout')
|| $this->config->getValue('version') !== Version::CONFIG_VIPPS
) {
return '';
}
if (!$this->getIsInCatalogProduct() &&
Expand Down
73 changes: 46 additions & 27 deletions Controller/Payment/Fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
use Psr\Log\LoggerInterface;
use Vipps\Payment\Api\Data\QuoteInterface;
use Vipps\Payment\Api\QuoteRepositoryInterface;
use Vipps\Payment\Gateway\Config\Config;
use Vipps\Payment\Gateway\Transaction\Transaction;
use Vipps\Payment\GatewayEpayment\Data\Payment;
use Vipps\Payment\Model\Fallback\AuthoriseProxy;
use Vipps\Payment\Model\Gdpr\Compliance;
use Vipps\Payment\Model\OrderLocator;
use Vipps\Payment\Model\Transaction\StatusVisitor;
use Vipps\Payment\Model\TransactionProcessor;

/**
Expand Down Expand Up @@ -106,7 +110,7 @@ class Fallback implements ActionInterface, CsrfAwareActionInterface
private $resultFactory;

/**
* @var ConfigInterface
* @var Config
*/
private $config;

Expand All @@ -119,6 +123,8 @@ class Fallback implements ActionInterface, CsrfAwareActionInterface
* @var OrderInterface|null
*/
private $order;
private StatusVisitor $statusVisitor;
private AuthoriseProxy $authoriseProxy;

/**
* Fallback constructor.
Expand All @@ -134,23 +140,25 @@ class Fallback implements ActionInterface, CsrfAwareActionInterface
* @param OrderLocator $orderLocator
* @param Compliance $compliance
* @param LoggerInterface $logger
* @param ConfigInterface $config
* @param Config $config
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
ResultFactory $resultFactory,
RequestInterface $request,
SessionManagerInterface $checkoutSession,
TransactionProcessor $transactionProcessor,
CartRepositoryInterface $cartRepository,
ManagerInterface $messageManager,
ResultFactory $resultFactory,
RequestInterface $request,
SessionManagerInterface $checkoutSession,
TransactionProcessor $transactionProcessor,
CartRepositoryInterface $cartRepository,
ManagerInterface $messageManager,
QuoteRepositoryInterface $vippsQuoteRepository,
OrderManagementInterface $orderManagement,
OrderLocator $orderLocator,
Compliance $compliance,
LoggerInterface $logger,
ConfigInterface $config
OrderLocator $orderLocator,
Compliance $compliance,
LoggerInterface $logger,
Config $config,
StatusVisitor $statusVisitor,
AuthoriseProxy $authoriseProxy
) {
$this->resultFactory = $resultFactory;
$this->request = $request;
Expand All @@ -164,6 +172,8 @@ public function __construct(
$this->orderManagement = $orderManagement;
$this->logger = $logger;
$this->config = $config;
$this->statusVisitor = $statusVisitor;
$this->authoriseProxy = $authoriseProxy;
}

/**
Expand All @@ -176,9 +186,10 @@ public function execute()
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
try {
$this->authorize();

$vippsQuote = $this->getVippsQuote();

$this->authoriseProxy->do($this->request, $vippsQuote);

$transaction = $this->transactionProcessor->process($vippsQuote);

$resultRedirect = $this->prepareResponse($resultRedirect, $transaction);
Expand All @@ -196,7 +207,7 @@ public function execute()
$cartPersistence = $this->config->getValue('cancellation_cart_persistence');

$quoteCouldBeRestored = $transaction
&& ($transaction->transactionWasCancelled() || $transaction->isTransactionExpired());
&& ($this->statusVisitor->isCanceled($transaction) || $this->statusVisitor->isExpired($transaction));
$order = $this->getOrder();

if ($quoteCouldBeRestored && $cartPersistence) {
Expand Down Expand Up @@ -285,20 +296,20 @@ private function getVippsQuote($forceReload = false): QuoteInterface
{
if (null === $this->vippsQuote || $forceReload) {
$this->vippsQuote = $this->vippsQuoteRepository
->loadByOrderId($this->request->getParam('order_id'));
->loadByOrderId($this->authoriseProxy->getOrderId($this->request));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one

}

return $this->vippsQuote;
}

/**
* @param Redirect $resultRedirect
* @param Transaction $transaction
* @param Transaction|Payment $transaction
*
* @return Redirect
* @throws \Exception
*/
private function prepareResponse(Redirect $resultRedirect, Transaction $transaction)
private function prepareResponse(Redirect $resultRedirect, $transaction)
{
$this->defineMessage($transaction);
$this->defineRedirectPath($resultRedirect, $transaction);
Expand Down Expand Up @@ -344,13 +355,19 @@ private function isCartPersistent()
return $this->config->getValue('cancellation_cart_persistence');
}

private function defineMessage(Transaction $transaction): void
/**
* @param Transaction|Payment $transaction
* @return void
*/
private function defineMessage($transaction): void
{
if ($transaction->transactionWasCancelled()) {
$this->messageManager->addWarningMessage(__('Your order was cancelled in Vipps.'));
} elseif ($transaction->isTransactionReserved() || $transaction->isTransactionCaptured()) {
//$this->messageManager->addWarningMessage(__('Your order was successfully placed.'));
} elseif ($transaction->isTransactionExpired()) {
if ($this->statusVisitor->isCanceled($transaction)) {
$this->messageManager->addWarningMessage(__('Your order was cancelled in %1.', $this->config->getTitle()));
} elseif (
$this->statusVisitor->isReserved($transaction)
|| $this->statusVisitor->isCaptured($transaction)) {
$this->messageManager->addWarningMessage(__('Your order was successfully placed.'));
} elseif ($this->statusVisitor->isExpired($transaction)) {
$this->messageManager->addErrorMessage(
__('Transaction was expired. Please, place your order again')
);
Expand All @@ -363,13 +380,15 @@ private function defineMessage(Transaction $transaction): void

/**
* @param Redirect $resultRedirect
* @param Transaction $transaction
* @param Transaction|Payment $transaction
*
* @throws NoSuchEntityException
*/
private function defineRedirectPath(Redirect $resultRedirect, Transaction $transaction): void
private function defineRedirectPath(Redirect $resultRedirect, $transaction): void
{
if ($transaction->isTransactionReserved() || $transaction->isTransactionCaptured()) {
if ($this->statusVisitor->isReserved($transaction)
|| $this->statusVisitor->isCaptured($transaction)
) {
$resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
} else {
$orderId = $this->getOrder() ? $this->getOrder()->getEntityId() : null;
Expand Down
10 changes: 5 additions & 5 deletions Controller/Payment/InitExpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Payment\Gateway\ConfigInterface;
use Magento\Payment\Gateway\Command\ResultInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Psr\Log\LoggerInterface;
use Vipps\Payment\Api\CommandManagerInterface;
use Vipps\Payment\Gateway\Config\Config;
use Vipps\Payment\Gateway\Request\Initiate\InitiateBuilderInterface;
use Vipps\Payment\Model\Method\Vipps;

Expand Down Expand Up @@ -74,7 +74,7 @@ class InitExpress implements ActionInterface
private $frameworkExceptionFactory;

/**
* @var ConfigInterface
* @var Config
*/
private $config;

Expand Down Expand Up @@ -102,7 +102,7 @@ class InitExpress implements ActionInterface
* @param CommandManagerInterface $commandManager
* @param CartRepositoryInterface $cartRepository
* @param LocalizedExceptionFactory $frameworkExceptionFactory
* @param ConfigInterface $config
* @param Config $config
* @param ManagerInterface $messageManager
* @param CheckoutHelper $checkoutHelper
* @param LoggerInterface $logger
Expand All @@ -116,7 +116,7 @@ public function __construct(
CommandManagerInterface $commandManager,
CartRepositoryInterface $cartRepository,
LocalizedExceptionFactory $frameworkExceptionFactory,
ConfigInterface $config,
Config $config,
ManagerInterface $messageManager,
CheckoutHelper $checkoutHelper,
LoggerInterface $logger
Expand Down Expand Up @@ -155,7 +155,7 @@ public function execute()
} catch (\Exception $e) {
$this->logger->critical($this->enlargeMessage($e));
$this->messageManager->addErrorMessage(
__('An error occurred during request to Vipps. Please try again later.')
__('An error occurred during request to %1. Please try again later.', $this->config->getTitle())
);
$resultRedirect->setPath('checkout/cart', ['_secure' => true]);
}
Expand Down
Loading