Conditions | 16 |
Paths | 1538 |
Total Lines | 113 |
Code Lines | 76 |
Lines | 0 |
Ratio | 0 % |
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 |
||
129 | public function process_booking( $bookingInfo = null ) { |
||
130 | if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
||
131 | return; |
||
132 | } |
||
133 | if ( isset( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) { |
||
134 | $bookingInfo->NoRedirect = true; |
||
135 | |||
136 | $countries = EDU()->api->GetCountries( EDU()->get_token(), 'Swedish' ); |
||
137 | |||
138 | $selectedCountry = 'SE'; |
||
139 | $selectedLocale = 'sv-SE'; |
||
140 | |||
141 | $invoiceCountry = $bookingInfo->Customer->InvoiceCountry; |
||
142 | if ( empty( $invoiceCountry ) ) { |
||
143 | $invoiceCountry = $bookingInfo->Customer->Country; |
||
144 | } |
||
145 | |||
146 | foreach ( $countries as $country ) { |
||
147 | if ( $invoiceCountry == $country->CountryName ) { |
||
148 | $selectedCountry = $country->CountryCode; |
||
149 | if ( ! empty( $country->CultureName ) ) { |
||
150 | $selectedLocale = $country->CultureName; |
||
151 | } |
||
152 | break; |
||
153 | } |
||
154 | } |
||
155 | |||
156 | $selectedLocale = explode( '-', $selectedLocale )[0]; |
||
157 | |||
158 | $currency = get_option( 'eduadmin-currency', 'SEK' ); |
||
159 | |||
160 | $wpConfig = ConfigurationService::getDefaultConfig(); |
||
161 | $wpOrder = WebPay::createOrder( $wpConfig ); |
||
162 | |||
163 | $orderRow = WebPayItem::orderRow(); |
||
164 | $orderRow->setName( $bookingInfo->EventBooking->EventDescription ); |
||
165 | $orderRow->setQuantity( 1 ); |
||
166 | |||
167 | $vatPercent = ( $bookingInfo->EventBooking->VatSum / $bookingInfo->EventBooking->TotalPriceExVat ) * 100; |
||
168 | $orderRow->setVatPercent( $vatPercent ); |
||
169 | $orderRow->setAmountIncVat( (float) $bookingInfo->EventBooking->TotalPriceIncVat ); |
||
170 | |||
171 | $customer = WebPayItem::companyCustomer(); |
||
172 | |||
173 | if ( ! empty( $bookingInfo->Customer->InvoiceName ) ) { |
||
174 | $customer->setCompanyName( $bookingInfo->Customer->InvoiceName ); |
||
175 | } else { |
||
176 | $customer->setCompanyName( $bookingInfo->Customer->CustomerName ); |
||
177 | } |
||
178 | |||
179 | if ( ! empty( $bookingInfo->Customer->InvoiceAddress1 ) ) { |
||
180 | $customer->setStreetAddress( $bookingInfo->Customer->InvoiceAddress1 ); |
||
181 | } else { |
||
182 | $customer->setStreetAddress( $bookingInfo->Customer->Address1 ); |
||
183 | } |
||
184 | |||
185 | if ( ! empty( $bookingInfo->Customer->InvoiceZip ) ) { |
||
186 | $customer->setZipCode( $bookingInfo->Customer->InvoiceZip ); |
||
187 | } else { |
||
188 | $customer->setZipCode( $bookingInfo->Customer->Zip ); |
||
189 | } |
||
190 | |||
191 | if ( ! empty( $bookingInfo->Customer->InvoiceCity ) ) { |
||
192 | $customer->setLocality( $bookingInfo->Customer->InvoiceCity ); |
||
193 | } else { |
||
194 | $customer->setLocality( $bookingInfo->Customer->City ); |
||
195 | } |
||
196 | |||
197 | if ( ! empty( $bookingInfo->Customer->Phone ) ) { |
||
198 | $customer->setPhoneNumber( $bookingInfo->Customer->Phone ); |
||
199 | } |
||
200 | |||
201 | if ( ! empty( $bookingInfo->Customer->InvoiceEmail ) ) { |
||
202 | $customer->setEmail( $bookingInfo->Customer->InvoiceEmail ); |
||
203 | } else { |
||
204 | $customer->setEmail( $bookingInfo->Customer->Email ); |
||
205 | } |
||
206 | |||
207 | $customer->setIpAddress( EDU()->get_ip_adress() ); |
||
208 | |||
209 | $surl = get_home_url(); |
||
210 | $cat = get_option( 'eduadmin-rewriteBaseUrl' ); |
||
211 | $baseUrl = $surl . '/' . $cat; |
||
212 | |||
213 | $defaultThankYou = @get_page_link( get_option( 'eduadmin-thankYouPage', '/' ) ) . "?edu-thankyou=" . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1'; |
||
214 | $defaultCancel = $baseUrl . "?edu-cancel=" . $bookingInfo->EventBooking->EventCustomerLnkID . '&svea=1'; |
||
215 | |||
216 | $wpForm = $wpOrder |
||
217 | ->setCurrency( $currency ) |
||
218 | ->setCountryCode( $selectedCountry ) |
||
219 | ->setOrderDate( date( 'c' ) ) |
||
220 | ->setClientOrderNumber( $bookingInfo->EventBooking->EventCustomerLnkID ) |
||
221 | ->addOrderRow( $orderRow ) |
||
222 | ->addCustomerDetails( $customer ) |
||
223 | ->usePayPage() |
||
224 | ->setPayPageLanguage( $selectedLocale ) |
||
225 | ->setReturnUrl( apply_filters( 'eduadmin-thankyou-url', $defaultThankYou ) ) |
||
226 | ->setCancelUrl( apply_filters( 'eduadmin-cancel-url', $defaultCancel ) ) |
||
227 | ->getPaymentUrl(); |
||
228 | |||
229 | if ( $wpForm->accepted ) { |
||
230 | if ( 'no' === $this->get_option( 'testrun', 'no' ) ) { |
||
231 | echo '<script type="text/javascript">location.href = "' . $wpForm->url . '";</script>'; |
||
232 | } else { |
||
233 | echo '<script type="text/javascript">location.href = "' . $wpForm->testurl . '";</script>'; |
||
234 | } |
||
235 | } else { |
||
236 | add_filter( 'edu-booking-error', function( $errors ) use ( &$wpForm ) { |
||
237 | $errors[] = $wpForm->errormessage; |
||
238 | } ); |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | } |
||
244 | endif; |