Completed
Push — master ( 9db63e...40913a )
by Oleksandr
24s queued 13s
created

PayoneCheckoutPreConditionPlugin::checkCondition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Communication\Plugin\Checkout;
9
10
use Generated\Shared\Transfer\CheckoutResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Spryker\Zed\CheckoutExtension\Dependency\Plugin\CheckoutPreConditionPluginInterface;
13
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
14
use SprykerEco\Zed\Payone\PayoneConfig;
15
16
/**
17
 * @method \SprykerEco\Zed\Payone\Business\PayoneFacadeInterface getFacade()
18
 * @method \SprykerEco\Zed\Payone\Communication\PayoneCommunicationFactory getFactory()
19
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface getQueryContainer()
20
 * @method \SprykerEco\Zed\Payone\PayoneConfig getConfig()
21
 */
22
class PayoneCheckoutPreConditionPlugin extends AbstractPlugin implements CheckoutPreConditionPluginInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     * - Does additional logic only if the payment provider is 'Payone' otherwise does nothing.
27
     * - Maps Quote to CalculableObject.
28
     * - Run all calculator plugins.
29
     * - Maps CalculableObject to Quote.
30
     * - Executes `QuotePostRecalculatePluginInterface` stack of plugins if `$executeQuotePlugins` is true.
31
     * - Sets the amount of the payment detail of the 'Payone' payment.
32
     * - Returns 'true' in any case.
33
     *
34
     * @api
35
     *
36
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
37
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
38
     *
39
     * @return bool
40
     */
41
    public function checkCondition(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer)
42
    {
43
        if ($quoteTransfer->getPayment()->getPaymentProvider() === PayoneConfig::PROVIDER_NAME) {
44
            $quoteTransfer = $this->getFactory()->getCalculationFacade()->recalculateQuote($quoteTransfer);
45
            $quoteTransfer->getPayment()->getPayone()->getPaymentDetail()->setAmount($quoteTransfer->getPayment()->getAmount());
46
        }
47
48
        return true;
49
    }
50
}
51