001    /**
002     * Copyright (c) 2000-2013 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            @Override
032            public void completeOrder(
033                            long groupId, String number, String ppTxnId, String ppPaymentStatus,
034                            double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail,
035                            ServiceContext serviceContext)
036                    throws PortalException, SystemException {
037    
038                    ShoppingOrder order = shoppingOrderPersistence.findByNumber(number);
039    
040                    ShoppingOrderPermission.check(
041                            getPermissionChecker(), groupId, order.getOrderId(),
042                            ActionKeys.UPDATE);
043    
044                    shoppingOrderLocalService.completeOrder(
045                            number, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
046                            ppPayerEmail, false, serviceContext);
047            }
048    
049            @Override
050            public void deleteOrder(long groupId, long orderId)
051                    throws PortalException, SystemException {
052    
053                    ShoppingOrderPermission.check(
054                            getPermissionChecker(), groupId, orderId, ActionKeys.DELETE);
055    
056                    shoppingOrderLocalService.deleteOrder(orderId);
057            }
058    
059            @Override
060            public ShoppingOrder getOrder(long groupId, long orderId)
061                    throws PortalException, SystemException {
062    
063                    ShoppingOrder order = shoppingOrderLocalService.getOrder(orderId);
064    
065                    if (order.getUserId() == getUserId()) {
066                            return order;
067                    }
068    
069                    ShoppingPermission.check(
070                            getPermissionChecker(), groupId, ActionKeys.MANAGE_ORDERS);
071    
072                    return order;
073            }
074    
075            @Override
076            public void sendEmail(
077                            long groupId, long orderId, String emailType,
078                            ServiceContext serviceContext)
079                    throws PortalException, SystemException {
080    
081                    ShoppingOrderPermission.check(
082                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
083    
084                    shoppingOrderLocalService.sendEmail(orderId, emailType, serviceContext);
085            }
086    
087            @Override
088            public ShoppingOrder updateOrder(
089                            long groupId, long orderId, String ppTxnId, String ppPaymentStatus,
090                            double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
091                    throws PortalException, SystemException {
092    
093                    ShoppingOrderPermission.check(
094                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
095    
096                    return shoppingOrderLocalService.updateOrder(
097                            orderId, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
098                            ppPayerEmail);
099            }
100    
101            @Override
102            public ShoppingOrder updateOrder(
103                            long groupId, long orderId, String billingFirstName,
104                            String billingLastName, String billingEmailAddress,
105                            String billingCompany, String billingStreet, String billingCity,
106                            String billingState, String billingZip, String billingCountry,
107                            String billingPhone, boolean shipToBilling,
108                            String shippingFirstName, String shippingLastName,
109                            String shippingEmailAddress, String shippingCompany,
110                            String shippingStreet, String shippingCity, String shippingState,
111                            String shippingZip, String shippingCountry, String shippingPhone,
112                            String ccName, String ccType, String ccNumber, int ccExpMonth,
113                            int ccExpYear, String ccVerNumber, String comments)
114                    throws PortalException, SystemException {
115    
116                    ShoppingOrderPermission.check(
117                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
118    
119                    return shoppingOrderLocalService.updateOrder(
120                            orderId, billingFirstName, billingLastName, billingEmailAddress,
121                            billingCompany, billingStreet, billingCity, billingState,
122                            billingZip, billingCountry, billingPhone, shipToBilling,
123                            shippingFirstName, shippingLastName, shippingEmailAddress,
124                            shippingCompany, shippingStreet, shippingCity, shippingState,
125                            shippingZip, shippingCountry, shippingPhone, ccName, ccType,
126                            ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
127            }
128    
129    }