Passed
Push — master ( a2100c...af4f13 )
by Andrey
06:37
created

Saver::getOrderStatus()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 5
nop 1
dl 0
loc 16
rs 8.8571
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\Order;
9
10
use Generated\Shared\Transfer\AmazonpayPaymentTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayPaymentTransfer 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 Generated\Shared\Transfer\CheckoutResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutResponseTransfer 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 Generated\Shared\Transfer\QuoteTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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...
13
use Generated\Shared\Transfer\SaveOrderTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\SaveOrderTransfer 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...
14
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...
15
use SprykerEco\Shared\Amazonpay\AmazonpayConstants;
16
17
class Saver implements SaverInterface
18
{
19
20
    /**
21
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
22
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
23
     *
24
     * @return void
25
     */
26
    public function saveOrderPayment(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer)
27
    {
28
        $this->savePaymentForOrder(
29
            $quoteTransfer->getAmazonpayPayment(),
30
            $checkoutResponseTransfer->getSaveOrder()
31
        );
32
    }
33
34
    /**
35
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $paymentTransfer
36
     * @param \Generated\Shared\Transfer\SaveOrderTransfer $saveOrderTransfer
37
     *
38
     * @return \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay
39
     */
40
    protected function savePaymentForOrder(AmazonpayPaymentTransfer $paymentTransfer, SaveOrderTransfer $saveOrderTransfer)
41
    {
42
        $paymentEntity = new SpyPaymentAmazonpay();
43
        $paymentEntity->setOrderReferenceId($paymentTransfer->getOrderReferenceId());
44
        $paymentEntity->setStatus($this->getOrderStatus($paymentTransfer));
45
        $paymentEntity->setSellerOrderId($paymentTransfer->getSellerOrderId());
46
47
        $paymentEntity->setAuthorizationReferenceId(
48
            $paymentTransfer->getAuthorizationDetails()->getAuthorizationReferenceId()
49
        );
50
51
        $paymentEntity->setAmazonAuthorizationId(
52
            $paymentTransfer->getAuthorizationDetails()->getAmazonAuthorizationId()
53
        );
54
55
        $paymentEntity->setAmazonCaptureId(
56
            $paymentTransfer->getAuthorizationDetails()->getIdList()
57
        );
58
59
        $paymentEntity->setFkSalesOrder($saveOrderTransfer->getIdSalesOrder());
60
61
        $paymentEntity->setRequestId(
62
            $paymentTransfer->getResponseHeader()->getRequestId()
63
        );
64
65
        $paymentEntity->setIsSandbox($paymentTransfer->getIsSandbox());
66
        $paymentEntity->save();
67
68
        return $paymentEntity;
69
    }
70
71
    /**
72
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $paymentTransfer
73
     *
74
     * @return string
75
     */
76
    protected function getOrderStatus(AmazonpayPaymentTransfer $paymentTransfer)
77
    {
78
        if ($paymentTransfer->getAuthorizationDetails()->getIdList()) {
79
            return AmazonpayConstants::OMS_STATUS_CAPTURE_COMPLETED;
80
        }
81
82
        if ($paymentTransfer->getAuthorizationDetails()->getAuthorizationStatus()->getIsDeclined()) {
83
            return AmazonpayConstants::OMS_STATUS_AUTH_DECLINED;
84
        }
85
86
        if ($paymentTransfer->getAuthorizationDetails()->getAuthorizationStatus()->getIsPending()) {
87
            return AmazonpayConstants::OMS_STATUS_AUTH_PENDING;
88
        }
89
90
        if ($paymentTransfer->getAuthorizationDetails()->getAuthorizationStatus()->getIsOpen()) {
91
            return AmazonpayConstants::OMS_STATUS_AUTH_OPEN;
92
        }
93
    }
94
95
}
96