1   /**
2    * Copyright (c) 2000-2007 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.kernel.security.permission.ActionKeys;
28  import com.liferay.portal.service.impl.PrincipalBean;
29  import com.liferay.portal.service.permission.PortletPermissionUtil;
30  import com.liferay.portal.util.PortletKeys;
31  import com.liferay.portlet.shopping.model.ShoppingOrder;
32  import com.liferay.portlet.shopping.service.ShoppingOrderLocalServiceUtil;
33  import com.liferay.portlet.shopping.service.ShoppingOrderService;
34  import com.liferay.portlet.shopping.service.permission.ShoppingOrderPermission;
35  import com.liferay.portlet.shopping.service.persistence.ShoppingOrderUtil;
36  
37  /**
38   * <a href="ShoppingOrderServiceImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   *
42   */
43  public class ShoppingOrderServiceImpl
44      extends PrincipalBean implements ShoppingOrderService {
45  
46      public void completeOrder(
47              long plid, String number, String ppTxnId, String ppPaymentStatus,
48              double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
49          throws PortalException, SystemException {
50  
51          ShoppingOrder order = ShoppingOrderUtil.findByNumber(number);
52  
53          ShoppingOrderPermission.check(
54              getPermissionChecker(), plid, order.getOrderId(),
55              ActionKeys.UPDATE);
56  
57          ShoppingOrderLocalServiceUtil.completeOrder(
58              number, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
59              ppPayerEmail, false);
60      }
61  
62      public void deleteOrder(long plid, long orderId)
63          throws PortalException, SystemException {
64  
65          ShoppingOrderPermission.check(
66              getPermissionChecker(), plid, orderId, ActionKeys.DELETE);
67  
68          ShoppingOrderLocalServiceUtil.deleteOrder(orderId);
69      }
70  
71      public ShoppingOrder getOrder(long plid, long orderId)
72          throws PortalException, SystemException {
73  
74          ShoppingOrder order = ShoppingOrderLocalServiceUtil.getOrder(orderId);
75  
76          if (order.getUserId() == getUserId()) {
77              return order;
78          }
79          else {
80              PortletPermissionUtil.check(
81                  getPermissionChecker(), plid, PortletKeys.SHOPPING,
82                  ActionKeys.MANAGE_ORDERS);
83  
84              return order;
85          }
86      }
87  
88      public void sendEmail(long plid, long orderId, String emailType)
89          throws PortalException, SystemException {
90  
91          ShoppingOrderPermission.check(
92              getPermissionChecker(), plid, orderId, ActionKeys.UPDATE);
93  
94          ShoppingOrderLocalServiceUtil.sendEmail(orderId, emailType);
95      }
96  
97      public ShoppingOrder updateOrder(
98              long plid, long orderId, String billingFirstName,
99              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(), plid, orderId, ActionKeys.UPDATE);
113 
114         return ShoppingOrderLocalServiceUtil.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     public ShoppingOrder updateOrder(
125             long plid, long orderId, String ppTxnId, String ppPaymentStatus,
126             double ppPaymentGross, String ppReceiverEmail, String ppPayerEmail)
127         throws PortalException, SystemException {
128 
129         ShoppingOrderPermission.check(
130             getPermissionChecker(), plid, orderId, ActionKeys.UPDATE);
131 
132         return ShoppingOrderLocalServiceUtil.updateOrder(
133             orderId, ppTxnId, ppPaymentStatus, ppPaymentGross, ppReceiverEmail,
134             ppPayerEmail);
135     }
136 
137 }