|
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\Heidelpay\Business\Payment\Transaction\Handler; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\OrderTransfer; |
|
|
|
|
|
|
11
|
|
|
use SprykerEco\Zed\Heidelpay\Business\Payment\Request\AdapterRequestFromOrderBuilderInterface; |
|
12
|
|
|
use SprykerEco\Zed\Heidelpay\Business\Payment\Transaction\Exception\RefundNotSupportedException; |
|
13
|
|
|
use SprykerEco\Zed\Heidelpay\Business\Payment\Transaction\RefundTransactionInterface; |
|
14
|
|
|
use SprykerEco\Zed\Heidelpay\Business\Payment\Type\PaymentWithRefundInterface; |
|
15
|
|
|
|
|
16
|
|
|
class RefundTransactionHandler implements RefundTransactionHandlerInterface |
|
17
|
|
|
{ |
|
18
|
|
|
public const ERROR_MESSAGE_REFUND_TRANSACTION_NOT_SUPPORTED = |
|
19
|
|
|
'Attempt to call refund transaction on payment method \'%s\' ' . |
|
20
|
|
|
'that does not support it'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \SprykerEco\Zed\Heidelpay\Business\Payment\Transaction\RefundTransactionInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $transaction; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \SprykerEco\Zed\Heidelpay\Business\Payment\Type\PaymentWithRefundInterface[] |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $paymentMethodAdapterCollection; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var \SprykerEco\Zed\Heidelpay\Business\Payment\Request\AdapterRequestFromOrderBuilderInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $heidelpayRequestBuilder; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param \SprykerEco\Zed\Heidelpay\Business\Payment\Transaction\RefundTransactionInterface $transaction |
|
39
|
|
|
* @param \SprykerEco\Zed\Heidelpay\Business\Payment\Type\PaymentWithRefundInterface[] $paymentMethodAdapterCollection |
|
40
|
|
|
* @param \SprykerEco\Zed\Heidelpay\Business\Payment\Request\AdapterRequestFromOrderBuilderInterface $heidelpayRequestBuilder |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct( |
|
43
|
|
|
RefundTransactionInterface $transaction, |
|
44
|
|
|
array $paymentMethodAdapterCollection, |
|
45
|
|
|
AdapterRequestFromOrderBuilderInterface $heidelpayRequestBuilder |
|
46
|
|
|
) { |
|
47
|
|
|
$this->transaction = $transaction; |
|
48
|
|
|
$this->paymentMethodAdapterCollection = $paymentMethodAdapterCollection; |
|
49
|
|
|
$this->heidelpayRequestBuilder = $heidelpayRequestBuilder; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
|
54
|
|
|
* |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
public function executeRefund(OrderTransfer $orderTransfer): void |
|
58
|
|
|
{ |
|
59
|
|
|
$refundRequestTransfer = $this->heidelpayRequestBuilder->buildRefundRequestFromOrder($orderTransfer); |
|
60
|
|
|
$paymentAdapter = $this->getPaymentMethodAdapter($orderTransfer); |
|
61
|
|
|
$this->transaction->executeTransaction($refundRequestTransfer, $paymentAdapter); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
|
66
|
|
|
* |
|
67
|
|
|
* @throws \SprykerEco\Zed\Heidelpay\Business\Payment\Transaction\Exception\RefundNotSupportedException |
|
68
|
|
|
* |
|
69
|
|
|
* @return \SprykerEco\Zed\Heidelpay\Business\Payment\Type\PaymentWithRefundInterface |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getPaymentMethodAdapter(OrderTransfer $orderTransfer): PaymentWithRefundInterface |
|
72
|
|
|
{ |
|
73
|
|
|
$paymentMethodCode = $orderTransfer->getHeidelpayPayment()->getPaymentMethod(); |
|
74
|
|
|
|
|
75
|
|
|
if (!isset($this->paymentMethodAdapterCollection[$paymentMethodCode])) { |
|
76
|
|
|
throw new RefundNotSupportedException( |
|
77
|
|
|
sprintf(static::ERROR_MESSAGE_REFUND_TRANSACTION_NOT_SUPPORTED, $paymentMethodCode) |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->paymentMethodAdapterCollection[$paymentMethodCode]; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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