Skip to content

Commit

Permalink
Merge pull request #51 from NikZh/publication-1.2.9
Browse files Browse the repository at this point in the history
VIPPS-243: Publication v.1.2.9
  • Loading branch information
NikZh authored Sep 9, 2019
2 parents 57e27a8 + a7a4cfe commit 82d1652
Show file tree
Hide file tree
Showing 31 changed files with 1,154 additions and 33 deletions.
53 changes: 53 additions & 0 deletions Block/PartialVoid/Order/Email/Items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright 2018 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\Block\PartialVoid\Order\Email;
use Magento\Sales\Block\Order\Email\Items as OrderItems;
use Magento\Sales\Model\Order;

/**
* Class Items
* @package Vipps\Payment\Block\PartialVoid\Order\Email
*/
class Items extends OrderItems
{
/**
* @var Order
*/
private $order;

/**
* For this block we only need items that was canceled, using native template is preferred
* so other items was removed from this order instance (just for template)
*
* @return Order
*/
public function getOrder(): Order
{
if (!$this->order) {
$this->order = clone $this->getData('order');
$items = $this->order->getItems();
foreach ($items as $key => $item) {
if (!$item->getQtyCanceled()) {
unset($items[$key]);
}
}
$this->order->setItems($items);
}

return $this->order;
}
}
22 changes: 16 additions & 6 deletions Controller/Payment/ShippingDetails.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2018 Vipps
* Copyright 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
Expand All @@ -25,9 +25,7 @@
use Magento\Quote\Model\Quote;
use Vipps\Payment\Model\Gdpr\Compliance;
use Vipps\Payment\Gateway\Transaction\ShippingDetails as TransactionShippingDetails;
use Vipps\Payment\Model\{
QuoteLocator, Quote\AddressUpdater
};
use Vipps\Payment\Model\{Quote\ShippingMethodValidator, QuoteLocator, Quote\AddressUpdater};
use Zend\Http\Response as ZendResponse;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -77,6 +75,10 @@ class ShippingDetails extends Action
* @var AddressUpdater
*/
private $addressUpdater;
/**
* @var ShippingMethodValidator
*/
private $shippingMethodValidator;

/**
* ShippingDetails constructor.
Expand All @@ -98,6 +100,7 @@ public function __construct(
ShipmentEstimationInterface $shipmentEstimation,
AddressInterfaceFactory $addressFactory,
AddressUpdater $addressUpdater,
ShippingMethodValidator $shippingMethodValidator,
Compliance $compliance,
Json $serializer,
LoggerInterface $logger
Expand All @@ -111,6 +114,7 @@ public function __construct(
$this->logger = $logger;
$this->addressUpdater = $addressUpdater;
$this->gdprCompliance = $compliance;
$this->shippingMethodValidator = $shippingMethodValidator;
}

/**
Expand Down Expand Up @@ -147,12 +151,18 @@ public function execute()
'shippingDetails' => []
];
foreach ($shippingMethods as $key => $shippingMethod) {

$methodFullCode = $shippingMethod->getCarrierCode() . '_' . $shippingMethod->getMethodCode();
if (!$this->shippingMethodValidator->isValid($methodFullCode)) {
continue;
}

$responseData['shippingDetails'][] = [
'isDefault' => 'N',
'priority' => $key,
'shippingCost' => $shippingMethod->getAmount(),
'shippingMethod' => $shippingMethod->getMethodCode(),
'shippingMethodId' => $shippingMethod->getCarrierCode() . '_' . $shippingMethod->getMethodCode(),
'shippingMethod' => $shippingMethod->getMethodTitle(),
'shippingMethodId' => $methodFullCode,
];
}
$result->setHttpResponseCode(ZendResponse::STATUS_CODE_200);
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Command/CaptureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private function captureBasedOnPaymentDetails($commandSubject, Transaction $tran
$message = __(
'Captured amount is not the same as you are trying to capture.'
. PHP_EOL . ' Payment information was not synced correctly between Magento and Vipps.'
. PHP_EOL . ' It might be happened that previous operation was successfully completed in Vipps'
. PHP_EOL . ' It might be that the previous operation was successfully completed in Vipps'
. PHP_EOL . ' but Magento did not receive a response.'
. PHP_EOL . ' To be in sync you have to capture the same amount that has been already captured'
. PHP_EOL . ' in Vipps: %1',
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Command/RefundCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private function refundBasedOnPaymentDetails($commandSubject, Transaction $trans
$message = __(
'Refunded amount is not the same as you are trying to refund.'
. PHP_EOL . ' Payment information was not synced correctly between Magento and Vipps.'
. PHP_EOL . ' It might be happened that previous operation was successfully completed in Vipps'
. PHP_EOL . ' It might be that the previous operation was successfully completed in Vipps'
. PHP_EOL . ' but Magento did not receive a response.'
. PHP_EOL . ' To be in sync you have to refund the same amount that has been already refunded'
. PHP_EOL . ' in Vipps: %1',
Expand Down
85 changes: 85 additions & 0 deletions Gateway/Config/CanVoidHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Copyright 2018 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.
*/
declare(strict_types=1);

namespace Vipps\Payment\Gateway\Config;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Payment\Gateway\Config\ValueHandlerInterface;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Vipps\Payment\Gateway\Command\PaymentDetailsProvider;
use Vipps\Payment\Gateway\Exception\VippsException;
use Vipps\Payment\Gateway\Transaction\TransactionBuilder;

/**
* Class CanVoidHandler
* @package Vipps\Payment\Gateway\Config
*/
class CanVoidHandler implements ValueHandlerInterface
{
/**
* @var Config
*/
private $gatewayConfig;

/**
* @var PaymentDetailsProvider
*/
private $paymentDetailsProvider;

/**
* @var TransactionBuilder
*/
private $transactionBuilder;

/**
* CanVoidHandler constructor.
*
* @param Config $gatewayConfig
* @param PaymentDetailsProvider $paymentDetailsProvider
* @param TransactionBuilder $transactionBuilder
*/
public function __construct(
Config $gatewayConfig,
PaymentDetailsProvider $paymentDetailsProvider,
TransactionBuilder $transactionBuilder
) {
$this->gatewayConfig = $gatewayConfig;
$this->paymentDetailsProvider = $paymentDetailsProvider;
$this->transactionBuilder = $transactionBuilder;
}

/**
* Disable partial online void
*
* @param array $subject
* @param null $storeId
*
* @return bool
* @throws NoSuchEntityException
* @throws VippsException
*/
public function handle(array $subject, $storeId = null): bool
{
$response = $this->paymentDetailsProvider->get($subject);
$transaction = $this->transactionBuilder->setData($response)->build();
if ($transaction->getTransactionSummary()->getCapturedAmount() > 0) {
return false;
}

return (bool)$this->gatewayConfig->getValue(SubjectReader::readField($subject), $storeId);
}
}
33 changes: 14 additions & 19 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,14 @@
1. You must have a Vipps merchant account. See [Vipps på Nett](https://www.vipps.no/bedrift/vipps-pa-nett)
1. As with _all_ Magento extensions, it is highly recommended to backup your site before installation and to install and test on a staging environment prior to production deployments.

# Installation via Composer (recommended)
# Installation via Composer

1. Navigate to your [Magento root directory](https://devdocs.magento.com/guides/v2.2/extension-dev-guide/build/module-file-structure.html).
1. Enter command: `composer require vipps/module-payment`
1. Enter command: `php bin/magento module:enable Vipps_Payment`
1. Enter command: `php bin/magento setup:upgrade`
1. Put your Magento in production mode if it’s required.

# Installation via Marketplace

**Please note:** _This extension is not yet available on Magento Marketplace. This notice will be removed when it is._

Here are steps required to install Payments extension via Component Manager.

1. Make a purchase for the Vipps extension on [Magento Marketplace](https://marketplace.magento.com).
1. From your `Magento Admin` access `System` -> `Web Setup Wizard` page.
1. Enter Marketplace authentication keys. Please read about authentication keys generation.
1. Navigate to `Component Manager` page.
1. On the `Component Manager` page click the `Sync button to update your new purchased extensions.
1. Click `Install` in the `Action` column for `Realex Payments` component.
1. . Follow Web Setup Wizard instructions.

# Configuration

The Vipps Payment module can be easily configured to meet business expectations of your web store. This section will show you how to configure the extension via `Magento Admin`.
Expand All @@ -38,6 +24,7 @@ From Magento Admin navigate to `Store` -> `Configuration` -> `Sales` -> `Payment
By clicking the `Configure` button, all configuration module settings will be shown. Once you have finished with the configuration simply click `Close` and `Save` button for your convenience.

## Add a separate connection for Vipps resources
These settings are required to prevent profiles loss when Magento reverts invoice/refund transactions.
* Duplicate 'default' connection in app/etc/env.php and name it 'vipps'. It should look like:
```
'vipps' =>
Expand All @@ -59,7 +46,6 @@ By clicking the `Configure` button, all configuration module settings will be sh
'connection' => 'vipps',
),
```
These settings are required to prevent profiles loss when Magento reverts invoice/refund transactions.

# Settings

Expand All @@ -68,19 +54,28 @@ Vipps Payments configuration is divided by sections. It helps to quickly find an
1. Basic Vipps Settings.
1. Express Checkout Settings.

![Screenshot of Vipps Settings](docs/vipps_method.png)
![Screenshot of Vipps Settings](docs/images/vipps_method.png)

Please ensure you check all configuration settings prior to using Vipps Payment. Pay attention to the Vipps Basic Settings section, namely `Saleunit Serial Number`, `Client ID`, `Client Secret`, `Subscription Key 1`, `Subscription Key 2`.

For information about how to find the above values, see the [Vipps Developer Portal documentation](https://github.com/vippsas/vipps-developers/blob/master/vipps-developer-portal-getting-started.md).

# Basic Vipps Settings

![Screenshot of Basic Vipps Settings](docs/vipps_basic.png)
![Screenshot of Basic Vipps Settings](docs/images/vipps_basic.png)

# Express Checkout Settings

![Screenshot of Express Vipps Settings](docs/express_vipps_settings.png)
![Screenshot of Express Vipps Settings](docs/images/express_vipps_settings.png)

# Quote Monitoring

Quote it is a cart contents in Magento. Theoretically the quote is an offer and if the user accepts it (by checking out) it converts to order.

When payment was initiated (customer was redirected to Vipps) Magento creates a new record on `Vipps Quote Monitoring` page and starts tracking an Vipps order.
To do that Magento has a cron job that runs by schedule/each 10 min.

You can find this page under `System -> Vipps` menu section. Under `Store -> Sales -> Payment Methods -> Vipps -> Cancellation` you can find appropriate configuration settings.

# Support

Expand Down
69 changes: 69 additions & 0 deletions Model/Config/Source/Email/Template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright 2018 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.
*/
declare(strict_types=1);

namespace Vipps\Payment\Model\Config\Source\Email;

use Magento\Config\Model\Config\Source\Email\Template as EmailTemplate;
use Magento\Config\Model\Config\Structure\SearchInterface;
use Magento\Email\Model\ResourceModel\Template\CollectionFactory;
use Magento\Email\Model\Template\Config;
use Magento\Framework\Registry;

/**
* Class Template
* @package Vipps\Payment\Model\Config\Source\Email
*/
class Template extends EmailTemplate
{
/**
* @var SearchInterface
*/
private $config;

/**
* Template constructor.
*
* @param Registry $coreRegistry
* @param CollectionFactory $templatesFactory
* @param Config $emailConfig
* @param SearchInterface $config
* @param array $data
*/
public function __construct(
Registry $coreRegistry,
CollectionFactory $templatesFactory,
Config $emailConfig,
SearchInterface $config,
array $data = []
) {
parent::__construct($coreRegistry, $templatesFactory, $emailConfig, $data);
$this->config = $config;
}

/**
* Replace config path for correct rendering default template option
*
* @return array
*/
public function toOptionArray(): array
{
$element = $this->config->getElement($this->getPath());
$configData = $element->getData();
$this->setPath($configData['config_path']);
return parent::toOptionArray();
}
}
Loading

0 comments on commit 82d1652

Please sign in to comment.