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\MetaVisitor; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\PaymentBraintreeTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\TransactionMetaTransfer; |
|
|
|
|
12
|
|
|
use SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface; |
13
|
|
|
|
14
|
|
|
class PaymentTransactionMetaVisitor implements TransactionMetaVisitorInterface |
15
|
|
|
{ |
16
|
|
|
protected const TRANSACTION_STATUS = 'settling'; |
17
|
|
|
protected const TRANSACTION_CODE = 'capture'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface |
21
|
|
|
*/ |
22
|
|
|
protected $repository; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface $repository |
26
|
|
|
*/ |
27
|
|
|
public function __construct(BraintreeRepositoryInterface $repository) |
28
|
|
|
{ |
29
|
|
|
$this->repository = $repository; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param \Generated\Shared\Transfer\TransactionMetaTransfer $transactionMetaTransfer |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function visit(TransactionMetaTransfer $transactionMetaTransfer) |
38
|
|
|
{ |
39
|
|
|
$paymentBraintreeTransfer = $this->findPaymentBraintreeTransfer($transactionMetaTransfer); |
40
|
|
|
|
41
|
|
|
if ($paymentBraintreeTransfer) { |
42
|
|
|
$transactionMetaTransfer->setIdPayment($paymentBraintreeTransfer->getIdPaymentBraintree()); |
43
|
|
|
$transactionMetaTransfer->setTransactionIdentifier($paymentBraintreeTransfer->getTransactionId()); |
44
|
|
|
|
45
|
|
|
if ($transactionMetaTransfer->getRefund() && $this->countRefundedUniqItems($transactionMetaTransfer->getRefund()->getItems()) === 1) { |
46
|
|
|
$transactionMetaTransfer->setTransactionIdentifier($this->getTransactionId($transactionMetaTransfer)); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param \Generated\Shared\Transfer\TransactionMetaTransfer $transactionMetaTransfer |
53
|
|
|
* |
54
|
|
|
* @return \Generated\Shared\Transfer\PaymentBraintreeTransfer|null |
55
|
|
|
*/ |
56
|
|
|
protected function findPaymentBraintreeTransfer(TransactionMetaTransfer $transactionMetaTransfer): ?PaymentBraintreeTransfer |
57
|
|
|
{ |
58
|
|
|
$idSalesOrderEntity = $transactionMetaTransfer->requireIdSalesOrder()->getIdSalesOrder(); |
59
|
|
|
|
60
|
|
|
return $this->repository->findPaymentBraintreeBySalesOrderId($idSalesOrderEntity); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param \Generated\Shared\Transfer\TransactionMetaTransfer $transactionMetaTransfer |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
protected function getTransactionId(TransactionMetaTransfer $transactionMetaTransfer): string |
69
|
|
|
{ |
70
|
|
|
$idSalesOrderItem = $transactionMetaTransfer->getRefund()->getItems()[0]->getIdSalesOrderItem(); |
71
|
|
|
|
72
|
|
|
$transactionId = $this->repository |
73
|
|
|
->findSucceededPaymentBraintreeTransactionStatusLogQueryBySalesOrderIdAndTransactionCode( |
74
|
|
|
$transactionMetaTransfer->getIdSalesOrder(), |
75
|
|
|
static::TRANSACTION_CODE, |
76
|
|
|
static::TRANSACTION_STATUS |
77
|
|
|
) |
78
|
|
|
->getTransactionId(); |
79
|
|
|
|
80
|
|
|
$paymentBraintreeTransactionStatusLogTransferByOrderItem = $this->repository |
81
|
|
|
->findPaymentBraintreeTransactionStatusLogQueryByOrderItem($idSalesOrderItem); |
82
|
|
|
|
83
|
|
|
if ($paymentBraintreeTransactionStatusLogTransferByOrderItem) { |
84
|
|
|
$transactionId = $this->repository |
85
|
|
|
->findPaymentBraintreeTransactionStatusLogQueryByOrderItem($idSalesOrderItem)->getTransactionId(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $transactionId; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param \ArrayObject|\Generated\Shared\Transfer\ItemTransfer[] $itemTransfers |
93
|
|
|
* |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
protected function countRefundedUniqItems(iterable $itemTransfers): int |
97
|
|
|
{ |
98
|
|
|
$uniqItems = []; |
99
|
|
|
$count = 0; |
100
|
|
|
|
101
|
|
|
foreach ($itemTransfers as $itemTransfer) { |
102
|
|
|
if (!in_array($itemTransfer->getIdSalesOrderItem(), $uniqItems)) { |
103
|
|
|
$uniqItems[] = $itemTransfer->getIdSalesOrderItem(); |
104
|
|
|
$count++; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $count; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths