|
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\Communication\Plugin\Checkout\Oms\Condition; |
|
9
|
|
|
|
|
10
|
|
|
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLog; |
|
11
|
|
|
use Orm\Zed\Sales\Persistence\SpySalesOrderItem; |
|
12
|
|
|
use Spryker\Zed\Kernel\Communication\AbstractPlugin; |
|
13
|
|
|
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface; |
|
14
|
|
|
use SprykerEco\Shared\Heidelpay\HeidelpayConfig; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @method \SprykerEco\Zed\Heidelpay\Business\HeidelpayFacadeInterface getFacade() |
|
18
|
|
|
* @method \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayQueryContainerInterface getQueryContainer() |
|
19
|
|
|
* @method \SprykerEco\Zed\Heidelpay\Communication\HeidelpayCommunicationFactory getFactory() |
|
20
|
|
|
* @method \SprykerEco\Zed\Heidelpay\HeidelpayConfig getConfig() |
|
21
|
|
|
*/ |
|
22
|
|
|
class IsDebitCompletedPlugin extends AbstractPlugin implements ConditionInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
* - Checks if Debit transaction was successful. |
|
27
|
|
|
* |
|
28
|
|
|
* @api |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem |
|
31
|
|
|
* |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
public function check(SpySalesOrderItem $orderItem): bool |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->hasCustomerCompletedDebit($orderItem->getFkSalesOrder()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param int $idSalesOrder |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function hasCustomerCompletedDebit(int $idSalesOrder): bool |
|
45
|
|
|
{ |
|
46
|
|
|
$externalTransactionLog = $this->getExternalTransactionLogEntry($idSalesOrder); |
|
47
|
|
|
if ($externalTransactionLog === null) { |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this->isTransactionSuccessful($externalTransactionLog); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param int $idSalesOrder |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLog|null |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getExternalTransactionLogEntry(int $idSalesOrder): ?SpyPaymentHeidelpayTransactionLog |
|
60
|
|
|
{ |
|
61
|
|
|
$transactionLogQuery = $this->getQueryContainer()->queryExternalResponseTransactionLog($idSalesOrder); |
|
62
|
|
|
|
|
63
|
|
|
return $transactionLogQuery->findOne(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLog $externalTransactionLog |
|
68
|
|
|
* |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function isTransactionSuccessful(SpyPaymentHeidelpayTransactionLog $externalTransactionLog): bool |
|
72
|
|
|
{ |
|
73
|
|
|
return $externalTransactionLog->getResponseCode() === HeidelpayConfig::EXTERNAL_RESPONSE_TRANSACTION_STATUS_OK; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|