001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.shopping.model.ShoppingOrder;
022    import com.liferay.portlet.shopping.service.base.ShoppingOrderServiceBaseImpl;
023    import com.liferay.portlet.shopping.service.permission.ShoppingOrderPermission;
024    import com.liferay.portlet.shopping.service.permission.ShoppingPermission;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ShoppingOrderServiceImpl extends ShoppingOrderServiceBaseImpl {
030    
031            public void completeOrder(
032                            long groupId, String number, String ppTxnId, String ppPaymentStatus,
033                            double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail,
034                            ServiceContext serviceContext)
035                    throws PortalException, SystemException {
036    
037                    ShoppingOrder order = shoppingOrderPersistence.findByNumber(number);
038    
039                    ShoppingOrderPermission.check(
040                            getPermissionChecker(), groupId, order.getOrderId(),
041                            ActionKeys.UPDATE);
042    
043                    shoppingOrderLocalService.completeOrder(
044                            number, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
045                            ppPayerEmail, false, serviceContext);
046            }
047    
048            public void deleteOrder(long groupId, long orderId)
049                    throws PortalException, SystemException {
050    
051                    ShoppingOrderPermission.check(
052                            getPermissionChecker(), groupId, orderId, ActionKeys.DELETE);
053    
054                    shoppingOrderLocalService.deleteOrder(orderId);
055            }
056    
057            public ShoppingOrder getOrder(long groupId, long orderId)
058                    throws PortalException, SystemException {
059    
060                    ShoppingOrder order = shoppingOrderLocalService.getOrder(orderId);
061    
062                    if (order.getUserId() == getUserId()) {
063                            return order;
064                    }
065                    else {
066                            ShoppingPermission.check(
067                                    getPermissionChecker(), groupId, ActionKeys.MANAGE_ORDERS);
068    
069                            return order;
070                    }
071            }
072    
073            public void sendEmail(
074                            long groupId, long orderId, String emailType,
075                            ServiceContext serviceContext)
076                    throws PortalException, SystemException {
077    
078                    ShoppingOrderPermission.check(
079                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
080    
081                    shoppingOrderLocalService.sendEmail(orderId, emailType, serviceContext);
082            }
083    
084            public ShoppingOrder updateOrder(
085                            long groupId, long orderId, String ppTxnId, String ppPaymentStatus,
086                            double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
087                    throws PortalException, SystemException {
088    
089                    ShoppingOrderPermission.check(
090                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
091    
092                    return shoppingOrderLocalService.updateOrder(
093                            orderId, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
094                            ppPayerEmail);
095            }
096    
097            public ShoppingOrder updateOrder(
098                            long groupId, long orderId, String billingFirstName,
099                            String billingLastName, String billingEmailAddress,
100                            String billingCompany, String billingStreet, String billingCity,
101                            String billingState, String billingZip, String billingCountry,
102                            String billingPhone, boolean shipToBilling,
103                            String shippingFirstName, String shippingLastName,
104                            String shippingEmailAddress, String shippingCompany,
105                            String shippingStreet, String shippingCity, String shippingState,
106                            String shippingZip, String shippingCountry, String shippingPhone,
107                            String ccName, String ccType, String ccNumber, int ccExpMonth,
108                            int ccExpYear, String ccVerNumber, String comments)
109                    throws PortalException, SystemException {
110    
111                    ShoppingOrderPermission.check(
112                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
113    
114                    return shoppingOrderLocalService.updateOrder(
115                            orderId, billingFirstName, billingLastName, billingEmailAddress,
116                            billingCompany, billingStreet, billingCity, billingState,
117                            billingZip, billingCountry, billingPhone, shipToBilling,
118                            shippingFirstName, shippingLastName, shippingEmailAddress,
119                            shippingCompany, shippingStreet, shippingCity, shippingState,
120                            shippingZip, shippingCountry, shippingPhone, ccName, ccType,
121                            ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
122            }
123    
124    }