Completed
Pull Request — master (#34)
by Roman
14:40 queued 07:36
created

CheckoutPaymentChecker::isQuotePaymentValid()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
nc 3
nop 2
dl 0
loc 23
rs 9.7998
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Braintree\Business\Checkout;
9
10
use Generated\Shared\Transfer\CheckoutErrorTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutErrorTransfer 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\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...
12
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...
13
use SprykerEco\Shared\Braintree\BraintreeConfig;
14
15
class CheckoutPaymentChecker implements CheckoutPaymentCheckerInterface
16
{
17
    protected const ERROR_MESSAGE_INVALID_PARAMETER_NONCE = 'Parameter `NONCE` is invalid.';
18
19
    /**
20
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
21
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
22
     *
23
     * @return bool
24
     */
25
    public function isQuotePaymentValid(
26
        QuoteTransfer $quoteTransfer,
27
        CheckoutResponseTransfer $checkoutResponseTransfer
28
    ): bool {
29
        $paymentTransfer = $quoteTransfer
30
            ->requirePayment()
31
            ->getPayment();
32
        if ($paymentTransfer->getPaymentProvider() !== BraintreeConfig::PROVIDER_NAME) {
33
            return true;
34
        }
35
36
        $braintreePaymentTransfer = $paymentTransfer
37
            ->requireBraintree()
38
            ->getBraintree();
39
        if (!$braintreePaymentTransfer->getNonce()) {
40
            $checkoutResponseTransfer
41
                ->setIsSuccess(false)
42
                ->addError($this->createCheckoutErrorTransfer());
43
44
            return false;
45
        }
46
47
        return true;
48
    }
49
50
    /**
51
     * @return \Generated\Shared\Transfer\CheckoutErrorTransfer
52
     */
53
    protected function createCheckoutErrorTransfer(): CheckoutErrorTransfer
54
    {
55
        return (new CheckoutErrorTransfer())
56
            ->setMessage(static::ERROR_MESSAGE_INVALID_PARAMETER_NONCE);
57
    }
58
}
59