Completed
Pull Request — dev (#11)
by Aleksey
10:59 queued 05:13
created

getFullRefundTransactionLogEntry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\AfterPay\Persist...tAfterPayTransactionLog 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 Orm\Zed\Sales\Persistence\SpySalesOrderItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItem 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 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
     * @api
28
     *
29
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
30
     *
31
     * @return bool
32
     */
33
    public function check(SpySalesOrderItem $orderItem): bool
34
    {
35
        return $this->isRefundTransactionSuccessful($orderItem->getFkSalesOrder());
36
    }
37
38
    /**
39
     * @param int $idSalesOrder
40
     *
41
     * @return bool
42
     */
43
    protected function isRefundTransactionSuccessful(int $idSalesOrder): bool
44
    {
45
        $order = $this->getQueryContainer()->querySalesOrder($idSalesOrder)->findOne();
46
        if ($order === null) {
47
            return false;
48
        }
49
50
        $captureTransactionLog = $this->getFullRefundTransactionLogEntry($order->getOrderReference());
51
        if ($captureTransactionLog === null) {
52
            return false;
53
        }
54
55
        return $this->isTransactionSuccessful($captureTransactionLog);
56
    }
57
58
    /**
59
     * @param string $orderReference
60
     *
61
     * @return \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog|null
62
     */
63
    protected function getFullRefundTransactionLogEntry(string $orderReference): ?SpyPaymentAfterPayTransactionLog
64
    {
65
        $transactionLogQuery = $this->getQueryContainer()->queryRefundTransactionLog($orderReference);
66
67
        return $transactionLogQuery->findOne();
68
    }
69
70
    /**
71
     * @param \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog $refundTransactionLog
72
     *
73
     * @return bool
74
     */
75
    protected function isTransactionSuccessful(SpyPaymentAfterPayTransactionLog $refundTransactionLog): bool
76
    {
77
        return $refundTransactionLog->getOutcome() === static::REFUND_TRANSACTION_ACCEPTED;
78
    }
79
}
80