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