Completed
Pull Request — master (#3)
by Aleksey
15:31 queued 12:58
created

convertRequestTransferToArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 25
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 29
rs 9.52
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\CrefoPayApi\Business\Request\Converter;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\CrefoPayApiAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayApiAddressTransfer 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\CrefoPayApiAmountTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...efoPayApiAmountTransfer 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\CrefoPayApiBasketItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ayApiBasketItemTransfer 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\CrefoPayApiCompanyTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayApiCompanyTransfer 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 Generated\Shared\Transfer\CrefoPayApiPersonTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...efoPayApiPersonTransfer 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...
16
use Generated\Shared\Transfer\CrefoPayApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayApiRequestTransfer 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...
17
use SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestFields;
18
19
class CreateTransactionRequestConverter implements CrefoPayApiRequestConverterInterface
20
{
21
    /**
22
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
23
     *
24
     * @return array
25
     */
26
    public function convertRequestTransferToArray(CrefoPayApiRequestTransfer $requestTransfer): array
27
    {
28
        $createTransactionRequest = $requestTransfer->getCreateTransactionRequest();
29
        if ($createTransactionRequest === null) {
30
            return [];
31
        }
32
33
        return [
34
            CrefoPayApiRequestFields::API_FIELD_MERCHANT_ID => $createTransactionRequest->getMerchantID(),
35
            CrefoPayApiRequestFields::API_FIELD_STORE_ID => $createTransactionRequest->getStoreID(),
36
            CrefoPayApiRequestFields::API_FIELD_ORDER_ID => $createTransactionRequest->getOrderID(),
37
            CrefoPayApiRequestFields::API_FIELD_USER_ID => $createTransactionRequest->getUserID(),
38
            CrefoPayApiRequestFields::API_FIELD_INTEGRATION_TYPE => $createTransactionRequest->getIntegrationType(),
39
            CrefoPayApiRequestFields::API_FIELD_AUTO_CAPTURE => $createTransactionRequest->getAutoCapture(),
40
            CrefoPayApiRequestFields::API_FIELD_MERCHANT_REFERENCE => $createTransactionRequest->getMerchantReference(),
41
            CrefoPayApiRequestFields::API_FIELD_CONTEXT => $createTransactionRequest->getContext(),
42
            CrefoPayApiRequestFields::API_FIELD_USER_TYPE => $createTransactionRequest->getUserType(),
43
            CrefoPayApiRequestFields::API_FIELD_USER_RISK_CLASS => $createTransactionRequest->getUserRiskClass(),
44
            CrefoPayApiRequestFields::API_FIELD_USER_IP_ADDRESS => $createTransactionRequest->getUserIpAddress(),
45
            CrefoPayApiRequestFields::API_FIELD_COMPANY_DATA => $this->getCompanyData($createTransactionRequest->getCompanyData()),
46
            CrefoPayApiRequestFields::API_FIELD_USER_DATA => $this->getUserData($createTransactionRequest->getUserData()),
47
            CrefoPayApiRequestFields::API_FIELD_BILLING_RECIPIENT => $createTransactionRequest->getBillingRecipient(),
48
            CrefoPayApiRequestFields::API_FIELD_BILLING_ADDRESS => $this->getAddressData($createTransactionRequest->getBillingAddress()),
49
            CrefoPayApiRequestFields::API_FIELD_SHIPPING_RECIPIENT => $createTransactionRequest->getShippingRecipient(),
50
            CrefoPayApiRequestFields::API_FIELD_SHIPPING_ADDRESS => $this->getAddressData($createTransactionRequest->getShippingAddress()),
51
            CrefoPayApiRequestFields::API_FIELD_AMOUNT => $this->getAmountData($createTransactionRequest->getAmount()),
52
            CrefoPayApiRequestFields::API_FIELD_BASKET_ITEMS => $this->getBasketItemsData($createTransactionRequest->getBasketItems()),
53
            CrefoPayApiRequestFields::API_FIELD_BASKET_VALIDITY => $createTransactionRequest->getBasketValidity(),
54
            CrefoPayApiRequestFields::API_FIELD_LOCALE => $createTransactionRequest->getLocale(),
55
        ];
56
    }
57
58
    /**
59
     * @param \Generated\Shared\Transfer\CrefoPayApiCompanyTransfer|null $companyTransfer
60
     *
61
     * @return array|null
62
     */
63
    protected function getCompanyData(?CrefoPayApiCompanyTransfer $companyTransfer): ?array
64
    {
65
        return $companyTransfer ? $this->convertCompanyTransferToArray($companyTransfer) : null;
66
    }
67
68
    /**
69
     * @param \Generated\Shared\Transfer\CrefoPayApiPersonTransfer|null $personTransfer
70
     *
71
     * @return array|null
72
     */
73
    protected function getUserData(?CrefoPayApiPersonTransfer $personTransfer): ?array
74
    {
75
        return $personTransfer ? $this->convertPersonTransferToArray($personTransfer) : null;
76
    }
77
78
    /**
79
     * @param \Generated\Shared\Transfer\CrefoPayApiAddressTransfer|null $addressTransfer
80
     *
81
     * @return array|null
82
     */
83
    protected function getAddressData(?CrefoPayApiAddressTransfer $addressTransfer): ?array
84
    {
85
        return $addressTransfer ? $this->convertAddressTransferToArray($addressTransfer) : null;
86
    }
87
88
    /**
89
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer|null $amountTransfer
90
     *
91
     * @return array|null
92
     */
93
    protected function getAmountData(?CrefoPayApiAmountTransfer $amountTransfer): ?array
94
    {
95
        return $amountTransfer ? $this->convertAmountTransferToArray($amountTransfer) : null;
96
    }
97
98
    /**
99
     * @param \ArrayObject|\Generated\Shared\Transfer\CrefoPayApiBasketItemTransfer[] $basketItems
100
     *
101
     * @return array|null
102
     */
103
    protected function getBasketItemsData(ArrayObject $basketItems): ?array
104
    {
105
        if ($basketItems->count() === 0) {
106
            return null;
107
        }
108
109
        return array_map(
110
            function (CrefoPayApiBasketItemTransfer $basketItem) {
111
                return $this->convertBasketItemTransferToArray($basketItem);
112
            },
113
            $basketItems->getArrayCopy()
114
        );
115
    }
116
117
    /**
118
     * @param \Generated\Shared\Transfer\CrefoPayApiBasketItemTransfer $basketItem
119
     *
120
     * @return array
121
     */
122
    protected function convertBasketItemTransferToArray(CrefoPayApiBasketItemTransfer $basketItem): array
123
    {
124
        return [
125
            CrefoPayApiRequestFields::API_OBJECT_BASKET_ITEM_FIELD_TEXT => $basketItem->getBasketItemText(),
126
            CrefoPayApiRequestFields::API_OBJECT_BASKET_ITEM_FIELD_ID => $basketItem->getBasketItemID(),
127
            CrefoPayApiRequestFields::API_OBJECT_BASKET_ITEM_FIELD_COUNT => $basketItem->getBasketItemCount(),
128
            CrefoPayApiRequestFields::API_OBJECT_BASKET_ITEM_FIELD_AMOUNT => $this->getAmountData($basketItem->getBasketItemAmount()),
129
            CrefoPayApiRequestFields::API_OBJECT_BASKET_ITEM_FIELD_RISK_CLASS => $basketItem->getBasketItemRiskClass(),
130
            CrefoPayApiRequestFields::API_OBJECT_BASKET_ITEM_FIELD_TYPE => $basketItem->getBasketItemType(),
131
        ];
132
    }
133
134
    /**
135
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer $amountTransfer
136
     *
137
     * @return array
138
     */
139
    protected function convertAmountTransferToArray(CrefoPayApiAmountTransfer $amountTransfer): array
140
    {
141
        return [
142
            CrefoPayApiRequestFields::API_OBJECT_AMOUNT_FIELD_AMOUNT => $amountTransfer->getAmount(),
143
            CrefoPayApiRequestFields::API_OBJECT_AMOUNT_FIELD_VAT_AMOUNT => $amountTransfer->getVatAmount(),
144
            CrefoPayApiRequestFields::API_OBJECT_AMOUNT_FIELD_VAT_RATE => $amountTransfer->getVatRate(),
145
        ];
146
    }
147
148
    /**
149
     * @param \Generated\Shared\Transfer\CrefoPayApiCompanyTransfer $companyTransfer
150
     *
151
     * @return array
152
     */
153
    protected function convertCompanyTransferToArray(CrefoPayApiCompanyTransfer $companyTransfer): array
154
    {
155
        return [
156
            CrefoPayApiRequestFields::API_OBJECT_COMPANY_FIELD_NAME => $companyTransfer->getCompanyName(),
157
            CrefoPayApiRequestFields::API_OBJECT_COMPANY_FIELD_EMAIL => $companyTransfer->getEmail(),
158
            CrefoPayApiRequestFields::API_OBJECT_COMPANY_FIELD_REGISTER_TYPE => $companyTransfer->getCompanyRegisterType(),
159
            CrefoPayApiRequestFields::API_OBJECT_COMPANY_FIELD_REGISTRATION_ID => $companyTransfer->getCompanyRegistrationID(),
160
            CrefoPayApiRequestFields::API_OBJECT_COMPANY_FIELD_VAT_ID => $companyTransfer->getCompanyVatID(),
161
            CrefoPayApiRequestFields::API_OBJECT_COMPANY_FIELD_TAX_ID => $companyTransfer->getCompanyTaxID(),
162
        ];
163
    }
164
165
    /**
166
     * @param \Generated\Shared\Transfer\CrefoPayApiPersonTransfer $personTransfer
167
     *
168
     * @return array
169
     */
170
    protected function convertPersonTransferToArray(CrefoPayApiPersonTransfer $personTransfer): array
171
    {
172
        return [
173
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_SALUTATION => $personTransfer->getSalutation(),
174
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_NAME => $personTransfer->getName(),
175
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_SURNAME => $personTransfer->getSurname(),
176
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_DATE_OF_BIRTH => $personTransfer->getDateOfBirth(),
177
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_EMAIL => $personTransfer->getEmail(),
178
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_PHONE_NUMBER => $personTransfer->getPhoneNumber(),
179
            CrefoPayApiRequestFields::API_OBJECT_PERSON_FIELD_FAX_NUMBER => $personTransfer->getFaxNumber(),
180
        ];
181
    }
182
183
    /**
184
     * @param \Generated\Shared\Transfer\CrefoPayApiAddressTransfer $addressTransfer
185
     *
186
     * @return array
187
     */
188
    protected function convertAddressTransferToArray(CrefoPayApiAddressTransfer $addressTransfer): array
189
    {
190
        return [
191
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_STREET => $addressTransfer->getStreet(),
192
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_HOUSE_NUMBER => $addressTransfer->getNo(),
193
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_ADDITIONAL => $addressTransfer->getAdditional(),
194
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_ZIP => $addressTransfer->getZip(),
195
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_CITY => $addressTransfer->getCity(),
196
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_STATE => $addressTransfer->getState(),
197
            CrefoPayApiRequestFields::API_OBJECT_ADDRESS_FIELD_COUNTRY => $addressTransfer->getCountry(),
198
        ];
199
    }
200
}
201