001    /**
002     * Copyright (c) 2000-present 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.security.permission.ActionKeys;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.shopping.model.ShoppingOrder;
021    import com.liferay.portlet.shopping.service.base.ShoppingOrderServiceBaseImpl;
022    import com.liferay.portlet.shopping.service.permission.ShoppingOrderPermission;
023    import com.liferay.portlet.shopping.service.permission.ShoppingPermission;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class ShoppingOrderServiceImpl extends ShoppingOrderServiceBaseImpl {
029    
030            @Override
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 {
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            @Override
049            public void deleteOrder(long groupId, long orderId) throws PortalException {
050                    ShoppingOrderPermission.check(
051                            getPermissionChecker(), groupId, orderId, ActionKeys.DELETE);
052    
053                    shoppingOrderLocalService.deleteOrder(orderId);
054            }
055    
056            @Override
057            public ShoppingOrder getOrder(long groupId, long orderId)
058                    throws PortalException {
059    
060                    ShoppingOrder order = shoppingOrderLocalService.getOrder(orderId);
061    
062                    if (order.getUserId() == getUserId()) {
063                            return order;
064                    }
065    
066                    ShoppingPermission.check(
067                            getPermissionChecker(), groupId, ActionKeys.MANAGE_ORDERS);
068    
069                    return order;
070            }
071    
072            @Override
073            public void sendEmail(
074                            long groupId, long orderId, String emailType,
075                            ServiceContext serviceContext)
076                    throws PortalException {
077    
078                    ShoppingOrderPermission.check(
079                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
080    
081                    shoppingOrderLocalService.sendEmail(orderId, emailType, serviceContext);
082            }
083    
084            @Override
085            public ShoppingOrder updateOrder(
086                            long groupId, long orderId, String ppTxnId, String ppPaymentStatus,
087                            double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
088                    throws PortalException {
089    
090                    ShoppingOrderPermission.check(
091                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
092    
093                    return shoppingOrderLocalService.updateOrder(
094                            orderId, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
095                            ppPayerEmail);
096            }
097    
098            @Override
099            public ShoppingOrder updateOrder(
100                            long groupId, long orderId, String billingFirstName,
101                            String billingLastName, String billingEmailAddress,
102                            String billingCompany, String billingStreet, String billingCity,
103                            String billingState, String billingZip, String billingCountry,
104                            String billingPhone, boolean shipToBilling,
105                            String shippingFirstName, String shippingLastName,
106                            String shippingEmailAddress, String shippingCompany,
107                            String shippingStreet, String shippingCity, String shippingState,
108                            String shippingZip, String shippingCountry, String shippingPhone,
109                            String ccName, String ccType, String ccNumber, int ccExpMonth,
110                            int ccExpYear, String ccVerNumber, String comments)
111                    throws PortalException {
112    
113                    ShoppingOrderPermission.check(
114                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
115    
116                    return shoppingOrderLocalService.updateOrder(
117                            orderId, billingFirstName, billingLastName, billingEmailAddress,
118                            billingCompany, billingStreet, billingCity, billingState,
119                            billingZip, billingCountry, billingPhone, shipToBilling,
120                            shippingFirstName, shippingLastName, shippingEmailAddress,
121                            shippingCompany, shippingStreet, shippingCity, shippingState,
122                            shippingZip, shippingCountry, shippingPhone, ccName, ccType,
123                            ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
124            }
125    
126    }