TwoStepsAuthorizeRequestBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A buildAuthorizeRequest() 0 9 1
A addPaymentDetails() 0 10 1
A addCheckoutId() 0 6 1
A addOrderNumber() 0 8 1
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\Business\Payment\Transaction\Authorize\RequestBuilder;
9
10
use Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...uthorizeRequestTransfer 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\AfterPayCallTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AfterPayCallTransfer 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\AfterPayRequestOrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PayRequestOrderTransfer 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\AfterPayRequestPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yRequestPaymentTransfer 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 Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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\AfterPay\AfterPayConfig;
16
use SprykerEco\Zed\AfterPay\Business\Payment\Mapper\OrderToRequestTransferInterface;
17
18
class TwoStepsAuthorizeRequestBuilder implements AuthorizeRequestBuilderInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    protected static $paymentMethods = [
24
        AfterPayConfig::PAYMENT_METHOD_INVOICE => AfterPayConfig::PAYMENT_TYPE_INVOICE,
25
    ];
26
27
    /**
28
     * @var \SprykerEco\Zed\AfterPay\Business\Payment\Mapper\OrderToRequestTransferInterface
29
     */
30
    protected $orderToRequestMapper;
31
32
    /**
33
     * @param \SprykerEco\Zed\AfterPay\Business\Payment\Mapper\OrderToRequestTransferInterface $orderToRequestMapper
34
     */
35
    public function __construct(OrderToRequestTransferInterface $orderToRequestMapper)
36
    {
37
        $this->orderToRequestMapper = $orderToRequestMapper;
38
    }
39
40
    /**
41
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $orderWithPaymentTransfer
42
     *
43
     * @return \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer
44
     */
45
    public function buildAuthorizeRequest(AfterPayCallTransfer $orderWithPaymentTransfer): AfterPayAuthorizeRequestTransfer
46
    {
47
        $authorizeRequestTransfer = $this
48
            ->orderToRequestMapper
49
            ->orderToAuthorizeRequest($orderWithPaymentTransfer);
50
51
        $authorizeRequestTransfer->setCheckoutId($orderWithPaymentTransfer->getCheckoutId());
52
53
        return $authorizeRequestTransfer;
54
    }
55
56
    /**
57
     * @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer
58
     * @param \Generated\Shared\Transfer\OrderTransfer $orderWithPaymentTransfer
59
     *
60
     * @return void
61
     */
62
    protected function addOrderNumber(
63
        AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer,
64
        OrderTransfer $orderWithPaymentTransfer
65
    ): void {
66
        $requestOrderTransfer = (new AfterPayRequestOrderTransfer())
67
            ->setNumber($orderWithPaymentTransfer->getOrderReference());
68
69
        $authorizeRequestTransfer->setOrder($requestOrderTransfer);
70
    }
71
72
    /**
73
     * @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer
74
     * @param \Generated\Shared\Transfer\OrderTransfer $orderWithPaymentTransfer
75
     *
76
     * @return void
77
     */
78
    protected function addCheckoutId(
79
        AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer,
80
        OrderTransfer $orderWithPaymentTransfer
81
    ): void {
82
        $checkoutId = $orderWithPaymentTransfer->getAfterPayPayment()->getIdCheckout();
83
        $authorizeRequestTransfer->setCheckoutId($checkoutId);
84
    }
85
86
    /**
87
     * @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer
88
     * @param \Generated\Shared\Transfer\OrderTransfer $orderWithPaymentTransfer
89
     *
90
     * @return void
91
     */
92
    protected function addPaymentDetails(
93
        AfterPayAuthorizeRequestTransfer $authorizeRequestTransfer,
94
        OrderTransfer $orderWithPaymentTransfer
95
    ): void {
96
        $paymentMethod = $orderWithPaymentTransfer->getAfterPayPayment()->getPaymentMethod();
97
98
        $requestPaymentTransfer = (new AfterPayRequestPaymentTransfer())
99
            ->setType(static::$paymentMethods[$paymentMethod]);
100
101
        $authorizeRequestTransfer->setPayment($requestPaymentTransfer);
102
    }
103
}
104