RefundOrderTransactionHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A refund() 0 17 2
A __construct() 0 8 1
A getRefund() 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\Handler;
9
10
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...
11
use Generated\Shared\Transfer\RefundTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RefundTransfer 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\TransactionMetaTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TransactionMetaTransfer 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 Orm\Zed\Sales\Persistence\SpySalesOrder;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder 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...
14
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface;
15
use SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface;
16
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface;
17
18
class RefundOrderTransactionHandler extends AbstractTransactionHandler implements RefundOrderTransactionHandlerInterface
19
{
20
    /**
21
     * @var \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface
22
     */
23
    protected $refundFacade;
24
25
    /**
26
     * @param \SprykerEco\Zed\Braintree\Business\Payment\Transaction\TransactionInterface $transaction
27
     * @param \SprykerEco\Zed\Braintree\Business\Payment\Transaction\MetaVisitor\TransactionMetaVisitorInterface $transactionMetaVisitor
28
     * @param \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToRefundFacadeInterface $refundFacade
29
     */
30
    public function __construct(
31
        TransactionInterface $transaction,
32
        TransactionMetaVisitorInterface $transactionMetaVisitor,
33
        BraintreeToRefundFacadeInterface $refundFacade
34
    ) {
35
        parent::__construct($transaction, $transactionMetaVisitor);
36
37
        $this->refundFacade = $refundFacade;
38
    }
39
40
    /**
41
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $salesOrderItems
42
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $salesOrderEntity
43
     *
44
     * @return \Generated\Shared\Transfer\BraintreeTransactionResponseTransfer
45
     */
46
    public function refund(array $salesOrderItems, SpySalesOrder $salesOrderEntity): BraintreeTransactionResponseTransfer
47
    {
48
        $refundTransfer = $this->getRefund($salesOrderItems, $salesOrderEntity);
49
50
        $transactionMetaTransfer = new TransactionMetaTransfer();
51
        $transactionMetaTransfer->setIdSalesOrder($salesOrderEntity->getIdSalesOrder());
52
        $transactionMetaTransfer->setRefund($refundTransfer);
53
54
        $this->transactionMetaVisitor->visit($transactionMetaTransfer);
55
56
        $braintreeTransactionResponseTransfer = $this->transaction->executeTransaction($transactionMetaTransfer);
57
58
        if ($braintreeTransactionResponseTransfer->getIsSuccess()) {
59
            $this->refundFacade->saveRefund($refundTransfer);
60
        }
61
62
        return $braintreeTransactionResponseTransfer;
63
    }
64
65
    /**
66
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $salesOrderItems
67
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $salesOrderEntity
68
     *
69
     * @return \Generated\Shared\Transfer\RefundTransfer
70
     */
71
    protected function getRefund(array $salesOrderItems, SpySalesOrder $salesOrderEntity): RefundTransfer
72
    {
73
        return $this->refundFacade->calculateRefund($salesOrderItems, $salesOrderEntity);
74
    }
75
}
76