|
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\AfterPay\Communication\Plugin\Oms\Condition; |
|
9
|
|
|
|
|
10
|
|
|
use Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog; |
|
|
|
|
|
|
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\AfterPay\AfterPayConfig; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @method \SprykerEco\Zed\AfterPay\Business\AfterPayFacadeInterface getFacade() |
|
18
|
|
|
* @method \SprykerEco\Zed\AfterPay\Persistence\AfterPayQueryContainerInterface getQueryContainer() |
|
19
|
|
|
* @method \SprykerEco\Zed\AfterPay\Communication\AfterPayCommunicationFactory getFactory() |
|
20
|
|
|
* @method \SprykerEco\Zed\AfterPay\AfterPayConfig getConfig() |
|
21
|
|
|
*/ |
|
22
|
|
|
class IsRefundCompletedPlugin extends AbstractPlugin implements ConditionInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public const REFUND_TRANSACTION_ACCEPTED = AfterPayConfig::API_TRANSACTION_OUTCOME_ACCEPTED; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritDoc} |
|
28
|
|
|
* - Checks if the `refund` operation was successfully accepted for the order. |
|
29
|
|
|
* |
|
30
|
|
|
* @api |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem |
|
33
|
|
|
* |
|
34
|
|
|
* @return bool |
|
35
|
|
|
*/ |
|
36
|
|
|
public function check(SpySalesOrderItem $orderItem): bool |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->isRefundTransactionSuccessful($orderItem->getFkSalesOrder()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param int $idSalesOrder |
|
43
|
|
|
* |
|
44
|
|
|
* @return bool |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function isRefundTransactionSuccessful(int $idSalesOrder): bool |
|
47
|
|
|
{ |
|
48
|
|
|
$order = $this->getQueryContainer()->querySalesOrder($idSalesOrder)->findOne(); |
|
49
|
|
|
if ($order === null) { |
|
50
|
|
|
return false; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$captureTransactionLog = $this->getFullRefundTransactionLogEntry($order->getOrderReference()); |
|
54
|
|
|
if ($captureTransactionLog === null) { |
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->isTransactionSuccessful($captureTransactionLog); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $orderReference |
|
63
|
|
|
* |
|
64
|
|
|
* @return \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog|null |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getFullRefundTransactionLogEntry(string $orderReference): ?SpyPaymentAfterPayTransactionLog |
|
67
|
|
|
{ |
|
68
|
|
|
$transactionLogQuery = $this->getQueryContainer()->queryRefundTransactionLog($orderReference); |
|
69
|
|
|
|
|
70
|
|
|
return $transactionLogQuery->findOne(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog $refundTransactionLog |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function isTransactionSuccessful(SpyPaymentAfterPayTransactionLog $refundTransactionLog): bool |
|
79
|
|
|
{ |
|
80
|
|
|
return $refundTransactionLog->getOutcome() === static::REFUND_TRANSACTION_ACCEPTED; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
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