001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.shopping.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.mail.MailMessage;
026: import com.liferay.portal.kernel.util.GetterUtil;
027: import com.liferay.portal.kernel.util.StringUtil;
028: import com.liferay.portal.kernel.util.Validator;
029: import com.liferay.portal.model.Company;
030: import com.liferay.portal.model.User;
031: import com.liferay.portal.util.PortalUtil;
032: import com.liferay.portal.util.PortletKeys;
033: import com.liferay.portlet.shopping.BillingCityException;
034: import com.liferay.portlet.shopping.BillingCountryException;
035: import com.liferay.portlet.shopping.BillingEmailAddressException;
036: import com.liferay.portlet.shopping.BillingFirstNameException;
037: import com.liferay.portlet.shopping.BillingLastNameException;
038: import com.liferay.portlet.shopping.BillingPhoneException;
039: import com.liferay.portlet.shopping.BillingStateException;
040: import com.liferay.portlet.shopping.BillingStreetException;
041: import com.liferay.portlet.shopping.BillingZipException;
042: import com.liferay.portlet.shopping.CCExpirationException;
043: import com.liferay.portlet.shopping.CCNameException;
044: import com.liferay.portlet.shopping.CCNumberException;
045: import com.liferay.portlet.shopping.CCTypeException;
046: import com.liferay.portlet.shopping.CartMinOrderException;
047: import com.liferay.portlet.shopping.NoSuchOrderException;
048: import com.liferay.portlet.shopping.ShippingCityException;
049: import com.liferay.portlet.shopping.ShippingCountryException;
050: import com.liferay.portlet.shopping.ShippingEmailAddressException;
051: import com.liferay.portlet.shopping.ShippingFirstNameException;
052: import com.liferay.portlet.shopping.ShippingLastNameException;
053: import com.liferay.portlet.shopping.ShippingPhoneException;
054: import com.liferay.portlet.shopping.ShippingStateException;
055: import com.liferay.portlet.shopping.ShippingStreetException;
056: import com.liferay.portlet.shopping.ShippingZipException;
057: import com.liferay.portlet.shopping.model.ShoppingCart;
058: import com.liferay.portlet.shopping.model.ShoppingCartItem;
059: import com.liferay.portlet.shopping.model.ShoppingItem;
060: import com.liferay.portlet.shopping.model.ShoppingItemField;
061: import com.liferay.portlet.shopping.model.ShoppingOrder;
062: import com.liferay.portlet.shopping.model.ShoppingOrderItem;
063: import com.liferay.portlet.shopping.model.impl.ShoppingCartItemImpl;
064: import com.liferay.portlet.shopping.model.impl.ShoppingOrderImpl;
065: import com.liferay.portlet.shopping.service.base.ShoppingOrderLocalServiceBaseImpl;
066: import com.liferay.portlet.shopping.util.ShoppingPreferences;
067: import com.liferay.portlet.shopping.util.ShoppingUtil;
068: import com.liferay.portlet.shopping.util.comparator.OrderDateComparator;
069: import com.liferay.util.CreditCard;
070: import com.liferay.util.PwdGenerator;
071: import com.liferay.util.cal.CalendarUtil;
072:
073: import java.io.IOException;
074:
075: import java.util.Currency;
076: import java.util.Date;
077: import java.util.Iterator;
078: import java.util.List;
079: import java.util.Map;
080:
081: import javax.mail.internet.InternetAddress;
082:
083: /**
084: * <a href="ShoppingOrderLocalServiceImpl.java.html"><b><i>View Source</i></b>
085: * </a>
086: *
087: * @author Brian Wing Shun Chan
088: *
089: */
090: public class ShoppingOrderLocalServiceImpl extends
091: ShoppingOrderLocalServiceBaseImpl {
092:
093: public void completeOrder(String number, String ppTxnId,
094: String ppPaymentStatus, double ppPaymentGross,
095: String ppReceiverEmail, String ppPayerEmail,
096: boolean updateInventory) throws PortalException,
097: SystemException {
098:
099: // Order
100:
101: ShoppingOrder order = shoppingOrderPersistence
102: .findByNumber(number);
103:
104: order.setModifiedDate(new Date());
105: order.setPpTxnId(ppTxnId);
106: order.setPpPaymentStatus(ppPaymentStatus);
107: order.setPpPaymentGross(ppPaymentGross);
108: order.setPpReceiverEmail(ppReceiverEmail);
109: order.setPpPayerEmail(ppPayerEmail);
110:
111: shoppingOrderPersistence.update(order);
112:
113: // Inventory
114:
115: if (updateInventory
116: && ppPaymentStatus
117: .equals(ShoppingOrderImpl.STATUS_COMPLETED)) {
118:
119: List orderItems = shoppingOrderItemLocalService
120: .getOrderItems(order.getOrderId());
121:
122: for (int i = 0; i < orderItems.size(); i++) {
123: ShoppingOrderItem orderItem = (ShoppingOrderItem) orderItems
124: .get(i);
125:
126: ShoppingItem item = shoppingItemLocalService
127: .getItem(ShoppingUtil.getItemId(orderItem
128: .getItemId()));
129:
130: if (!item.isFields()) {
131: int quantity = item.getStockQuantity()
132: - orderItem.getQuantity();
133:
134: item.setStockQuantity(quantity);
135: } else {
136: List itemFields = shoppingItemFieldLocalService
137: .getItemFields(item.getItemId());
138:
139: ShoppingItemField[] itemFieldsArray = (ShoppingItemField[]) itemFields
140: .toArray(new ShoppingItemField[0]);
141:
142: String[] fieldsArray = ShoppingCartItemImpl
143: .getFieldsArray(ShoppingUtil
144: .getItemFields(orderItem
145: .getItemId()));
146:
147: int rowPos = ShoppingUtil.getFieldsQuantitiesPos(
148: item, itemFieldsArray, fieldsArray);
149:
150: String[] fieldsQuantities = item
151: .getFieldsQuantitiesArray();
152:
153: try {
154: int quantity = GetterUtil
155: .getInteger(fieldsQuantities[rowPos])
156: - orderItem.getQuantity();
157:
158: fieldsQuantities[rowPos] = Integer
159: .toString(quantity);
160:
161: item.setFieldsQuantitiesArray(fieldsQuantities);
162: } catch (Exception e) {
163: }
164: }
165:
166: shoppingItemPersistence.update(item);
167: }
168: }
169:
170: // Email
171:
172: sendEmail(order, "confirmation");
173: }
174:
175: public void deleteOrder(long orderId) throws PortalException,
176: SystemException {
177:
178: ShoppingOrder order = shoppingOrderPersistence
179: .findByPrimaryKey(orderId);
180:
181: deleteOrder(order);
182: }
183:
184: public void deleteOrder(ShoppingOrder order)
185: throws PortalException, SystemException {
186:
187: // Items
188:
189: shoppingOrderItemPersistence
190: .removeByOrderId(order.getOrderId());
191:
192: // Message boards
193:
194: mbMessageLocalService.deleteDiscussionMessages(
195: ShoppingOrder.class.getName(), order.getOrderId());
196:
197: // Order
198:
199: shoppingOrderPersistence.remove(order.getOrderId());
200: }
201:
202: public void deleteOrders(long groupId) throws PortalException,
203: SystemException {
204:
205: Iterator itr = shoppingOrderPersistence.findByGroupId(groupId)
206: .iterator();
207:
208: while (itr.hasNext()) {
209: ShoppingOrder order = (ShoppingOrder) itr.next();
210:
211: deleteOrder(order);
212: }
213: }
214:
215: public ShoppingOrder getLatestOrder(long userId, long groupId)
216: throws PortalException, SystemException {
217:
218: List orders = shoppingOrderPersistence.findByG_U_PPPS(groupId,
219: userId, ShoppingOrderImpl.STATUS_LATEST, 0, 1);
220:
221: ShoppingOrder order = null;
222:
223: if (orders.size() == 1) {
224: order = (ShoppingOrder) orders.get(0);
225: } else {
226: User user = userPersistence.findByPrimaryKey(userId);
227: Date now = new Date();
228:
229: String number = getNumber();
230:
231: List pastOrders = shoppingOrderPersistence.findByG_U_PPPS(
232: groupId, userId, ShoppingOrderImpl.STATUS_CHECKOUT,
233: 0, 1);
234:
235: if (pastOrders.size() > 0) {
236: ShoppingOrder pastOrder = (ShoppingOrder) pastOrders
237: .get(0);
238:
239: long orderId = counterLocalService.increment();
240:
241: order = shoppingOrderPersistence.create(orderId);
242:
243: order.setBillingCompany(pastOrder.getBillingCompany());
244: order.setBillingStreet(pastOrder.getBillingStreet());
245: order.setBillingCity(pastOrder.getBillingCity());
246: order.setBillingState(pastOrder.getBillingState());
247: order.setBillingZip(pastOrder.getBillingZip());
248: order.setBillingCountry(pastOrder.getBillingCountry());
249: order.setBillingPhone(pastOrder.getBillingPhone());
250: order.setShipToBilling(pastOrder.isShipToBilling());
251: order
252: .setShippingCompany(pastOrder
253: .getShippingCompany());
254: order.setShippingStreet(pastOrder.getShippingStreet());
255: order.setShippingCity(pastOrder.getShippingCity());
256: order.setShippingState(pastOrder.getShippingState());
257: order.setShippingZip(pastOrder.getShippingZip());
258: order
259: .setShippingCountry(pastOrder
260: .getShippingCountry());
261: order.setShippingPhone(pastOrder.getShippingPhone());
262: } else {
263: long orderId = counterLocalService.increment();
264:
265: order = shoppingOrderPersistence.create(orderId);
266: }
267:
268: order.setGroupId(groupId);
269: order.setCompanyId(user.getCompanyId());
270: order.setUserId(user.getUserId());
271: order.setUserName(user.getFullName());
272: order.setCreateDate(now);
273: order.setModifiedDate(now);
274: order.setNumber(number);
275: order.setBillingFirstName(user.getFirstName());
276: order.setBillingLastName(user.getLastName());
277: order.setBillingEmailAddress(user.getEmailAddress());
278: order.setShippingFirstName(user.getFirstName());
279: order.setShippingLastName(user.getLastName());
280: order.setShippingEmailAddress(user.getEmailAddress());
281: order.setCcName(user.getFullName());
282: order.setPpPaymentStatus(ShoppingOrderImpl.STATUS_LATEST);
283: order.setSendOrderEmail(true);
284: order.setSendShippingEmail(true);
285:
286: shoppingOrderPersistence.update(order);
287: }
288:
289: return order;
290: }
291:
292: public ShoppingOrder getOrder(long orderId) throws PortalException,
293: SystemException {
294:
295: return shoppingOrderPersistence.findByPrimaryKey(orderId);
296: }
297:
298: public ShoppingOrder getOrder(String number)
299: throws PortalException, SystemException {
300:
301: return shoppingOrderPersistence.findByNumber(number);
302: }
303:
304: public ShoppingOrder saveLatestOrder(ShoppingCart cart)
305: throws PortalException, SystemException {
306:
307: Map items = cart.getItems();
308: Date now = new Date();
309:
310: ShoppingPreferences shoppingPrefs = ShoppingPreferences
311: .getInstance(cart.getCompanyId(), cart.getGroupId());
312:
313: if (!ShoppingUtil.meetsMinOrder(shoppingPrefs, items)) {
314: throw new CartMinOrderException();
315: }
316:
317: ShoppingOrder order = getLatestOrder(cart.getUserId(), cart
318: .getGroupId());
319:
320: order.setCreateDate(now);
321: order.setModifiedDate(now);
322: order.setPpPaymentStatus(ShoppingOrderImpl.STATUS_CHECKOUT);
323:
324: shoppingOrderPersistence.update(order);
325:
326: boolean requiresShipping = false;
327:
328: Iterator itr = items.entrySet().iterator();
329:
330: while (itr.hasNext()) {
331: Map.Entry entry = (Map.Entry) itr.next();
332:
333: ShoppingCartItem cartItem = (ShoppingCartItem) entry
334: .getKey();
335: Integer count = (Integer) entry.getValue();
336:
337: ShoppingItem item = cartItem.getItem();
338:
339: if (item.isRequiresShipping()) {
340: requiresShipping = true;
341: }
342:
343: long orderItemId = counterLocalService.increment();
344:
345: ShoppingOrderItem orderItem = shoppingOrderItemPersistence
346: .create(orderItemId);
347:
348: orderItem.setOrderId(order.getOrderId());
349: orderItem.setItemId(cartItem.getCartItemId());
350: orderItem.setSku(item.getSku());
351: orderItem.setName(item.getName());
352: orderItem.setDescription(item.getDescription());
353: orderItem.setProperties(item.getProperties());
354: orderItem.setPrice(ShoppingUtil.calculateActualPrice(item,
355: count.intValue())
356: / count.intValue());
357: orderItem.setQuantity(count.intValue());
358:
359: shoppingOrderItemPersistence.update(orderItem);
360: }
361:
362: order.setModifiedDate(new Date());
363: order.setTax(ShoppingUtil.calculateTax(items, order
364: .getBillingState()));
365: order.setShipping(ShoppingUtil.calculateAlternativeShipping(
366: items, cart.getAltShipping()));
367: order.setAltShipping(shoppingPrefs
368: .getAlternativeShippingName(cart.getAltShipping()));
369: order.setRequiresShipping(requiresShipping);
370: order.setInsure(cart.isInsure());
371: order.setInsurance(ShoppingUtil.calculateInsurance(items));
372: order.setCouponCodes(cart.getCouponCodes());
373: order.setCouponDiscount(ShoppingUtil.calculateCouponDiscount(
374: items, order.getBillingState(), cart.getCoupon()));
375: order.setSendOrderEmail(true);
376: order.setSendShippingEmail(true);
377:
378: shoppingOrderPersistence.update(order);
379:
380: return order;
381: }
382:
383: public List search(long groupId, long companyId, long userId,
384: String number, String billingFirstName,
385: String billingLastName, String billingEmailAddress,
386: String shippingFirstName, String shippingLastName,
387: String shippingEmailAddress, String ppPaymentStatus,
388: boolean andOperator, int begin, int end)
389: throws PortalException, SystemException {
390:
391: OrderDateComparator obc = new OrderDateComparator(false);
392:
393: return shoppingOrderFinder.findByG_C_U_N_PPPS(groupId,
394: companyId, userId, number, billingFirstName,
395: billingLastName, billingEmailAddress,
396: shippingFirstName, shippingLastName,
397: shippingEmailAddress, ppPaymentStatus, andOperator,
398: begin, end, obc);
399: }
400:
401: public int searchCount(long groupId, long companyId, long userId,
402: String number, String billingFirstName,
403: String billingLastName, String billingEmailAddress,
404: String shippingFirstName, String shippingLastName,
405: String shippingEmailAddress, String ppPaymentStatus,
406: boolean andOperator) throws PortalException,
407: SystemException {
408:
409: return shoppingOrderFinder.countByG_C_U_N_PPPS(groupId,
410: companyId, userId, number, billingFirstName,
411: billingLastName, billingEmailAddress,
412: shippingFirstName, shippingLastName,
413: shippingEmailAddress, ppPaymentStatus, andOperator);
414: }
415:
416: public void sendEmail(long orderId, String emailType)
417: throws PortalException, SystemException {
418:
419: ShoppingOrder order = shoppingOrderPersistence
420: .findByPrimaryKey(orderId);
421:
422: sendEmail(order, emailType);
423: }
424:
425: public void sendEmail(ShoppingOrder order, String emailType)
426: throws PortalException, SystemException {
427:
428: try {
429: ShoppingPreferences shoppingPrefs = ShoppingPreferences
430: .getInstance(order.getCompanyId(), order
431: .getGroupId());
432:
433: if (emailType.equals("confirmation")
434: && shoppingPrefs.getEmailOrderConfirmationEnabled()) {
435: } else if (emailType.equals("shipping")
436: && shoppingPrefs.getEmailOrderShippingEnabled()) {
437: } else {
438: return;
439: }
440:
441: Company company = companyPersistence.findByPrimaryKey(order
442: .getCompanyId());
443:
444: User user = userPersistence.findByPrimaryKey(order
445: .getUserId());
446:
447: Currency currency = Currency.getInstance(shoppingPrefs
448: .getCurrencyId());
449:
450: String billingAddress = order.getBillingFirstName() + " "
451: + order.getBillingLastName() + "<br>"
452: + order.getBillingEmailAddress() + "<br>"
453: + order.getBillingStreet() + "<br>"
454: + order.getBillingCity() + "<br>"
455: + order.getBillingState() + "<br>"
456: + order.getBillingZip() + "<br>"
457: + order.getBillingCountry() + "<br>"
458: + order.getBillingPhone() + "<br>";
459:
460: String shippingAddress = order.getShippingFirstName() + " "
461: + order.getShippingLastName() + "<br>"
462: + order.getShippingEmailAddress() + "<br>"
463: + order.getShippingStreet() + "<br>"
464: + order.getShippingCity() + "<br>"
465: + order.getShippingState() + "<br>"
466: + order.getShippingZip() + "<br>"
467: + order.getShippingCountry() + "<br>"
468: + order.getShippingPhone() + "<br>";
469:
470: double total = ShoppingUtil.calculateTotal(order);
471:
472: String portletName = PortalUtil.getPortletTitle(
473: PortletKeys.SHOPPING, user);
474:
475: String fromName = shoppingPrefs.getEmailFromName();
476: String fromAddress = shoppingPrefs.getEmailFromAddress();
477:
478: String toName = user.getFullName();
479: String toAddress = user.getEmailAddress();
480:
481: String subject = null;
482: String body = null;
483:
484: if (emailType.equals("confirmation")) {
485: subject = shoppingPrefs
486: .getEmailOrderConfirmationSubject();
487: body = shoppingPrefs.getEmailOrderConfirmationBody();
488: } else if (emailType.equals("shipping")) {
489: subject = shoppingPrefs.getEmailOrderShippingSubject();
490: body = shoppingPrefs.getEmailOrderShippingBody();
491: }
492:
493: subject = StringUtil.replace(subject,
494: new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]",
495: "[$ORDER_BILLING_ADDRESS$]",
496: "[$ORDER_CURRENCY$]", "[$ORDER_NUMBER$]",
497: "[$ORDER_SHIPPING_ADDRESS$]",
498: "[$ORDER_TOTAL$]", "[$PORTAL_URL$]",
499: "[$PORTLET_NAME$]", "[$TO_ADDRESS$]",
500: "[$TO_NAME$]" }, new String[] {
501: fromAddress, fromName, billingAddress,
502: currency.getSymbol(), order.getNumber(),
503: shippingAddress, String.valueOf(total),
504: company.getVirtualHost(), portletName,
505: toAddress, toName });
506:
507: body = StringUtil.replace(body,
508: new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]",
509: "[$ORDER_BILLING_ADDRESS$]",
510: "[$ORDER_CURRENCY$]", "[$ORDER_NUMBER$]",
511: "[$ORDER_SHIPPING_ADDRESS$]",
512: "[$ORDER_TOTAL$]", "[$PORTAL_URL$]",
513: "[$PORTLET_NAME$]", "[$TO_ADDRESS$]",
514: "[$TO_NAME$]" }, new String[] {
515: fromAddress, fromName, billingAddress,
516: currency.getSymbol(), order.getNumber(),
517: shippingAddress, String.valueOf(total),
518: company.getVirtualHost(), portletName,
519: toAddress, toName });
520:
521: InternetAddress from = new InternetAddress(fromAddress,
522: fromName);
523:
524: InternetAddress to = new InternetAddress(toAddress, toName);
525:
526: MailMessage message = new MailMessage(from, to, subject,
527: body, true);
528:
529: mailService.sendEmail(message);
530:
531: if (emailType.equals("confirmation")
532: && order.isSendOrderEmail()) {
533: order.setSendOrderEmail(false);
534:
535: shoppingOrderPersistence.update(order);
536: } else if (emailType.equals("shipping")
537: && order.isSendShippingEmail()) {
538:
539: order.setSendShippingEmail(false);
540:
541: shoppingOrderPersistence.update(order);
542: }
543: } catch (IOException ioe) {
544: throw new SystemException(ioe);
545: } catch (PortalException pe) {
546: throw pe;
547: }
548: }
549:
550: public ShoppingOrder updateLatestOrder(long userId, long groupId,
551: String billingFirstName, String billingLastName,
552: String billingEmailAddress, String billingCompany,
553: String billingStreet, String billingCity,
554: String billingState, String billingZip,
555: String billingCountry, String billingPhone,
556: boolean shipToBilling, String shippingFirstName,
557: String shippingLastName, String shippingEmailAddress,
558: String shippingCompany, String shippingStreet,
559: String shippingCity, String shippingState,
560: String shippingZip, String shippingCountry,
561: String shippingPhone, String ccName, String ccType,
562: String ccNumber, int ccExpMonth, int ccExpYear,
563: String ccVerNumber, String comments)
564: throws PortalException, SystemException {
565:
566: ShoppingOrder order = getLatestOrder(userId, groupId);
567:
568: return updateOrder(order.getOrderId(), billingFirstName,
569: billingLastName, billingEmailAddress, billingCompany,
570: billingStreet, billingCity, billingState, billingZip,
571: billingCountry, billingPhone, shipToBilling,
572: shippingFirstName, shippingLastName,
573: shippingEmailAddress, shippingCompany, shippingStreet,
574: shippingCity, shippingState, shippingZip,
575: shippingCountry, shippingPhone, ccName, ccType,
576: ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
577: }
578:
579: public ShoppingOrder updateOrder(long orderId,
580: String billingFirstName, String billingLastName,
581: String billingEmailAddress, String billingCompany,
582: String billingStreet, String billingCity,
583: String billingState, String billingZip,
584: String billingCountry, String billingPhone,
585: boolean shipToBilling, String shippingFirstName,
586: String shippingLastName, String shippingEmailAddress,
587: String shippingCompany, String shippingStreet,
588: String shippingCity, String shippingState,
589: String shippingZip, String shippingCountry,
590: String shippingPhone, String ccName, String ccType,
591: String ccNumber, int ccExpMonth, int ccExpYear,
592: String ccVerNumber, String comments)
593: throws PortalException, SystemException {
594:
595: ShoppingOrder order = shoppingOrderPersistence
596: .findByPrimaryKey(orderId);
597:
598: ShoppingPreferences shoppingPrefs = ShoppingPreferences
599: .getInstance(order.getCompanyId(), order.getGroupId());
600:
601: validate(shoppingPrefs, billingFirstName, billingLastName,
602: billingEmailAddress, billingStreet, billingCity,
603: billingState, billingZip, billingCountry, billingPhone,
604: shipToBilling, shippingFirstName, shippingLastName,
605: shippingEmailAddress, shippingStreet, shippingCity,
606: shippingState, shippingZip, shippingCountry,
607: shippingPhone, ccName, ccType, ccNumber, ccExpMonth,
608: ccExpYear, ccVerNumber);
609:
610: order.setModifiedDate(new Date());
611: order.setBillingFirstName(billingFirstName);
612: order.setBillingLastName(billingLastName);
613: order.setBillingEmailAddress(billingEmailAddress);
614: order.setBillingCompany(billingCompany);
615: order.setBillingStreet(billingStreet);
616: order.setBillingCity(billingCity);
617: order.setBillingState(billingState);
618: order.setBillingZip(billingZip);
619: order.setBillingCountry(billingCountry);
620: order.setBillingPhone(billingPhone);
621: order.setShipToBilling(shipToBilling);
622:
623: if (shipToBilling) {
624: order.setShippingFirstName(billingFirstName);
625: order.setShippingLastName(billingLastName);
626: order.setShippingEmailAddress(billingEmailAddress);
627: order.setShippingCompany(billingCompany);
628: order.setShippingStreet(billingStreet);
629: order.setShippingCity(billingCity);
630: order.setShippingState(billingState);
631: order.setShippingZip(billingZip);
632: order.setShippingCountry(billingCountry);
633: order.setShippingPhone(billingPhone);
634: } else {
635: order.setShippingFirstName(shippingFirstName);
636: order.setShippingLastName(shippingLastName);
637: order.setShippingEmailAddress(shippingEmailAddress);
638: order.setShippingCompany(shippingCompany);
639: order.setShippingStreet(shippingStreet);
640: order.setShippingCity(shippingCity);
641: order.setShippingState(shippingState);
642: order.setShippingZip(shippingZip);
643: order.setShippingCountry(shippingCountry);
644: order.setShippingPhone(shippingPhone);
645: }
646:
647: order.setCcName(ccName);
648: order.setCcType(ccType);
649: order.setCcNumber(ccNumber);
650: order.setCcExpMonth(ccExpMonth);
651: order.setCcExpYear(ccExpYear);
652: order.setCcVerNumber(ccVerNumber);
653: order.setComments(comments);
654:
655: shoppingOrderPersistence.update(order);
656:
657: return order;
658: }
659:
660: public ShoppingOrder updateOrder(long orderId, String ppTxnId,
661: String ppPaymentStatus, double ppPaymentGross,
662: String ppReceiverEmail, String ppPayerEmail)
663: throws PortalException, SystemException {
664:
665: ShoppingOrder order = shoppingOrderPersistence
666: .findByPrimaryKey(orderId);
667:
668: order.setModifiedDate(new Date());
669: order.setPpTxnId(ppTxnId);
670: order.setPpPaymentStatus(ppPaymentStatus);
671: order.setPpPaymentGross(ppPaymentGross);
672: order.setPpReceiverEmail(ppReceiverEmail);
673: order.setPpPayerEmail(ppPayerEmail);
674:
675: shoppingOrderPersistence.update(order);
676:
677: return order;
678: }
679:
680: protected String getNumber() throws SystemException {
681: String number = PwdGenerator.getPassword(PwdGenerator.KEY1
682: + PwdGenerator.KEY2, 12);
683:
684: try {
685: shoppingOrderPersistence.findByNumber(number);
686:
687: return getNumber();
688: } catch (NoSuchOrderException nsoe) {
689: return number;
690: }
691: }
692:
693: protected void validate(ShoppingPreferences shoppingPrefs,
694: String billingFirstName, String billingLastName,
695: String billingEmailAddress, String billingStreet,
696: String billingCity, String billingState, String billingZip,
697: String billingCountry, String billingPhone,
698: boolean shipToBilling, String shippingFirstName,
699: String shippingLastName, String shippingEmailAddress,
700: String shippingStreet, String shippingCity,
701: String shippingState, String shippingZip,
702: String shippingCountry, String shippingPhone,
703: String ccName, String ccType, String ccNumber,
704: int ccExpMonth, int ccExpYear, String ccVerNumber)
705: throws PortalException {
706:
707: if (Validator.isNull(billingFirstName)) {
708: throw new BillingFirstNameException();
709: } else if (Validator.isNull(billingLastName)) {
710: throw new BillingLastNameException();
711: } else if (!Validator.isEmailAddress(billingEmailAddress)) {
712: throw new BillingEmailAddressException();
713: } else if (Validator.isNull(billingStreet)) {
714: throw new BillingStreetException();
715: } else if (Validator.isNull(billingCity)) {
716: throw new BillingCityException();
717: } else if (Validator.isNull(billingState)) {
718: throw new BillingStateException();
719: } else if (Validator.isNull(billingZip)) {
720: throw new BillingZipException();
721: } else if (Validator.isNull(billingCountry)) {
722: throw new BillingCountryException();
723: } else if (Validator.isNull(billingPhone)) {
724: throw new BillingPhoneException();
725: }
726:
727: if (!shipToBilling) {
728: if (Validator.isNull(shippingFirstName)) {
729: throw new ShippingFirstNameException();
730: } else if (Validator.isNull(shippingLastName)) {
731: throw new ShippingLastNameException();
732: } else if (!Validator.isEmailAddress(shippingEmailAddress)) {
733: throw new ShippingEmailAddressException();
734: } else if (Validator.isNull(shippingStreet)) {
735: throw new ShippingStreetException();
736: } else if (Validator.isNull(shippingCity)) {
737: throw new ShippingCityException();
738: } else if (Validator.isNull(shippingState)) {
739: throw new ShippingStateException();
740: } else if (Validator.isNull(shippingZip)) {
741: throw new ShippingZipException();
742: } else if (Validator.isNull(shippingCountry)) {
743: throw new ShippingCountryException();
744: } else if (Validator.isNull(shippingPhone)) {
745: throw new ShippingPhoneException();
746: }
747: }
748:
749: if ((!shoppingPrefs.usePayPal())
750: && (shoppingPrefs.getCcTypes().length > 0)) {
751:
752: if (Validator.isNull(ccName)) {
753: throw new CCNameException();
754: } else if (Validator.isNull(ccType)) {
755: throw new CCTypeException();
756: } else if (!CreditCard.isValid(ccNumber, ccType)) {
757: throw new CCNumberException();
758: } else if (!CalendarUtil.isFuture(ccExpMonth, ccExpYear)) {
759: throw new CCExpirationException();
760: }
761: }
762: }
763:
764: }
|