KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > event_registrations > cms > action > WebEventRegistrationAction


1 package com.dotmarketing.portlets.event_registrations.cms.action;
2
3 import java.net.URLEncoder JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Date JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import javax.servlet.http.HttpSession JavaDoc;
11
12 import org.apache.commons.beanutils.BeanUtils;
13 import org.apache.struts.Globals;
14 import org.apache.struts.action.ActionErrors;
15 import org.apache.struts.action.ActionForm;
16 import org.apache.struts.action.ActionForward;
17 import org.apache.struts.action.ActionMapping;
18 import org.apache.struts.action.ActionMessage;
19 import org.apache.struts.action.ActionMessages;
20 import org.apache.struts.actions.DispatchAction;
21
22 import com.dotmarketing.beans.UserProxy;
23 import com.dotmarketing.cms.factories.PublicAddressFactory;
24 import com.dotmarketing.db.DotHibernate;
25 import com.dotmarketing.factories.HostFactory;
26 import com.dotmarketing.factories.InodeFactory;
27 import com.dotmarketing.factories.UserProxyFactory;
28 import com.dotmarketing.util.Config;
29 import com.dotmarketing.util.CreditCardProcessor;
30 import com.dotmarketing.util.CreditCardProcessorException;
31 import com.dotmarketing.util.CreditCardProcessorResponse;
32 import com.dotmarketing.util.Logger;
33 import com.dotmarketing.util.Mailer;
34 import com.dotmarketing.util.UtilMethods;
35 import com.dotmarketing.util.Validator;
36 import com.dotmarketing.util.WebKeys;
37 import com.liferay.portal.model.Address;
38 import com.liferay.portal.model.User;
39 import com.dotmarketing.portlets.event_registrations.factories.WebEventAttendeeFactory;
40 import com.dotmarketing.portlets.event_registrations.factories.WebEventRegistrationFactory;
41 import com.dotmarketing.portlets.event_registrations.model.WebEventAttendee;
42 import com.dotmarketing.portlets.event_registrations.model.WebEventRegistration;
43 import com.dotmarketing.portlets.event_registrations.struts.WebEventAttendeeForm;
44 import com.dotmarketing.portlets.event_registrations.struts.WebEventRegistrationForm;
45 import com.dotmarketing.portlets.webevents.factories.WebEventFactory;
46 import com.dotmarketing.portlets.webevents.factories.WebEventLocationFactory;
47 import com.dotmarketing.portlets.webevents.model.WebEvent;
48 import com.dotmarketing.portlets.webevents.model.WebEventLocation;
49 import com.dotmarketing.portlets.organization.model.Organization;
50
51 /**
52  * @author David
53  *
54  */

55 public class WebEventRegistrationAction extends DispatchAction {
56
57     /**
58      * Beginning the Event Registration process This method forwards to the user
59      * registration pages to check the user info
60      */

61     public ActionForward unspecified(ActionMapping mapping, ActionForm lf,
62             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
63             throws Exception JavaDoc {
64
65         HttpSession JavaDoc session = request.getSession();
66
67         WebEventRegistrationForm form = (WebEventRegistrationForm) lf;
68         long eventLocationInode = form.getEventLocationInode();
69         long eventInode = form.getEventInode();
70         if (eventLocationInode == 0) {
71             ActionForward forward = mapping.findForward("upcommingEvents");
72             return forward;
73         }
74         
75         lf = new WebEventRegistrationForm();
76         ((WebEventRegistrationForm) lf).setEventLocationInode(eventLocationInode);
77         ((WebEventRegistrationForm) lf).setEventInode(eventInode);
78         session.setAttribute("webEventRegistrationForm",lf);
79
80         // Removing session attributes from past registration
81
request.getSession().removeAttribute(
82                 WebKeys.WEBEVENTS_REG_BEAN);
83         request.getSession().removeAttribute(
84                 WebKeys.WEBEVENTS_REG_ERRORS);
85
86         // Forwarding to login/registration page
87
if (session.getAttribute(WebKeys.CMS_USER) != null) {
88             User user = (User) session.getAttribute(WebKeys.CMS_USER);
89             UserProxy proxy = UserProxyFactory.getUserProxy(user);
90             request.setAttribute("userProxyInode", proxy.getInode());
91         }
92         String JavaDoc referrer = request.getRequestURI();
93         String JavaDoc refererForgotPassword = referrer + "?" + request.getQueryString();
94         refererForgotPassword = URLEncoder.encode(refererForgotPassword,"UTF-8");
95         request.setAttribute("from", "webEventRegistration");
96         request.setAttribute("referrer", referrer + "?dispatch=toStep1");
97         request.setAttribute("refererForgotPassword",refererForgotPassword);
98
99         ActionMessages messages = new ActionMessages();
100         messages.add(Globals.MESSAGES_KEY, new ActionMessage("error.login.webevent"));
101         saveMessages(request, messages);
102         return mapping.findForward("registrantInfoPage");
103     }
104
105     /**
106      * This action goes to the add registrants page
107      */

108     public ActionForward toStep1(ActionMapping mapping, ActionForm lf,
109             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
110             throws Exception JavaDoc {
111
112         HttpSession JavaDoc sess = request.getSession();
113         WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) lf;
114         
115         WebEvent event = WebEventFactory.getWebEvent(registrationForm.getEventInode());
116         User user = (User) sess.getAttribute(WebKeys.CMS_USER);
117
118         if (registrationForm.getEventLocationInode() == 0) {
119             ActionForward forward = mapping.findForward("upcommingEvents");
120             return forward;
121         }
122
123         registrationForm.setUserInode(UserProxyFactory.getUserProxy(user).getInode());
124         
125         registrationForm.resetCurrentAttendee();
126         registrationForm.setDatePosted(new Date JavaDoc());
127         registrationForm.setLastModDate(new Date JavaDoc());
128
129         
130         if (event.isInstitute()) {
131             //code for institutes
132

133             // Token Generation to avoid transactions duplication
134
generateToken(request);
135             saveToken(request);
136
137             return mapping.findForward("step1");
138         }
139         else {
140
141             //code for webinars
142
WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm();
143             attendeeForm.setFirstName(user.getFirstName());
144             attendeeForm.setLastName(user.getLastName());
145             attendeeForm.setTitle("");
146             attendeeForm.setBadgeName("");
147             attendeeForm.setEmail(user.getEmailAddress());
148
149             WebEventLocation loc = WebEventLocationFactory.getWebEventLocation(registrationForm.getEventLocationInode());
150             
151             if (request.getSession().getAttribute("isPartner") != null
152                     && request.getSession().getAttribute("isPartner")
153                             .equals("true")){
154                 if (loc.isDefaultContractPartnerPrice()){
155                     Organization organization = (Organization)request.getSession().getAttribute("userOrganization");
156                     if (organization.getInode() > 0)
157                         if (organization.getInstitute_price() > 0)
158                             attendeeForm.setRegistrationPrice(organization.getInstitute_price());
159                         else
160                             attendeeForm.setRegistrationPrice(loc.getPartnerPrice());
161                 }
162                 else
163                     attendeeForm.setRegistrationPrice(loc.getPartnerPrice());
164             }
165             else
166                 attendeeForm.setRegistrationPrice(loc.getNonPartnerPrice());
167             List JavaDoc<WebEventAttendeeForm> currentAttendees = registrationForm.getEventAttendees();
168             if (!currentAttendees.contains(attendeeForm)) {
169                 currentAttendees.add(attendeeForm);
170             }
171             // Token Generation to avoid transactions duplication
172
generateToken(request);
173             saveToken(request);
174             return toStep2(mapping, lf,request, response);
175         }
176     }
177
178     /**
179      * Add/Save a registrant info
180      */

181     public ActionForward saveAttendee(ActionMapping mapping, ActionForm lf,
182             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
183             throws Exception JavaDoc {
184
185         WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) lf;
186
187         if (registrationForm.getEventLocationInode() == 0) {
188             ActionForward forward = mapping.findForward("upcommingEvents");
189             return forward;
190         }
191
192         if (!Validator.validate(request, registrationForm, mapping)) {
193             return mapping.findForward("step1");
194         }
195
196         WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm();
197         attendeeForm.setFirstName(registrationForm
198                 .getCurrentAttendeeFirstName());
199         attendeeForm.setLastName(registrationForm.getCurrentAttendeeLastName());
200         attendeeForm.setTitle(registrationForm.getCurrentAttendeeTitle());
201         attendeeForm.setBadgeName(registrationForm
202                 .getCurrentAttendeeBadgeName());
203         attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail());
204         registrationForm.resetCurrentAttendee();
205
206         WebEventLocation loc = WebEventLocationFactory
207                 .getWebEventLocation(registrationForm.getEventLocationInode());
208         if (request.getSession().getAttribute("isPartner") != null
209                 && request.getSession().getAttribute("isPartner")
210                         .equals("true")){
211             if (loc.isDefaultContractPartnerPrice()){
212                 Organization organization = (Organization)request.getSession().getAttribute("userOrganization");
213                 if (organization.getInode() > 0)
214                     if (organization.getInstitute_price() > 0)
215                         attendeeForm.setRegistrationPrice(organization.getInstitute_price());
216                     else
217                         attendeeForm.setRegistrationPrice(loc.getPartnerPrice());
218             }
219             else
220                 attendeeForm.setRegistrationPrice(loc.getPartnerPrice());
221         }
222         else
223             attendeeForm.setRegistrationPrice(loc.getNonPartnerPrice());
224
225
226         List JavaDoc<WebEventAttendeeForm> currentAttendees = registrationForm
227                 .getEventAttendees();
228
229         if (request.getParameter("isnew") != null
230                 && request.getParameter("isnew").equals("true")) {
231
232             if (currentAttendees.contains(attendeeForm)) {
233                 ActionErrors errors = new ActionErrors();
234                 errors.add("attendees", new ActionMessage(
235                         "error.attendee.already.registered"));
236                 saveMessages(request, errors);
237             } else {
238                 currentAttendees.add(attendeeForm);
239             }
240         } else {
241             WebEventAttendeeForm lastAttendeeForm = new WebEventAttendeeForm();
242             lastAttendeeForm.setEmail(registrationForm.getCurrentAttendeeLastEmail());
243             lastAttendeeForm.setFirstName(registrationForm.getCurrentAttendeeLastFirstName());
244             lastAttendeeForm.setLastName(registrationForm.getCurrentAttendeeLastLastName());
245             
246             if (currentAttendees.contains(lastAttendeeForm)) {
247                 currentAttendees.remove(lastAttendeeForm);
248                 currentAttendees.add(attendeeForm);
249             } else {
250                 currentAttendees.add(attendeeForm);
251             }
252         }
253
254         return mapping.findForward("step1");
255     }
256
257     /**
258      * Delete a registrant
259      */

260     public ActionForward deleteAttendee(ActionMapping mapping, ActionForm lf,
261             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
262             throws Exception JavaDoc {
263
264         WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) lf;
265
266         if (registrationForm.getEventLocationInode() == 0) {
267             ActionForward forward = mapping.findForward("upcommingEvents");
268             return forward;
269         }
270
271         WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm();
272         attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail());
273         attendeeForm.setFirstName(registrationForm.getCurrentAttendeeFirstName());
274         attendeeForm.setLastName(registrationForm.getCurrentAttendeeLastName());
275
276         List JavaDoc currentAttendees = registrationForm.getEventAttendees();
277         currentAttendees.remove(attendeeForm);
278         registrationForm.resetCurrentAttendee();
279
280         return mapping.findForward("step1");
281     }
282
283     /**
284      * Loads the data to edit a registrant already added
285      */

286     public ActionForward editAttendee(ActionMapping mapping, ActionForm lf,
287             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
288             throws Exception JavaDoc {
289
290         WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) lf;
291
292         if (registrationForm.getEventLocationInode() == 0) {
293             ActionForward forward = mapping.findForward("upcommingEvents");
294             return forward;
295         }
296
297         WebEventAttendeeForm attendeeForm = new WebEventAttendeeForm();
298         attendeeForm.setEmail(registrationForm.getCurrentAttendeeEmail());
299         attendeeForm.setFirstName(registrationForm.getCurrentAttendeeFirstName());
300         attendeeForm.setLastName(registrationForm.getCurrentAttendeeLastName());
301
302         List JavaDoc<WebEventAttendeeForm> currentAttendees = registrationForm
303                 .getEventAttendees();
304         if (currentAttendees.indexOf(attendeeForm) >= 0) {
305             attendeeForm = currentAttendees.get(currentAttendees
306                     .indexOf(attendeeForm));
307             registrationForm.setCurrentAttendeeFirstName(attendeeForm
308                     .getFirstName());
309             registrationForm.setCurrentAttendeeLastName(attendeeForm
310                     .getLastName());
311             registrationForm.setCurrentAttendeeTitle(attendeeForm.getTitle());
312             registrationForm.setCurrentAttendeeBadgeName(attendeeForm
313                     .getBadgeName());
314             registrationForm.setCurrentAttendeeEmail(attendeeForm.getEmail());
315         }
316
317         return mapping.findForward("step1");
318     }
319
320     /**
321      * Forwards to the checkout info page
322      */

323     public ActionForward toStep2(ActionMapping mapping, ActionForm lf,
324             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
325             throws Exception JavaDoc {
326
327         WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) lf;
328
329         if (registrationForm.getEventLocationInode() == 0) {
330             ActionForward forward = mapping.findForward("upcommingEvents");
331             return forward;
332         }
333
334         HttpSession JavaDoc sess = request.getSession();
335
336         User user = (User) sess.getAttribute(WebKeys.CMS_USER);
337
338         List JavaDoc addresses = PublicAddressFactory.getAddressesByUserId(user
339                 .getUserId());
340
341         if (addresses.size() > 0) {
342             Address mailingAddress = (Address) addresses.get(0);
343             // Prepopulation of the billing address info based on the user
344
// address info
345
if (!UtilMethods.isSet(registrationForm.getBillingAddress1()))
346                 registrationForm
347                         .setBillingAddress1(mailingAddress.getStreet1());
348             if (!UtilMethods.isSet(registrationForm.getBillingAddress2()))
349                 registrationForm
350                         .setBillingAddress2(mailingAddress.getStreet2());
351             if (!UtilMethods.isSet(registrationForm.getBillingCity()))
352                 registrationForm.setBillingCity(mailingAddress.getCity());
353             if (!UtilMethods.isSet(registrationForm.getBillingContactEmail()))
354                 registrationForm.setBillingContactEmail(user.getEmailAddress());
355             if (!UtilMethods.isSet(registrationForm.getBillingContactName()))
356                 registrationForm.setBillingContactName(user.getFullName());
357             if (!UtilMethods.isSet(registrationForm.getBillingContactPhone()))
358                 registrationForm.setBillingContactPhone(mailingAddress
359                         .getPhone());
360             if (!UtilMethods.isSet(registrationForm.getBillingState()))
361                 registrationForm.setBillingState(mailingAddress.getState());
362             if (!UtilMethods.isSet(registrationForm.getBillingZip()))
363                 registrationForm.setBillingZip(mailingAddress.getZip());
364             if (!UtilMethods.isSet(registrationForm.getBillingCountry()))
365                 registrationForm.setBillingCountry(mailingAddress.getCountry());
366         }
367         
368         //save the registration
369
//Starting transactional processing
370
DotHibernate.startTransaction();
371
372         String JavaDoc ceoName = (String JavaDoc)request.getSession().getAttribute("ceoName");
373         String JavaDoc howDidYouHear = String.valueOf ((Long JavaDoc)request.getSession().getAttribute("howDidYouHear"));
374         
375         if (ceoName == null)
376             ceoName = "";
377         if (howDidYouHear == null)
378             howDidYouHear = "0";
379         registrationForm.setCeoName(ceoName);
380         registrationForm.setHowDidYouHear(howDidYouHear);
381         WebEventRegistration registration;
382         if (registrationForm.getInode() > 0){
383             registration = WebEventRegistrationFactory.getWebEventRegistration(registrationForm.getInode());
384         }
385         else{
386             registration = new WebEventRegistration();
387         }
388         ArrayList JavaDoc events = new ArrayList JavaDoc();
389         events.add(registration);
390         List JavaDoc<WebEventAttendee> attendees = WebEventAttendeeFactory.getWebEventAttendeesByEventRegistration(events);
391         for (WebEventAttendee attendee : attendees) {
392             InodeFactory.deleteInode(attendee);
393         }
394         registrationForm.setTotalDue(0);
395         registrationForm.setTotalPaid(0);
396         registrationForm.setTotalRegistration(0);
397         
398         
399         BeanUtils.copyProperties(registration, registrationForm);
400         
401         registration.setTotalPaid(0);
402         registration.setRegistrationStatus(Config.getIntProperty("EREG_INCOMPLETE"));
403         registrationForm.setRegistrationStatus(Config.getIntProperty("EREG_INCOMPLETE"));
404         InodeFactory.saveInode(registration);
405         registrationForm.setInode(registration.getInode());
406         request.setAttribute("registrationInode",String.valueOf(registration.getInode()));
407         // Saving attendees
408

409         float registrationAmount = 0;
410         List JavaDoc<WebEventAttendeeForm> attendeesForms = registrationForm.getEventAttendees();
411         for (WebEventAttendeeForm attendeeForm : attendeesForms) {
412             WebEventAttendee attendee = new WebEventAttendee();
413             BeanUtils.copyProperties(attendee, attendeeForm);
414             attendee.setEventRegistrationInode(registrationForm.getInode());
415             InodeFactory.saveInode(attendee);
416             registrationAmount += attendee.getRegistrationPrice();
417         }
418         registration.setTotalRegistration(registrationAmount);
419         registration.setTotalDue(registrationAmount);
420         InodeFactory.saveInode(registration);
421
422         //Commiting
423
DotHibernate.commitTransaction();
424         //------------------------------------------------------------------
425

426         return mapping.findForward("step2");
427     }
428
429     /**
430      * Place the registration order and forwards to the confirmation page
431      */

432     public ActionForward toStep3(ActionMapping mapping, ActionForm lf,
433             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
434             throws Exception JavaDoc {
435
436         try { // A big try catch to support unknown errors
437

438             WebEventRegistrationForm registrationForm = (WebEventRegistrationForm) lf;
439             
440
441             if (registrationForm.getEventLocationInode() == 0) {
442                 ActionForward forward = mapping.findForward("upcommingEvents");
443                 return forward;
444             }
445
446             if (!isTokenValid(request)) {
447
448                 // Duplicated transaction?
449
// waiting 2 min max for the transaction processing
450

451                 for (int i = 0; i < 120; i++) {
452                     ActionMessages messages = (ActionMessages) request.getSession().getAttribute(
453                                     WebKeys.WEBEVENTS_REG_ERRORS);
454                     if (messages != null && messages.size() > 0) {
455                         saveMessages(request, messages);
456                         request.getSession().removeAttribute(
457                                 WebKeys.WEBEVENTS_REG_ERRORS); //
458
// Token Generation to avoid transactions duplication
459
generateToken(request);
460                         saveToken(request);
461                         return mapping.findForward("step2");
462                     } else {
463                         WebEventRegistration registration = (WebEventRegistration) request
464                                 .getSession().getAttribute(
465                                         WebKeys.WEBEVENTS_REG_BEAN);
466                         if (registration != null) {
467                             ActionMessages ae = new ActionMessages();
468                             
469                             WebEvent event = WebEventFactory.getWebEvent(registrationForm.getEventInode());
470                             
471                             ae.add(Globals.ERROR_KEY,new ActionMessage("error.web_event.registration.already.processed2"));
472                             saveErrors(request, ae);
473                             if (event.isInstitute()) {
474                                 if (registration.getPaymentType() == 1)
475                                     return mapping.findForward("creditCardConfirmation");
476                                 else
477                                     return mapping.findForward("checkConfirmation");
478                             }
479                             else {
480                                 if (registration.getPaymentType() == 1)
481                                     return mapping.findForward("webinarCCConfirmation");
482                                 else
483                                     return mapping.findForward("webinarCheckConfirmation");
484                             }
485                         }
486                         Thread.sleep(1000);
487                     }
488                 }
489
490                 // No transaction processing found?
491
ActionMessages ae = new ActionMessages();
492                 ae.add(Globals.ERROR_KEY, new ActionMessage(
493                         "error.web_event.registration.already.processed"));
494                 saveErrors(request, ae);
495                 ActionForward forward = mapping
496                         .findForward("/dotCMS/myAccount");
497                 return forward;
498
499             }
500             resetToken(request);
501             request.getSession().removeAttribute(
502                     WebKeys.WEBEVENTS_REG_ERRORS);
503             request.getSession().removeAttribute(
504                     WebKeys.WEBEVENTS_REG_BEAN);
505
506             if (!Validator.validate(request, registrationForm, mapping)) {
507                 ActionMessages ae = getErrors(request);
508                 request.getSession().setAttribute(
509                         WebKeys.WEBEVENTS_REG_ERRORS, ae);
510                 generateToken(request);
511                 saveToken(request);
512                 return mapping.findForward("step2");
513             }
514
515             // Starting transactional processing
516
DotHibernate.startTransaction();
517                 
518             /*edg1
519             String ceoName = (String)request.getSession().getAttribute("ceoName");
520             String howDidYouHear = String.valueOf ((Long)request.getSession().getAttribute("howDidYouHear"));
521             if (ceoName == null)
522                 ceoName = "";
523             if (howDidYouHear == null)
524                 howDidYouHear = "0";
525             registrationForm.setCeoName(ceoName);
526             registrationForm.setHowDidYouHear(howDidYouHear);
527             
528             
529             // Saving registration
530             WebEventRegistration registration = new WebEventRegistration();
531             BeanUtils.copyProperties(registration, registrationForm);
532             edg1*/

533             
534             WebEventRegistration registration = null;
535             if(registrationForm.getInode() == 0){
536                 registration = WebEventRegistrationFactory.newInstance();
537             } else {
538                 registration = WebEventRegistrationFactory.getWebEventRegistration(registrationForm.getInode());
539             }
540             BeanUtils.copyProperties(registration, registrationForm);
541             //saving state in the registration
542
if (registration.getBillingState()!=null && registration.getBillingState().equals("otherCountry")) {
543                 registration.setBillingState(registrationForm.getBillingStateOtherCountryText());
544             }
545             
546             registration.setCardNumber(UtilMethods.obfuscateCreditCard(registrationForm.getCardNumber()));
547             registration.setCardVerificationValue("");
548             
549             InodeFactory.saveInode(registration);
550
551             // Getting registration Total
552
// WE DONT SAVE HERE AGAIN WE SAVED BEFORE... THIS WAS CREATING DUPLICATE ATTENDEES
553
float registrationAmount = 0;
554             List JavaDoc<WebEventAttendeeForm> attendeesForms = registrationForm.getEventAttendees();
555             for (WebEventAttendeeForm attendeeForm : attendeesForms) {
556                 registrationAmount += attendeeForm.getRegistrationPrice();
557             }
558
559             if (registrationForm.getPaymentType() == 1) {
560
561                 try {
562
563                     // updating amounts
564
registration.setTotalDue(0);
565                     registration.setTotalPaid(registrationAmount);
566                     registration.setTotalRegistration(registrationAmount);
567                     registration.setRegistrationStatus(Config.getIntProperty("EREG_PAID"));
568                     InodeFactory.saveInode(registration);
569
570                     // Place the credit card order, send the order to the credit
571
// card third party gateway
572
CreditCardProcessorResponse ccResponse = new CreditCardProcessorResponse("APPROVED", null, null, null, null, null, null, null, null, null);
573                     
574                     if (!Config.getStringProperty("TEST_CREDIT_CARD_NUMBER").equals(registrationForm.getCardNumber()) ||
575                         !Config.getStringProperty("TEST_CREDIT_CARD_TYPE").equals(registration.getCardType())) {
576                         ccResponse = CreditCardProcessor.processCreditCardOrderInstitutes(registration.getInode(),
577                                 null, true, request.getRemoteUser(), null, null,
578                                 null, (float)registrationAmount, registrationForm.getCardNumber(),
579                                 Integer.parseInt(registrationForm.getCardExpMonth()), Integer.parseInt(registrationForm.getCardExpYear()),
580                                 registrationForm.getCardVerificationValue(), registrationForm.getCardName(),
581                                 null, registrationForm.getBillingAddress1(), registrationForm.getBillingAddress2(),
582                                 registrationForm.getBillingCity(), registrationForm.getBillingState(),
583                                 registrationForm.getBillingZip(), registrationForm.getBillingCountry(),
584                                 registrationForm.getBillingContactPhone(), null, registrationForm.getBillingContactEmail(),
585                                 Config.getStringProperty("WEB_EVENT_REGISTRATION_COMMENTS"), "");
586                     }
587
588                     if (!ccResponse.orderApproved()) {
589                         DotHibernate.rollbackTransaction();
590                         ActionMessages ae = new ActionMessages();
591                         ae.add(Globals.ERROR_KEY, new ActionMessage(
592                                     "error.cc_processing.card.denied", ccResponse.getError()));
593                         saveErrors(request, ae);
594                         request.getSession().setAttribute(
595                                 WebKeys.WEBEVENTS_REG_ERRORS, ae);
596                         generateToken(request);
597                         saveToken(request);
598                         return mapping.findForward("step2");
599                     }
600                     
601                 } catch (CreditCardProcessorException e) {
602                     Logger.warn(this,
603                             "Credit card processor exception placing a credit card order: "
604                                     + e.getMessage(), e);
605                     DotHibernate.rollbackTransaction();
606                     ActionMessages ae = new ActionMessages();
607                     switch (e.getCode()) {
608                     case CreditCardProcessorException.DATA_MISSING:
609                         ae.add(Globals.ERROR_KEY, new ActionMessage(
610                                 "error.cc_processing.invalid.card.data"));
611                         break;
612                     case CreditCardProcessorException.COMMUNICATION_ERROR:
613                         ae.add(Globals.ERROR_KEY, new ActionMessage(
614                                 "error.cc_processing.communication.error"));
615                         break;
616                     default:
617                         ae.add(Globals.ERROR_KEY, new ActionMessage(
618                                 "error.cc_processing.unknown"));
619                     }
620                     saveErrors(request, ae);
621                     request.getSession().setAttribute(
622                             WebKeys.WEBEVENTS_REG_ERRORS, ae);
623                     generateToken(request);
624                     saveToken(request);
625                     return mapping.findForward("step2");
626                 } catch (Exception JavaDoc e) {
627                     Logger.error(this,
628                             "Unknown Error placing a credit card order: "
629                                     + e.getMessage(), e);
630                     DotHibernate.rollbackTransaction();
631                     ActionMessages ae = new ActionMessages();
632                     ae.add(Globals.ERROR_KEY, new ActionMessage(
633                             "error.cc_processing.unknown"));
634                     saveErrors(request, ae);
635                     request.getSession().setAttribute(
636                             WebKeys.WEBEVENTS_REG_ERRORS, ae);
637                     generateToken(request);
638                     saveToken(request);
639                     return mapping.findForward("step2");
640                 }
641
642             } else {
643                 // updating amounts
644
registration.setTotalDue(registrationAmount);
645                 registration.setTotalPaid(0);
646                 registration.setTotalRegistration(registrationAmount);
647                 registration.setRegistrationStatus(Config.getIntProperty("EREG_WAITING"));
648                 InodeFactory.saveInode(registration);
649             }
650
651             // Commiting
652
DotHibernate.commitTransaction();
653             request.removeAttribute("registrationInode");
654             // To be used in the confirmation page
655
request.getSession().setAttribute(
656                     WebKeys.WEBEVENTS_REG_BEAN, registration);
657
658             registrationForm.resetAllForm();
659             request.getSession().removeAttribute("ceoName");
660             request.getSession().removeAttribute("howDidYouHear");
661             // Send confirmation email
662
try {
663                 sendRegistrationReceipt(mapping, lf, request, response);
664             } catch (Exception JavaDoc e) {
665                 Logger.warn(this,"An error ocurred triying to send the confirmation email.",e);
666             }
667
668             // To the confirmation page
669
WebEvent event = WebEventFactory.getWebEvent(registration.getEventInode());
670             if (event.isInstitute()) {
671                 if (registration.getPaymentType() == 1)
672                     return mapping.findForward("creditCardConfirmation");
673                 else
674                     return mapping.findForward("checkConfirmation");
675             }
676             else {
677                 if (registration.getPaymentType() == 1)
678                     return mapping.findForward("webinarCCConfirmation");
679                 else
680                     return mapping.findForward("webinarCheckConfirmation");
681             }
682
683
684         } catch (Exception JavaDoc e) { // General exceptions catch
685
Logger.error(this, "Unknown Error placing an order: "
686                     + e.getMessage(), e);
687             DotHibernate.rollbackTransaction();
688             ActionMessages ae = new ActionMessages();
689             ae.add(Globals.ERROR_KEY, new ActionMessage(
690                     "error.cc_processing.unknown"));
691             saveErrors(request, ae);
692             request.getSession().setAttribute(
693                     WebKeys.WEBEVENTS_REG_ERRORS, ae);
694             generateToken(request);
695             saveToken(request);
696             return mapping.findForward("step2");
697         }
698     }
699
700     public static boolean sendRegistrationReceipt(ActionMapping mapping,
701             ActionForm lf, HttpServletRequest JavaDoc request,
702             HttpServletResponse JavaDoc response) {
703
704         WebEventRegistration registration = (WebEventRegistration) request.getSession().getAttribute(WebKeys.WEBEVENTS_REG_BEAN);
705
706         UserProxy proxy = UserProxyFactory.getUserProxy(registration.getUserInode());
707         User user = com.dotmarketing.cms.factories.PublicUserFactory.getUserByUserId(proxy.getUserId());
708
709         // build a decent default context
710
String JavaDoc path = "";
711         
712         WebEvent event = WebEventFactory.getWebEvent(registration.getEventInode());
713
714         if (event.isInstitute()) {
715             if (registration.getPaymentType() == 1)
716                 path = mapping.findForward("creditCardConfirmationEmail").getPath();
717             else
718                 path = mapping.findForward("checkConfirmationEmail").getPath();
719         }
720         else {
721             if (registration.getPaymentType() == 1)
722                 path = mapping.findForward("webinarCCConfirmationEmail").getPath();
723             else
724                 path = mapping.findForward("webinarCheckConfirmationEmail").getPath();
725         }
726
727         try {
728             StringBuffer JavaDoc writer = UtilMethods.getURL("http://"
729                     + HostFactory.getCurrentHost(request).getHostname() + path
730                     + "?registrationInode=" + registration.getInode());
731
732             String JavaDoc[] reportEmails = Config
733                     .getStringArrayProperty("BCCEMAIL_REGISTRATION_ADDRESSES");
734
735             StringBuffer JavaDoc bcc = new StringBuffer JavaDoc();
736             for (String JavaDoc email : reportEmails) {
737                 if (bcc.toString().length() > 0)
738                     bcc.append(", ");
739                 bcc.append(email);
740             }
741
742             Mailer m = new Mailer();
743             m.setToEmail(user.getEmailAddress());
744             m.setSubject(Config
745                     .getStringProperty("WEB_EVENT_REGISTRATION_EMAIL_TITLE"));
746             m.setHTMLBody(writer.toString().trim());
747             m.setFromEmail(Config.getStringProperty("EMAIL_REGISTRATION_ADDRESS"));
748             m.setBcc(bcc.toString());
749             m.sendMessage();
750
751             return true;
752         } catch (Exception JavaDoc e) {
753             e.printStackTrace(System.out);
754             return false;
755         }
756
757     }
758
759 }
Popular Tags