-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEasyCreditExampleCalculation.php
More file actions
196 lines (173 loc) · 5.41 KB
/
Copy pathEasyCreditExampleCalculation.php
File metadata and controls
196 lines (173 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/*
* This file is part of OXID eSales AG EasyCredit module
* Copyright © OXID eSales AG. All rights reserved.
*
* Licensed under the GNU GPL v3 - See the file LICENSE for details.
*/
namespace OxidProfessionalServices\EasyCredit\Application\Component\Widget;
use OxidEsales\Eshop\Application\Component\Widget\WidgetController;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
use OxidEsales\Eshop\Core\Price;
use OxidProfessionalServices\EasyCredit\Core\Api\EasyCreditWebServiceClientFactory;
use OxidProfessionalServices\EasyCredit\Core\Di\EasyCreditApiConfig;
use OxidProfessionalServices\EasyCredit\Core\Di\EasyCreditDic;
use OxidProfessionalServices\EasyCredit\Core\Di\EasyCreditDicFactory;
use OxidProfessionalServices\EasyCredit\Core\Helper\EasyCreditHelper;
/**
* Class EasyCreditExampleCalculation
*
* @package OxidProfessionalServices\EasyCredit\Application\Component\Widget
*/
class EasyCreditExampleCalculation extends WidgetController
{
protected $_sThisTemplate = 'oxpseasycredit_examplecalculation.tpl';
/** @var EasyCreditDic */
private $dic;
/** @var \stdClass */
protected $exampleCalculation;
/** @var Basket */
protected $basket;
/**
* Return the monthly fee to pay for credit.
*
* @return string|void
*/
public function getExampleCalculationRate()
{
if ($this->hasExampleCalculation()) {
return Registry::getLang()->formatCurrency($this->getExampleCalulation()->betragRate);
}
}
/**
* Is there an example calculation?
*
* @return bool
*/
public function hasExampleCalculation()
{
return (bool) $this->getExampleCalulation();
}
/**
* Return example calculation.
*
* @return \stdClass
*/
protected function getExampleCalulation()
{
if (!$this->exampleCalculation) {
$response = $this->getExampleCalculationResponse();
if ($response) {
$this->exampleCalculation = $response;
}
}
return $this->exampleCalculation;
}
/**
* Return the DIC
*
* @return EasyCreditDic
* @throws SystemComponentException
*/
protected function getDic()
{
if (!$this->dic) {
$this->dic = EasyCreditDicFactory::getDic();
}
return $this->dic;
}
/**
* Returns the price relevant for the example calculation.
*
* @return Price
* @throws SystemComponentException
*/
protected function getPrice()
{
return EasyCreditHelper::getExampleCalculationPrice($this->getViewParameter("articleId"), $this->getBasket());
}
/**
* Returns active basket
*
* @return Basket
*/
protected function getBasket()
{
return Registry::getSession()->getBasket();
}
/**
* Load example calculation from ec service.
*
* @return false|\stdClass|void
* @throws SystemComponentException
*/
protected function getExampleCalculationResponse()
{
$price = $this->getPrice();
$payment = oxNew(Payment::class);
$payment->load('easycreditinstallment');
if (
!$price ||
(int) $price->getBruttoPrice() < (int) $payment->getFieldData('oxfromamount') ||
(int) $price->getBruttoPrice() > (int) $payment->getFieldData('oxtoamount')
) {
return false;
}
try {
/** @var EasyCreditDic $dic */
$dic = $this->getDic();
$webServiceClient = EasyCreditWebServiceClientFactory::getWebServiceClient(
EasyCreditApiConfig::API_CONFIG_SERVICE_NAME_V1_MODELLRECHNUNG_GUENSTIGSTER_RATENPLAN,
$dic,
[],
[EasyCreditApiConfig::API_CONFIG_SERVICE_REST_ARGUMENT_FINANZIERUNGSBETRAG => $price->getBruttoPrice()]
);
return $webServiceClient->execute();
} catch (\Exception $ex) {
$this->getDic()->getLogging()->log($ex->getMessage());
}
}
/**
* Getter for config parameter.
*
* @return mixed
*/
public function getUseOwnjQueryUI()
{
return Registry::getConfig()->getConfigParam('oxpsECExampleUseOwnjQueryUI');
}
/**
* Getter for ajax request url.
*
* @return string
*/
public function getAjaxUrl()
{
$sURL = Registry::getConfig()->getConfigParam('sShopURL');
$articleId = $this->getViewParameter("articleId");
return $sURL . 'index.php?cl=easycreditexamplecalculation' . ($articleId ? '&articleId=' . $articleId : '') . '&placeholderId=' . $this->getViewParameter("placeholderId") . '&ajax=1';
}
/**
* Getter for ajax popup url.
*
* @return string
*/
public function getPopupAjaxUrl()
{
$sURL = Registry::getConfig()->getConfigParam('sShopURL');
$articleId = $this->getViewParameter("articleId");
return $sURL . 'index.php?cl=easycreditexamplecalculationpopup' . ($articleId ? '&articleId=' . $articleId : '') . '&ajax=1';
}
/**
* Getter for request parameter to decide if it is an ajax request.
*
* @return bool
*/
public function isAjax()
{
return (Registry::getConfig()->getRequestParameter('ajax') == 1);
}
}