Completed
Pull Request — master (#25)
by Andrey
11:08 queued 03:02
created

Placement::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
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\Order;
9
10
use Generated\Shared\Transfer\AmazonpayPaymentTransfer;
11
use Generated\Shared\Transfer\CheckoutErrorTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutErrorTransfer 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\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...
13
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...
14
use SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\TransactionCollectionInterface;
15
16
class Placement implements PlacementInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\TransactionCollectionInterface
20
     */
21
    protected $confirmationTransactionCollection;
22
23
    /**
24
     * @param \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\TransactionCollectionInterface $confirmationTransactionCollection
25
     */
26
    public function __construct(
27
        TransactionCollectionInterface $confirmationTransactionCollection
28
    ) {
29
        $this->confirmationTransactionCollection = $confirmationTransactionCollection;
30
    }
31
32
    /**
33
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
34
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
35
     *
36
     * @return bool
37
     */
38
    public function placeOrder(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer)
39
    {
40
        if ($quoteTransfer->getAmazonpayPayment() === null) {
41
            return true;
42
        }
43
44
        $this->confirmationTransactionCollection->execute($quoteTransfer);
45
46
        if ($quoteTransfer->getAmazonpayPayment()->getResponseHeader()->getIsSuccess()) {
47
            return true;
48
        }
49
50
        $checkoutResponseTransfer->setIsSuccess(false);
51
        $checkoutResponseTransfer->addError(
52
            $this->createCheckoutErrorFromAmazonPaymentResponse(
53
                $quoteTransfer->getAmazonpayPayment()
54
            )
55
        );
56
57
        return false;
58
    }
59
60
    /**
61
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $amazonpayPaymentTransfer
62
     *
63
     * @return \Generated\Shared\Transfer\CheckoutErrorTransfer
64
     */
65
    protected function createCheckoutErrorFromAmazonPaymentResponse(AmazonpayPaymentTransfer $amazonpayPaymentTransfer)
66
    {
67
        $checkoutErrorTransfer = new CheckoutErrorTransfer();
68
        $checkoutErrorTransfer->setMessage($amazonpayPaymentTransfer->getResponseHeader()->getErrorMessage());
69
70
        return $checkoutErrorTransfer;
71
    }
72
}
73