Completed
Push — master ( e2eed5...73dfaa )
by Oleksandr
13s queued 10s
created

ShipmentTransaction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 77
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A doTransaction() 0 3 1
A __construct() 0 6 1
A capture() 0 7 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 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...
12
use SprykerEco\Zed\Braintree\BraintreeConfig;
13
use SprykerEco\Zed\Braintree\Business\Payment\Method\ApiConstants;
14
use SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface;
15
16
class ShipmentTransaction extends AbstractTransaction
17
{
18
    protected const ATTRIBUTE_KEY_ORDER_ID = 'orderId';
19
20
    /**
21
     * @var \SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface
22
     */
23
    protected $braintreeEntityManager;
24
25
    /**
26
     * @param \SprykerEco\Zed\Braintree\BraintreeConfig $config
27
     * @param \SprykerEco\Zed\Braintree\Persistence\BraintreeEntityManagerInterface $braintreeEntityManager
28
     */
29
    public function __construct(
30
        BraintreeConfig $config,
31
        BraintreeEntityManagerInterface $braintreeEntityManager
32
    ) {
33
        parent::__construct($config);
34
        $this->braintreeEntityManager = $braintreeEntityManager;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    protected function getTransactionType(): string
41
    {
42
        return ApiConstants::SALE;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    protected function getTransactionCode(): string
49
    {
50
        return ApiConstants::TRANSACTION_CODE_CAPTURE;
51
    }
52
53
    /**
54
     * @return \Braintree\Result\Successful|\Braintree\Result\Error|\Braintree\Transaction
55
     */
56
    protected function doTransaction()
57
    {
58
        return $this->capture();
59
    }
60
61
    /**
62
     * @param \Braintree\Result\Error|\Braintree\Result\Successful $response
63
     *
64
     * @return \Generated\Shared\Transfer\BraintreeTransactionResponseTransfer
65
     */
66
    protected function afterTransaction($response): BraintreeTransactionResponseTransfer
67
    {
68
        if ($this->isTransactionSuccessful($response)) {
69
            $braintreeTransactionResponseTransfer = $this->getSuccessResponseTransfer($response);
70
            $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

70
            $this->logApiResponse($braintreeTransactionResponseTransfer, /** @scrutinizer ignore-type */ $this->getIdPayment(), $response->transaction->statusHistory);
Loading history...
71
72
            $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

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