Passed
Pull Request — dev (#9)
by Andrey
08:25 queued 04:31
created

AuthorizeAdapter::getCaptureNow()   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 2
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\Api\Adapter;
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 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...
12
use PayWithAmazon\ClientInterface;
13
use SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface;
14
use SprykerEco\Zed\AmazonPay\Business\Api\Converter\ResponseParserConverterInterface;
15
use SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToMoneyInterface;
16
17
class AuthorizeAdapter extends AbstractAdapter
18
{
19
    const AUTHORIZATION_AMOUNT = 'authorization_amount';
20
    const AUTHORIZATION_REFERENCE_ID = 'authorization_reference_id';
21
    const TRANSACTION_TIMEOUT = 'transaction_timeout';
22
    const CAPTURE_NOW = 'capture_now';
23
24
    /**
25
     * @var bool
26
     */
27
    protected $captureNow;
28
29
    /**
30
     * @var int
31
     */
32
    protected $transactionTimeout;
33
34
    /**
35
     * @param \PayWithAmazon\ClientInterface $client
36
     * @param \SprykerEco\Zed\AmazonPay\Business\Api\Converter\ResponseParserConverterInterface $converter
37
     * @param \SprykerEco\Zed\AmazonPay\Dependency\Facade\AmazonPayToMoneyInterface $moneyFacade
38
     * @param \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface $config
39
     * @param bool|null $captureNow
40
     */
41
    public function __construct(
42
        ClientInterface $client,
43
        ResponseParserConverterInterface $converter,
44
        AmazonPayToMoneyInterface $moneyFacade,
45
        AmazonPayConfigInterface $config,
46
        $captureNow = null
47
    ) {
48
        parent::__construct($client, $converter, $moneyFacade);
49
50
        $this->captureNow = $this->getCaptureNow($config, $captureNow);
51
        $this->transactionTimeout = $config->getAuthTransactionTimeout();
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
56
     *
57
     * @return \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...
58
     */
59
    public function call(AmazonpayCallTransfer $amazonpayCallTransfer)
60
    {
61
        $result = $this->client->authorize(
62
            $this->getRequestArray($amazonpayCallTransfer->getAmazonpayPayment(), $this->getAmount($amazonpayCallTransfer))
63
        );
64
65
        return $this->converter->convert($result);
66
    }
67
68
    /**
69
     * @param \SprykerEco\Shared\AmazonPay\AmazonPayConfigInterface $config
70
     * @param bool|null $captureNow
71
     *
72
     * @return bool
73
     */
74
    protected function getCaptureNow(AmazonPayConfigInterface $config, $captureNow = null)
75
    {
76
        return $captureNow ?? $config->getCaptureNow();
77
    }
78
79
    /**
80
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $amazonpayPaymentTransfer
81
     * @param float $amount
82
     *
83
     * @return array
84
     */
85
    protected function getRequestArray(AmazonpayPaymentTransfer $amazonpayPaymentTransfer, $amount)
86
    {
87
        return [
88
            static::AMAZON_ORDER_REFERENCE_ID => $amazonpayPaymentTransfer->getOrderReferenceId(),
89
            static::AUTHORIZATION_AMOUNT => $amount,
90
            static::AUTHORIZATION_REFERENCE_ID => $amazonpayPaymentTransfer
91
                    ->getAuthorizationDetails()
92
                    ->getAuthorizationReferenceId(),
93
            static::TRANSACTION_TIMEOUT => $this->transactionTimeout,
94
            static::CAPTURE_NOW => $this->captureNow,
95
        ];
96
    }
97
}
98