PostSaveHook::postSaveHook()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 2
dl 0
loc 16
rs 9.9332
c 0
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\Hook;
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\Zed\Braintree\Business\Payment\Method\ApiConstants;
14
use SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface;
15
16
class PostSaveHook implements PostSaveHookInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface
20
     */
21
    protected $repository;
22
23
    /**
24
     * @param \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface $repository
25
     */
26
    public function __construct(BraintreeRepositoryInterface $repository)
27
    {
28
        $this->repository = $repository;
29
    }
30
31
    /**
32
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
33
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
34
     *
35
     * @return \Generated\Shared\Transfer\CheckoutResponseTransfer
36
     */
37
    public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
38
    {
39
        $paymentBraintreeTransactionStatusLogTransfer = $this->repository
40
            ->findPaymentBraintreeTransactionStatusLogQueryBySalesOrderId($checkoutResponse->getSaveOrder()->getIdSalesOrder());
41
42
        if ($paymentBraintreeTransactionStatusLogTransfer &&
43
            $paymentBraintreeTransactionStatusLogTransfer->getCode() != ApiConstants::PAYMENT_CODE_AUTHORIZE_SUCCESS) {
44
            $checkoutErrorTransfer = new CheckoutErrorTransfer();
45
            $checkoutErrorTransfer
46
                ->setErrorCode($paymentBraintreeTransactionStatusLogTransfer->getCode())
47
                ->setMessage($paymentBraintreeTransactionStatusLogTransfer->getMessage());
48
49
            $checkoutResponse->addError($checkoutErrorTransfer);
50
        }
51
52
        return $checkoutResponse;
53
    }
54
}
55