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                    else {
069                            ShoppingPermission.check(
070                                    getPermissionChecker(), groupId, ActionKeys.MANAGE_ORDERS);
071    
072                            return order;
073                    }
074            }
075    
076            @Override
077            public void sendEmail(
078                            long groupId, long orderId, String emailType,
079                            ServiceContext serviceContext)
080                    throws PortalException, SystemException {
081    
082                    ShoppingOrderPermission.check(
083                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
084    
085                    shoppingOrderLocalService.sendEmail(orderId, emailType, serviceContext);
086            }
087    
088            @Override
089            public ShoppingOrder updateOrder(
090                            long groupId, long orderId, String ppTxnId, String ppPaymentStatus,
091                            double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
092                    throws PortalException, SystemException {
093    
094                    ShoppingOrderPermission.check(
095                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
096    
097                    return shoppingOrderLocalService.updateOrder(
098                            orderId, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
099                            ppPayerEmail);
100            }
101    
102            @Override
103            public ShoppingOrder updateOrder(
104                            long groupId, long orderId, String billingFirstName,
105                            String billingLastName, String billingEmailAddress,
106                            String billingCompany, String billingStreet, String billingCity,
107                            String billingState, String billingZip, String billingCountry,
108                            String billingPhone, boolean shipToBilling,
109                            String shippingFirstName, String shippingLastName,
110                            String shippingEmailAddress, String shippingCompany,
111                            String shippingStreet, String shippingCity, String shippingState,
112                            String shippingZip, String shippingCountry, String shippingPhone,
113                            String ccName, String ccType, String ccNumber, int ccExpMonth,
114                            int ccExpYear, String ccVerNumber, String comments)
115                    throws PortalException, SystemException {
116    
117                    ShoppingOrderPermission.check(
118                            getPermissionChecker(), groupId, orderId, ActionKeys.UPDATE);
119    
120                    return shoppingOrderLocalService.updateOrder(
121                            orderId, billingFirstName, billingLastName, billingEmailAddress,
122                            billingCompany, billingStreet, billingCity, billingState,
123                            billingZip, billingCountry, billingPhone, shipToBilling,
124                            shippingFirstName, shippingLastName, shippingEmailAddress,
125                            shippingCompany, shippingStreet, shippingCity, shippingState,
126                            shippingZip, shippingCountry, shippingPhone, ccName, ccType,
127                            ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
128            }
129    
130    }