Conditions | 18 |
Paths | 2050 |
Total Lines | 152 |
Code Lines | 89 |
Lines | 6 |
Ratio | 3.95 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
165 | public function process_booking( $bookingInfo = null ) { |
||
166 | if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
||
167 | return; |
||
168 | } |
||
169 | if ( isset( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) { |
||
170 | $bookingInfo->NoRedirect = true; |
||
171 | |||
172 | $countries = EDU()->api->GetCountries( EDU()->get_token(), 'Swedish' ); |
||
173 | |||
174 | $selectedCountry = 'SE'; |
||
175 | $selectedLocale = 'sv-SE'; |
||
176 | |||
177 | $invoiceCountry = $bookingInfo->Customer->InvoiceCountry; |
||
178 | if ( empty( $invoiceCountry ) ) { |
||
179 | $invoiceCountry = $bookingInfo->Customer->Country; |
||
180 | } |
||
181 | |||
182 | foreach ( $countries as $country ) { |
||
183 | if ( $invoiceCountry == $country->CountryName ) { |
||
184 | $selectedCountry = $country->CountryCode; |
||
185 | if ( ! empty( $country->CultureName ) ) { |
||
186 | $selectedLocale = $country->CultureName; |
||
187 | } |
||
188 | break; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | //$selectedLocale = explode( '-', $selectedLocale )[0]; |
||
193 | |||
194 | $currency = get_option( 'eduadmin-currency', 'SEK' ); |
||
195 | |||
196 | View Code Duplication | if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) { |
|
197 | $wpConfig = new EduSveaWebPayTestConfig( $this ); |
||
198 | } else { |
||
199 | $wpConfig = new EduSveaWebPayProductionConfig( $this ); |
||
200 | } |
||
201 | #$wpOrder = WebPay::createOrder( $wpConfig ); |
||
202 | $wpOrder = WebPay::checkout( $wpConfig ); |
||
203 | |||
204 | $orderRow = WebPayItem::orderRow(); |
||
205 | $orderRow->setName( $bookingInfo->EventBooking->EventDescription ); |
||
206 | $orderRow->setQuantity( 1 ); |
||
207 | |||
208 | $vatPercent = ( $bookingInfo->EventBooking->VatSum / $bookingInfo->EventBooking->TotalPriceExVat ) * 100; |
||
209 | $orderRow->setVatPercent( $vatPercent ); |
||
210 | $orderRow->setAmountIncVat( (float) $bookingInfo->EventBooking->TotalPriceIncVat ); |
||
211 | |||
212 | $customer = WebPayItem::companyCustomer(); |
||
213 | |||
214 | if ( ! empty( $bookingInfo->Customer->InvoiceName ) ) { |
||
215 | $customer->setCompanyName( $bookingInfo->Customer->InvoiceName ); |
||
216 | } else { |
||
217 | $customer->setCompanyName( $bookingInfo->Customer->CustomerName ); |
||
218 | } |
||
219 | |||
220 | if ( ! empty( $bookingInfo->Customer->InvoiceAddress1 ) ) { |
||
221 | $customer->setStreetAddress( $bookingInfo->Customer->InvoiceAddress1 ); |
||
222 | } else { |
||
223 | $customer->setStreetAddress( $bookingInfo->Customer->Address1 ); |
||
224 | } |
||
225 | |||
226 | if ( ! empty( $bookingInfo->Customer->InvoiceZip ) ) { |
||
227 | $customer->setZipCode( $bookingInfo->Customer->InvoiceZip ); |
||
228 | } else { |
||
229 | $customer->setZipCode( $bookingInfo->Customer->Zip ); |
||
230 | } |
||
231 | |||
232 | $zipPreset = WebPayItem::presetValue() |
||
233 | ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::POSTAL_CODE ) |
||
234 | ->setValue( ! empty( $bookingInfo->Customer->InvoiceZip ) ? $bookingInfo->Customer->InvoiceZip : $bookingInfo->Customer->Zip ) |
||
235 | ->setIsReadonly( false ); |
||
236 | $wpOrder->addPresetValue( $zipPreset ); |
||
237 | |||
238 | if ( ! empty( $bookingInfo->Customer->InvoiceCity ) ) { |
||
239 | $customer->setLocality( $bookingInfo->Customer->InvoiceCity ); |
||
240 | } else { |
||
241 | $customer->setLocality( $bookingInfo->Customer->City ); |
||
242 | } |
||
243 | |||
244 | if ( ! empty( $bookingInfo->Customer->Phone ) ) { |
||
245 | $customer->setPhoneNumber( $bookingInfo->Customer->Phone ); |
||
246 | $phonePreset = WebPayItem::presetValue() |
||
247 | ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER ) |
||
248 | ->setValue( $bookingInfo->Customer->Phone ) |
||
249 | ->setIsReadonly( false ); |
||
250 | $wpOrder->addPresetValue( $phonePreset ); |
||
251 | } |
||
252 | |||
253 | if ( ! empty( $bookingInfo->Customer->InvoiceEmail ) ) { |
||
254 | $customer->setEmail( $bookingInfo->Customer->InvoiceEmail ); |
||
255 | } else { |
||
256 | $customer->setEmail( $bookingInfo->Customer->Email ); |
||
257 | } |
||
258 | |||
259 | $emailPreset = WebPayItem::presetValue() |
||
260 | ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::EMAIL_ADDRESS ) |
||
261 | ->setValue( ! empty( $bookingInfo->Customer->InvoiceEmail ) ? $bookingInfo->Customer->InvoiceEmail : $bookingInfo->Customer->Email ) |
||
262 | ->setIsReadonly( false ); |
||
263 | $wpOrder->addPresetValue( $emailPreset ); |
||
264 | |||
265 | $customer->setIpAddress( EDU()->get_ip_adress() ); |
||
266 | |||
267 | $surl = get_home_url(); |
||
268 | $cat = get_option( 'eduadmin-rewriteBaseUrl' ); |
||
269 | $baseUrl = $surl . '/' . $cat; |
||
270 | |||
271 | $defaultThankYou = @get_page_link( get_option( 'eduadmin-thankYouPage', '/' ) ) . "?edu-thankyou=" . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1&svea_order_id={checkout.order.uri}'; |
||
272 | $defaultCancel = $baseUrl . "?edu-cancel=" . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1&svea_order_id={checkout.order.uri}'; |
||
273 | |||
274 | $defaultPushUrl = $baseUrl . '?edu-thankyou=' . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1&svea_order_id={checkout.order.uri}'; |
||
275 | |||
276 | $defaultTermsUrl = get_option( 'eduadmin-bookingTermsLink' ); |
||
277 | |||
278 | //$defaultCheckoutUrl = $surl . $_SERVER['REQUEST_URI']; |
||
279 | |||
280 | $wpBuild = $wpOrder |
||
281 | ->setCurrency( $currency ) |
||
282 | ->setCountryCode( $selectedCountry ) |
||
283 | //->setOrderDate( date( 'c' ) ) |
||
284 | ->setClientOrderNumber( $bookingInfo->EventBooking->EventCustomerLnkID ) |
||
285 | ->addOrderRow( $orderRow ) |
||
286 | //->addCustomerDetails( $customer ) |
||
287 | //->usePayPage() |
||
288 | //->setPayPageLanguage( $selectedLocale ) |
||
289 | ->setLocale( $selectedLocale ) |
||
290 | //->setReturnUrl( apply_filters( 'eduadmin-thankyou-url', $defaultThankYou ) ) |
||
291 | //->setCancelUrl( apply_filters( 'eduadmin-cancel-url', $defaultCancel ) ); |
||
292 | ->setTermsUri( $defaultTermsUrl ) |
||
293 | ->setConfirmationUri( $defaultThankYou ) |
||
294 | ->setPushUri( $defaultPushUrl ) |
||
295 | ->setCheckoutUri( $defaultCancel ); // We have no "checkout"-url.. So we just cancel the booking instead. |
||
296 | //$wpForm = $wpBuild->getPaymentUrl(); |
||
297 | $wpForm = $wpBuild->createOrder(); |
||
298 | |||
299 | set_transient( 'eduadmin-sveaorderid-' . $bookingInfo->EventBooking->EventCustomerLnkID, $wpForm['OrderId'], HOUR_IN_SECONDS ); |
||
300 | |||
301 | if ( array_key_exists( 'Gui', $wpForm ) ) { |
||
302 | echo $wpForm['Gui']['Snippet']; |
||
303 | } |
||
304 | /*if ( $wpForm->accepted ) { |
||
305 | if ( 'no' === $this->get_option( 'testrun', 'no' ) ) { |
||
306 | echo '<script type="text/javascript">location.href = "' . $wpForm->url . '";</script>'; |
||
307 | } else { |
||
308 | echo '<script type="text/javascript">location.href = "' . $wpForm->testurl . '";</script>'; |
||
309 | } |
||
310 | } else { |
||
311 | add_filter( 'edu-booking-error', function( $errors ) use ( &$wpForm ) { |
||
312 | $errors[] = $wpForm->errormessage; |
||
313 | } ); |
||
314 | }*/ |
||
315 | } |
||
316 | } |
||
317 | } |
||
319 | endif; |