Passed
Push — feature/paypal-express ( aa383f...32ec15 )
by Volodymyr
05:03
created

ShipmentTransaction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A doTransaction() 0 3 1
A __construct() 0 6 1
A capture() 0 5 1
A getTransactionType() 0 3 1
A afterTransaction() 0 15 2
A getTransactionCode() 0 3 1
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\Payment\Transaction;
9
10
use Braintree\Transaction as BraintreeTransaction;
11
use SprykerEco\Zed\Braintree\BraintreeConfig;
12
use SprykerEco\Zed\Braintree\Business\Payment\Method\ApiConstants;
13
use SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface;
14
15
class ShipmentTransaction extends AbstractTransaction
16
{
17
    /**
18
     * @var \SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface
19
     */
20
    protected $braintreeEntityManager;
21
22
    /**
23
     * @param \SprykerEco\Zed\Braintree\BraintreeConfig $config
24
     * @param \SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface $braintreeEntityManager
25
     */
26
    public function __construct(
27
        BraintreeConfig $config,
28
        BraintreeEntityManagerInterface $braintreeEntityManager
29
    ) {
30
        parent::__construct($config);
31
        $this->braintreeEntityManager = $braintreeEntityManager;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    protected function getTransactionType()
38
    {
39
        return ApiConstants::SALE;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    protected function getTransactionCode()
46
    {
47
        return ApiConstants::TRANSACTION_CODE_CAPTURE;
48
    }
49
50
    /**
51
     * @return \Braintree\Result\Successful|\Braintree\Result\Error|\Braintree\Transaction
52
     */
53
    protected function doTransaction()
54
    {
55
        return $this->capture();
56
    }
57
58
    /**
59
     * @param \Braintree\Result\Error|\Braintree\Result\Successful $response
60
     *
61
     * @return \Generated\Shared\Transfer\BraintreeTransactionResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...sactionResponseTransfer 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...
62
     */
63
    protected function afterTransaction($response)
64
    {
65
        if ($this->isTransactionSuccessful($response)) {
66
            $braintreeTransactionResponseTransfer = $this->getSuccessResponseTransfer($response);
67
            $this->logApiResponse($braintreeTransactionResponseTransfer, $this->getIdPayment(), $response->transaction->statusHistory);
0 ignored issues
show
Bug introduced by
$this->getIdPayment() of type string is incompatible with the type integer expected by parameter $idPayment of SprykerEco\Zed\Braintree...ction::logApiResponse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            $this->logApiResponse($braintreeTransactionResponseTransfer, /** @scrutinizer ignore-type */ $this->getIdPayment(), $response->transaction->statusHistory);
Loading history...
68
69
            $this->braintreeEntityManager->updateIsShipmentOperationValue($this->getIdPayment(), $braintreeTransactionResponseTransfer->getTransactionId(), true);
0 ignored issues
show
Bug introduced by
$this->getIdPayment() of type string is incompatible with the type integer expected by parameter $idPaymentBraintree of SprykerEco\Zed\Braintree...hipmentOperationValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
            $this->braintreeEntityManager->updateIsShipmentOperationValue(/** @scrutinizer ignore-type */ $this->getIdPayment(), $braintreeTransactionResponseTransfer->getTransactionId(), true);
Loading history...
70
71
            return $braintreeTransactionResponseTransfer;
72
        }
73
74
        $braintreeTransactionResponseTransfer = $this->getErrorResponseTransfer($response);
75
        $this->logApiResponse($braintreeTransactionResponseTransfer, $this->getIdPayment());
76
77
        return $braintreeTransactionResponseTransfer;
78
    }
79
80
    /**
81
     * @return \Braintree\Result\Error|\Braintree\Result\Successful
82
     */
83
    protected function capture()
84
    {
85
        return BraintreeTransaction::submitForPartialSettlement(
86
            $this->getTransactionIdentifier(),
87
            $this->transactionMetaTransfer->getCaptureAmount()
88
        );
89
    }
90
}
91