1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.shopping.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.security.permission.ActionKeys;
28  import com.liferay.portal.service.permission.PortletPermissionUtil;
29  import com.liferay.portal.util.PortletKeys;
30  import com.liferay.portlet.shopping.model.ShoppingOrder;
31  import com.liferay.portlet.shopping.service.base.ShoppingOrderServiceBaseImpl;
32  import com.liferay.portlet.shopping.service.permission.ShoppingOrderPermission;
33  
34  /**
35   * <a href="ShoppingOrderServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class ShoppingOrderServiceImpl extends ShoppingOrderServiceBaseImpl {
41  
42      public void completeOrder(
43              long plid, String number, String ppTxnId, String ppPaymentStatus,
44              double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
45          throws PortalException, SystemException {
46  
47          ShoppingOrder order = shoppingOrderPersistence.findByNumber(number);
48  
49          ShoppingOrderPermission.check(
50              getPermissionChecker(), plid, order.getOrderId(),
51              ActionKeys.UPDATE);
52  
53          shoppingOrderLocalService.completeOrder(
54              number, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
55              ppPayerEmail, false);
56      }
57  
58      public void deleteOrder(long plid, long orderId)
59          throws PortalException, SystemException {
60  
61          ShoppingOrderPermission.check(
62              getPermissionChecker(), plid, orderId, ActionKeys.DELETE);
63  
64          shoppingOrderLocalService.deleteOrder(orderId);
65      }
66  
67      public ShoppingOrder getOrder(long plid, long orderId)
68          throws PortalException, SystemException {
69  
70          ShoppingOrder order = shoppingOrderLocalService.getOrder(orderId);
71  
72          if (order.getUserId() == getUserId()) {
73              return order;
74          }
75          else {
76              PortletPermissionUtil.check(
77                  getPermissionChecker(), plid, PortletKeys.SHOPPING,
78                  ActionKeys.MANAGE_ORDERS);
79  
80              return order;
81          }
82      }
83  
84      public void sendEmail(long plid, long orderId, String emailType)
85          throws PortalException, SystemException {
86  
87          ShoppingOrderPermission.check(
88              getPermissionChecker(), plid, orderId, ActionKeys.UPDATE);
89  
90          shoppingOrderLocalService.sendEmail(orderId, emailType);
91      }
92  
93      public ShoppingOrder updateOrder(
94              long plid, long orderId, String billingFirstName,
95              String billingLastName, String billingEmailAddress,
96              String billingCompany, String billingStreet, String billingCity,
97              String billingState, String billingZip, String billingCountry,
98              String billingPhone, boolean shipToBilling,
99              String shippingFirstName, String shippingLastName,
100             String shippingEmailAddress, String shippingCompany,
101             String shippingStreet, String shippingCity, String shippingState,
102             String shippingZip, String shippingCountry, String shippingPhone,
103             String ccName, String ccType, String ccNumber, int ccExpMonth,
104             int ccExpYear, String ccVerNumber, String comments)
105         throws PortalException, SystemException {
106 
107         ShoppingOrderPermission.check(
108             getPermissionChecker(), plid, orderId, ActionKeys.UPDATE);
109 
110         return shoppingOrderLocalService.updateOrder(
111             orderId, billingFirstName, billingLastName, billingEmailAddress,
112             billingCompany, billingStreet, billingCity, billingState,
113             billingZip, billingCountry, billingPhone, shipToBilling,
114             shippingFirstName, shippingLastName, shippingEmailAddress,
115             shippingCompany, shippingStreet, shippingCity, shippingState,
116             shippingZip, shippingCountry, shippingPhone, ccName, ccType,
117             ccNumber, ccExpMonth, ccExpYear, ccVerNumber, comments);
118     }
119 
120     public ShoppingOrder updateOrder(
121             long plid, long orderId, String ppTxnId, String ppPaymentStatus,
122             double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
123         throws PortalException, SystemException {
124 
125         ShoppingOrderPermission.check(
126             getPermissionChecker(), plid, orderId, ActionKeys.UPDATE);
127 
128         return shoppingOrderLocalService.updateOrder(
129             orderId, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
130             ppPayerEmail);
131     }
132 
133 }