EasycreditMapper   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 215
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 102
c 1
b 0
f 0
dl 0
loc 215
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A mapOrderConfirmationRequest() 0 6 1
A mapQueryCreditAssessmentRequest() 0 9 3
A mapApprovalTextRequest() 0 3 1
A __construct() 0 6 1
A prepareOrderItems() 0 13 2
A mapInterestAndTotalSumRequest() 0 6 1
A mapPreContractualInformationAndRedemptionPlanRequest() 0 6 1
A mapInitializePaymentRequest() 0 54 3
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\Easycredit\Business\Mapper;
9
10
use Generated\Shared\Transfer\EasycreditRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...sycreditRequestTransfer 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\PaymentEasycreditOrderIdentifierTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...OrderIdentifierTransfer 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;
0 ignored issues
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 Spryker\Shared\Money\Dependency\Plugin\MoneyPluginInterface;
14
use SprykerEco\Zed\Easycredit\EasycreditConfig;
15
16
class EasycreditMapper implements MapperInterface
17
{
18
    public const KEY_PERSONEN_DATEN = 'personendaten';
19
    public const KEY_RECHNUNGS_ADRESSE = 'rechnungsadresse';
20
    public const KEY_WEITERE_KAEUFER_ANGABEN = 'weitereKaeuferangaben';
21
    public const KEY_RUECK_SPRUNG_ADRESSEN = 'ruecksprungadressen';
22
    public const KEY_LIEFER_ADRESSE = 'lieferadresse';
23
    public const KEY_KONTAKT = 'kontakt';
24
    public const KEY_RISIKORELEVANTE_ANGABEN = 'risikorelevanteAngaben';
25
    public const KEY_WARENKORBINFOS = 'warenkorbinfos';
26
27
    public const KEY_SHOP_KENNUNG = 'shopKennung';
28
    public const KEY_BESTELL_WERT = 'bestellwert';
29
    public const KEY_INTEGRATIONS_ART = 'integrationsart';
30
31
    public const KEY_ANREDE = 'anrede';
32
    public const KEY_VORNAME = 'vorname';
33
    public const KEY_NACHNAME = 'nachname';
34
    public const KEY_GEBURTS_DATUM = 'geburtsdatum';
35
36
    public const KEY_STRASSE_HAUS_NR = 'strasseHausNr';
37
    public const KEY_PLZ = 'plz';
38
    public const KEY_ORT = 'ort';
39
    public const KEY_LAND = 'land';
40
41
    public const KEY_TELEFON_NUMMER = 'telefonnummer';
42
    public const KEY_TITEL = 'titel';
43
    public const KEY_GEBURTSNAME = 'geburtsname';
44
    public const KEY_GEBURTSORT = 'geburtsort';
45
46
    public const KEY_EMAIL = 'email';
47
48
    public const KEY_URL_ERFOLG = 'urlErfolg';
49
    public const KEY_URL_ABBRUCH = 'urlAbbruch';
50
    public const KEY_URL_ABLEHNUNG = 'urlAblehnung';
51
52
    public const KEY_BESTELLUNG_ERFOLGT_UEBER_LOGIN = 'bestellungErfolgtUeberLogin';
53
    public const KEY_LOGISTIK_DIENSTLEISTER = 'logistikDienstleister';
54
55
    public const KEY_MENGE = 'menge';
56
    public const KEY_PREIS = 'preis';
57
    public const KEY_PRODUKTBEZEICHNUNG = 'produktbezeichnung';
58
59
    protected const SALUTATION_MAPPER = [
60
        'Mr' => 'HERR',
61
        'Mrs' => 'FRAU',
62
        'Dr' => 'HERR',
63
        'Ms' => 'FRAU',
64
    ];
65
66
    /**
67
     * @var \SprykerEco\Zed\Easycredit\EasycreditConfig
68
     */
69
    protected $config;
70
71
    /**
72
     * @var \Spryker\Shared\Money\Dependency\Plugin\MoneyPluginInterface
73
     */
74
    protected $moneyPlugin;
75
76
    /**
77
     * @param \SprykerEco\Zed\Easycredit\EasycreditConfig $config
78
     * @param \Spryker\Shared\Money\Dependency\Plugin\MoneyPluginInterface $moneyPlugin
79
     */
80
    public function __construct(
81
        EasycreditConfig $config,
82
        MoneyPluginInterface $moneyPlugin
83
    ) {
84
        $this->config = $config;
85
        $this->moneyPlugin = $moneyPlugin;
86
    }
87
88
    /**
89
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
90
     *
91
     * @return \Generated\Shared\Transfer\EasycreditRequestTransfer
92
     */
93
    public function mapInitializePaymentRequest(QuoteTransfer $quoteTransfer): EasycreditRequestTransfer
94
    {
95
        $payload = [
96
            static::KEY_SHOP_KENNUNG => $this->config->getShopIdentifier(),
97
            static::KEY_BESTELL_WERT => $this->moneyPlugin->convertIntegerToDecimal($quoteTransfer->getTotals()->getGrandTotal()),
98
            static::KEY_INTEGRATIONS_ART => $this->config->getPaymentPageIntegrationType(),
99
            static::KEY_PERSONEN_DATEN => [
100
                static::KEY_ANREDE => static::SALUTATION_MAPPER[$quoteTransfer->getCustomer()->getSalutation()],
101
                static::KEY_VORNAME => $quoteTransfer->getShippingAddress()->getFirstName(),
102
                static::KEY_NACHNAME => $quoteTransfer->getShippingAddress()->getLastName(),
103
                static::KEY_GEBURTS_DATUM => '',
104
            ],
105
            static::KEY_RECHNUNGS_ADRESSE => [
106
                static::KEY_STRASSE_HAUS_NR => $quoteTransfer->getBillingAddress()->getAddress1() . $quoteTransfer->getBillingAddress()->getAddress2(),
107
                static::KEY_PLZ => $quoteTransfer->getBillingAddress()->getZipCode(),
108
                static::KEY_ORT => $quoteTransfer->getBillingAddress()->getCity(),
109
                static::KEY_LAND => $quoteTransfer->getBillingAddress()->getIso2Code(),
110
            ],
111
            static::KEY_LIEFER_ADRESSE => [
112
                static::KEY_VORNAME => $quoteTransfer->getShippingAddress()->getFirstName(),
113
                static::KEY_NACHNAME => $quoteTransfer->getShippingAddress()->getLastName(),
114
                static::KEY_STRASSE_HAUS_NR => $quoteTransfer->getShippingAddress()->getAddress1() . $quoteTransfer->getShippingAddress()->getAddress2(),
115
                static::KEY_PLZ => $quoteTransfer->getShippingAddress()->getZipCode(),
116
                static::KEY_ORT => $quoteTransfer->getShippingAddress()->getCity(),
117
                static::KEY_LAND => $quoteTransfer->getShippingAddress()->getIso2Code(),
118
            ],
119
            static::KEY_WEITERE_KAEUFER_ANGABEN => [
120
                static::KEY_TELEFON_NUMMER => $quoteTransfer->getCustomer()->getPhone(),
121
                static::KEY_GEBURTSNAME => $quoteTransfer->getCustomer()->getFirstName(),
122
            ],
123
            static::KEY_RUECK_SPRUNG_ADRESSEN => [
124
                static::KEY_URL_ERFOLG => $this->config->getSuccessUrl(),
125
                static::KEY_URL_ABBRUCH => $this->config->getCancelledUrl(),
126
                static::KEY_URL_ABLEHNUNG => $this->config->getDeniedUrl(),
127
            ],
128
            static::KEY_KONTAKT => [
129
                static::KEY_EMAIL => $quoteTransfer->getCustomer()->getEmail(),
130
            ],
131
            static::KEY_RISIKORELEVANTE_ANGABEN => [
132
                static::KEY_BESTELLUNG_ERFOLGT_UEBER_LOGIN => false,
133
                static::KEY_LOGISTIK_DIENSTLEISTER => $quoteTransfer->getShipment()->getShipmentSelection(),
134
            ],
135
        ];
136
137
        $payload[static::KEY_WARENKORBINFOS] = $this->prepareOrderItems($quoteTransfer);
138
139
        $requestTransfer = new EasycreditRequestTransfer();
140
        $requestTransfer->setPayload($payload);
141
142
        if ($quoteTransfer->getPayment() && $quoteTransfer->getPayment()->getEasycredit()) {
143
            $requestTransfer->setVorgangskennung($quoteTransfer->getPayment()->getEasycredit()->getVorgangskennung());
144
        }
145
146
        return $requestTransfer;
147
    }
148
149
    /**
150
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
151
     *
152
     * @return \Generated\Shared\Transfer\EasycreditRequestTransfer
153
     */
154
    public function mapPreContractualInformationAndRedemptionPlanRequest(QuoteTransfer $quoteTransfer): EasycreditRequestTransfer
155
    {
156
        $requestTransfer = new EasycreditRequestTransfer();
157
        $requestTransfer->setVorgangskennung($quoteTransfer->getPayment()->getEasycredit()->getVorgangskennung());
158
159
        return $requestTransfer;
160
    }
161
162
    /**
163
     * @param int $fkSalesOrder
164
     * @param \Generated\Shared\Transfer\PaymentEasycreditOrderIdentifierTransfer $paymentEasycreditOrderIdentifierTransfer
165
     *
166
     * @return \Generated\Shared\Transfer\EasycreditRequestTransfer
167
     */
168
    public function mapOrderConfirmationRequest(int $fkSalesOrder, PaymentEasycreditOrderIdentifierTransfer $paymentEasycreditOrderIdentifierTransfer): EasycreditRequestTransfer
169
    {
170
        $requestTransfer = new EasycreditRequestTransfer();
171
        $requestTransfer->setVorgangskennung($paymentEasycreditOrderIdentifierTransfer->getIdentifier());
172
173
        return $requestTransfer;
174
    }
175
176
    /**
177
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
178
     *
179
     * @return \Generated\Shared\Transfer\EasycreditRequestTransfer
180
     */
181
    public function mapInterestAndTotalSumRequest(QuoteTransfer $quoteTransfer): EasycreditRequestTransfer
182
    {
183
        $requestTransfer = new EasycreditRequestTransfer();
184
        $requestTransfer->setVorgangskennung($quoteTransfer->getPayment()->getEasycredit()->getVorgangskennung());
185
186
        return $requestTransfer;
187
    }
188
189
    /**
190
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
191
     *
192
     * @return \Generated\Shared\Transfer\EasycreditRequestTransfer
193
     */
194
    public function mapQueryCreditAssessmentRequest(QuoteTransfer $quoteTransfer): EasycreditRequestTransfer
195
    {
196
        $requestTransfer = new EasycreditRequestTransfer();
197
198
        if ($quoteTransfer->getPayment() && $quoteTransfer->getPayment()->getEasycredit()) {
199
            $requestTransfer->setVorgangskennung($quoteTransfer->getPayment()->getEasycredit()->getVorgangskennung());
200
        }
201
202
        return $requestTransfer;
203
    }
204
205
    /**
206
     * @return \Generated\Shared\Transfer\EasycreditRequestTransfer
207
     */
208
    public function mapApprovalTextRequest(): EasycreditRequestTransfer
209
    {
210
        return new EasycreditRequestTransfer();
211
    }
212
213
    /**
214
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
215
     *
216
     * @return array
217
     */
218
    protected function prepareOrderItems(QuoteTransfer $quoteTransfer): array
219
    {
220
        $items = [];
221
222
        foreach ($quoteTransfer->getItems() as $item) {
223
            $items[] = [
224
                static::KEY_MENGE => $item->getQuantity(),
225
                static::KEY_PREIS => $item->getRefundableAmount(),
226
                static::KEY_PRODUKTBEZEICHNUNG => $item->getName(),
227
            ];
228
        }
229
230
        return $items;
231
    }
232
}
233