ResponseParser   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
eloc 73
c 2
b 0
f 0
dl 0
loc 163
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parseInitializePaymentResponse() 0 17 3
A parsePreContractualInformationAndRedemptionPlanResponse() 0 16 2
A parseQueryCreditAssessmentResponse() 0 17 2
A parseInterestAndTotalSumResponse() 0 21 3
A parseOrderConfirmationResponse() 0 18 2
A parseApprovalTextResponse() 0 17 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\Parser;
9
10
use Generated\Shared\Transfer\EasycreditApprovalTextResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...valTextResponseTransfer 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\EasycreditInitializePaymentResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PaymentResponseTransfer 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\EasycreditInterestAndAdjustTotalSumResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...otalSumResponseTransfer 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\EasycreditOrderConfirmationResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rmationResponseTransfer 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\EasycreditPreContractualInformationAndRedemptionPlanResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ionPlanResponseTransfer 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\EasycreditQueryCreditAssessmentResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...essmentResponseTransfer 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\EasycreditResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ycreditResponseTransfer 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
18
class ResponseParser implements ResponseParserInterface
19
{
20
    protected const KEY_PAYMENT_IDENTIFIER = 'tbVorgangskennung';
21
    protected const KEY_ALLGEMEINE_VORGANGSDATEN = 'allgemeineVorgangsdaten';
22
    protected const KEY_URL_VORVERTRAGLICHE_INFORMATIONEN = 'urlVorvertraglicheInformationen';
23
    protected const KEY_TILGUNGSPLAN_TEXT = 'tilgungsplanText';
24
    protected const KEY_WS_MESSAGES = 'wsMessages';
25
    protected const KEY_MESSAGES = 'messages';
26
    protected const KEY_KEY = 'key';
27
    protected const VALUE_SUCCESS_CONFIRMATION = 'BestellungBestaetigenServiceActivity.Infos.ERFOLGREICH';
28
    protected const KEY_RATENPLAN = 'ratenplan';
29
    protected const KEY_ZINSEN = 'zinsen';
30
    protected const KEY_ANFALLENDE_ZINSEN = 'anfallendeZinsen';
31
    protected const KEY_ENTSCHEIDUNG = 'entscheidung';
32
    protected const KEY_ENTSCHEIDUNG_SERGEBNIS = 'entscheidungsergebnis';
33
    protected const KEY_TEXT_IDENTIFIER = 'zustimmungDatenuebertragungPaymentPage';
34
35
    /**
36
     * @param \Generated\Shared\Transfer\EasycreditResponseTransfer $easycreditResponseTransfer
37
     *
38
     * @return \Generated\Shared\Transfer\EasycreditInitializePaymentResponseTransfer
39
     */
40
    public function parseInitializePaymentResponse(EasycreditResponseTransfer $easycreditResponseTransfer): EasycreditInitializePaymentResponseTransfer
41
    {
42
        $payload = $easycreditResponseTransfer->getBody();
43
44
        $easycreditInitializePaymentResponseTransfer = new EasycreditInitializePaymentResponseTransfer();
45
        $easycreditInitializePaymentResponseTransfer->setSuccess(false);
46
47
        if ($easycreditResponseTransfer->getError() !== null) {
48
            return $easycreditInitializePaymentResponseTransfer;
49
        }
50
51
        if (isset($payload[static::KEY_PAYMENT_IDENTIFIER])) {
52
            $easycreditInitializePaymentResponseTransfer->setPaymentIdentifier($payload[static::KEY_PAYMENT_IDENTIFIER]);
53
            $easycreditInitializePaymentResponseTransfer->setSuccess(true);
54
        }
55
56
        return $easycreditInitializePaymentResponseTransfer;
57
    }
58
59
    /**
60
     * @param \Generated\Shared\Transfer\EasycreditResponseTransfer $easycreditResponseTransfer
61
     *
62
     * @return \Generated\Shared\Transfer\EasycreditPreContractualInformationAndRedemptionPlanResponseTransfer
63
     */
64
    public function parsePreContractualInformationAndRedemptionPlanResponse(EasycreditResponseTransfer $easycreditResponseTransfer): EasycreditPreContractualInformationAndRedemptionPlanResponseTransfer
65
    {
66
        $payload = $easycreditResponseTransfer->getBody();
67
68
        $easycreditPreContractualInformationAndRedemptionPlanResponseTransfer = new EasycreditPreContractualInformationAndRedemptionPlanResponseTransfer();
69
        $easycreditPreContractualInformationAndRedemptionPlanResponseTransfer->setSuccess(false);
70
71
        if ($easycreditResponseTransfer->getError() !== null) {
72
            return $easycreditPreContractualInformationAndRedemptionPlanResponseTransfer;
73
        }
74
75
        $urlVorvertraglicheInformationen = $payload[static::KEY_ALLGEMEINE_VORGANGSDATEN][static::KEY_URL_VORVERTRAGLICHE_INFORMATIONEN] ?? null;
76
        $easycreditPreContractualInformationAndRedemptionPlanResponseTransfer->setUrlVorvertraglicheInformationen($urlVorvertraglicheInformationen);
77
        $easycreditPreContractualInformationAndRedemptionPlanResponseTransfer->setSuccess($urlVorvertraglicheInformationen !== null);
78
79
        return $easycreditPreContractualInformationAndRedemptionPlanResponseTransfer;
80
    }
81
82
    /**
83
     * @param \Generated\Shared\Transfer\EasycreditResponseTransfer $easycreditResponseTransfer
84
     *
85
     * @return \Generated\Shared\Transfer\EasycreditOrderConfirmationResponseTransfer
86
     */
87
    public function parseOrderConfirmationResponse(EasycreditResponseTransfer $easycreditResponseTransfer): EasycreditOrderConfirmationResponseTransfer
88
    {
89
        $payload = $easycreditResponseTransfer->getBody();
90
91
        $easycreditOrderConfirmationResponseTransfer = new EasycreditOrderConfirmationResponseTransfer();
92
        $easycreditOrderConfirmationResponseTransfer->setSuccess(false);
93
94
        if ($easycreditResponseTransfer->getError() !== null) {
95
            return $easycreditOrderConfirmationResponseTransfer;
96
        }
97
98
        $successIdentifier = $payload[static::KEY_WS_MESSAGES][static::KEY_MESSAGES][0][static::KEY_KEY] ?? null;
99
100
        $isSuccess = $successIdentifier === static::VALUE_SUCCESS_CONFIRMATION;
101
        $easycreditOrderConfirmationResponseTransfer->setConfirmed($isSuccess);
102
        $easycreditOrderConfirmationResponseTransfer->setSuccess($isSuccess);
103
104
        return $easycreditOrderConfirmationResponseTransfer;
105
    }
106
107
    /**
108
     * @param \Generated\Shared\Transfer\EasycreditResponseTransfer $easycreditResponseTransfer
109
     *
110
     * @return \Generated\Shared\Transfer\EasycreditInterestAndAdjustTotalSumResponseTransfer
111
     */
112
    public function parseInterestAndTotalSumResponse(EasycreditResponseTransfer $easycreditResponseTransfer): EasycreditInterestAndAdjustTotalSumResponseTransfer
113
    {
114
        $payload = $easycreditResponseTransfer->getBody();
115
116
        $easycreditInterestAndAdjustTotalSumResponseTransfer = new EasycreditInterestAndAdjustTotalSumResponseTransfer();
117
        $easycreditInterestAndAdjustTotalSumResponseTransfer->setSuccess(false);
118
119
        if ($easycreditResponseTransfer->getError() !== null) {
120
            return $easycreditInterestAndAdjustTotalSumResponseTransfer;
121
        }
122
123
        $anfallendeZinsen = (float)$payload[static::KEY_RATENPLAN][static::KEY_ZINSEN][static::KEY_ANFALLENDE_ZINSEN] ?? null;
124
        $tilgungsplanText = $payload[static::KEY_TILGUNGSPLAN_TEXT] ?? null;
125
126
        $easycreditInterestAndAdjustTotalSumResponseTransfer->setAnfallendeZinsen($anfallendeZinsen);
127
        $easycreditInterestAndAdjustTotalSumResponseTransfer->setTilgungsplanText($tilgungsplanText);
128
129
        $isSuccess = $anfallendeZinsen !== null && $tilgungsplanText !== null;
130
        $easycreditInterestAndAdjustTotalSumResponseTransfer->setSuccess($isSuccess);
131
132
        return $easycreditInterestAndAdjustTotalSumResponseTransfer;
133
    }
134
135
    /**
136
     * @param \Generated\Shared\Transfer\EasycreditResponseTransfer $easycreditResponseTransfer
137
     *
138
     * @return \Generated\Shared\Transfer\EasycreditQueryCreditAssessmentResponseTransfer
139
     */
140
    public function parseQueryCreditAssessmentResponse(EasycreditResponseTransfer $easycreditResponseTransfer): EasycreditQueryCreditAssessmentResponseTransfer
141
    {
142
        $payload = $easycreditResponseTransfer->getBody();
143
144
        $easycreditQueryCreditAssessmentResponseTransfer = new EasycreditQueryCreditAssessmentResponseTransfer();
145
        $easycreditQueryCreditAssessmentResponseTransfer->setSuccess(false);
146
147
        if ($easycreditResponseTransfer->getError() !== null) {
148
            return $easycreditQueryCreditAssessmentResponseTransfer;
149
        }
150
151
        $status = $payload[static::KEY_ENTSCHEIDUNG][static::KEY_ENTSCHEIDUNG_SERGEBNIS] ?? null;
152
153
        $easycreditQueryCreditAssessmentResponseTransfer->setStatus($status);
154
        $easycreditQueryCreditAssessmentResponseTransfer->setSuccess($status !== null);
155
156
        return $easycreditQueryCreditAssessmentResponseTransfer;
157
    }
158
159
    /**
160
     * @param \Generated\Shared\Transfer\EasycreditResponseTransfer $easycreditResponseTransfer
161
     *
162
     * @return \Generated\Shared\Transfer\EasycreditApprovalTextResponseTransfer
163
     */
164
    public function parseApprovalTextResponse(EasycreditResponseTransfer $easycreditResponseTransfer): EasycreditApprovalTextResponseTransfer
165
    {
166
        $payload = $easycreditResponseTransfer->getBody();
167
168
        $easycreditApprovalTextResponseTransfer = new EasycreditApprovalTextResponseTransfer();
169
        $easycreditApprovalTextResponseTransfer->setSuccess(false);
170
171
        if ($easycreditResponseTransfer->getError() !== null) {
172
            return $easycreditApprovalTextResponseTransfer;
173
        }
174
175
        if (isset($payload[static::KEY_TEXT_IDENTIFIER])) {
176
            $easycreditApprovalTextResponseTransfer->setSuccess(true);
177
            $easycreditApprovalTextResponseTransfer->setText($payload[static::KEY_TEXT_IDENTIFIER]);
178
        }
179
180
        return $easycreditApprovalTextResponseTransfer;
181
    }
182
}
183