Passed
Pull Request — dev (#9)
by Andrey
07:08 queued 03:30
created

allowPartialProcessing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction;
9
10
use Generated\Shared\Transfer\AmazonpayCallTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayCallTransfer 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\AmazonPay\Persistence\SpyPaymentAmazonpay;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay 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 SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface;
13
use SprykerEco\Zed\AmazonPay\Business\Api\Adapter\CallAdapterInterface;
14
use SprykerEco\Zed\AmazonPay\Business\Order\PaymentProcessorInterface;
15
use SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface;
16
17
abstract class AbstractAmazonpayTransaction extends AbstractTransaction implements AmazonpayTransactionInterface
18
{
19
    /**
20
     * @var \Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay
21
     */
22
    protected $paymentEntity;
23
24
    /**
25
     * @var \Generated\Shared\Transfer\AmazonpayResponseTransfer
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...azonpayResponseTransfer 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...
26
     */
27
    protected $apiResponse;
28
29
    /**
30
     * @var \SprykerEco\Zed\AmazonPay\Business\Order\PaymentProcessorInterface
31
     */
32
    protected $paymentProcessor;
33
34
    /**
35
     * @param \SprykerEco\Zed\AmazonPay\Business\Api\Adapter\CallAdapterInterface $executionAdapter
36
     * @param \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface $config
37
     * @param \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface $transactionLogger
38
     * @param \SprykerEco\Zed\AmazonPay\Business\Order\PaymentProcessorInterface $paymentProcessor
39
     */
40
    public function __construct(
41
        CallAdapterInterface $executionAdapter,
42
        AmazonPayConfigInterface $config,
43
        TransactionLoggerInterface $transactionLogger,
44
        PaymentProcessorInterface $paymentProcessor
45
    ) {
46
        parent::__construct($executionAdapter, $config, $transactionLogger);
47
48
        $this->paymentProcessor = $paymentProcessor;
49
    }
50
51
    /**
52
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
53
     *
54
     * @return string
55
     */
56
    protected function generateOperationReferenceId(AmazonpayCallTransfer $amazonPayCallTransfer)
57
    {
58
        return uniqid($amazonPayCallTransfer->getAmazonpayPayment()->getOrderReferenceId(), false);
59
    }
60
61
    /**
62
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
63
     *
64
     * @return \Generated\Shared\Transfer\AmazonpayCallTransfer
65
     */
66
    public function execute(AmazonpayCallTransfer $amazonPayCallTransfer)
67
    {
68
        $this->apiResponse = $this->executionAdapter->call($amazonPayCallTransfer);
69
70
        $amazonPayCallTransfer->getAmazonpayPayment()
71
            ->fromArray($this->apiResponse->modifiedToArray(), true);
72
73
        $this->transactionsLogger->log(
74
            $amazonPayCallTransfer->getAmazonpayPayment()
75
        );
76
        $this->paymentEntity = $this->paymentProcessor->loadPaymentEntity($amazonPayCallTransfer);
77
78
        return $amazonPayCallTransfer;
79
    }
80
81
    /**
82
     * @param \Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay $paymentAmazonPayEntity
83
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
84
     *
85
     * @return bool
86
     */
87
    protected function isPartialProcessing(SpyPaymentAmazonpay $paymentAmazonPayEntity, AmazonpayCallTransfer $amazonPayCallTransfer)
88
    {
89
        return $this->allowPartialProcessing()
90
            && $amazonPayCallTransfer->getItems()->count()
91
                !== $paymentAmazonPayEntity->getSpyPaymentAmazonpaySalesOrderItems()->count();
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    protected function allowPartialProcessing()
98
    {
99
        return true;
100
    }
101
102
    /**
103
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
104
     *
105
     * @return bool
106
     */
107
    protected function isPaymentSuccess(AmazonpayCallTransfer $amazonPayCallTransfer)
108
    {
109
        return $amazonPayCallTransfer->getAmazonpayPayment()
110
            && $amazonPayCallTransfer->getAmazonpayPayment()->getResponseHeader()
111
            && $amazonPayCallTransfer->getAmazonpayPayment()->getResponseHeader()->getIsSuccess();
112
    }
113
}
114