use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderTotalApi method payment.
/**
* This service calculates order total for a given shopping cart This method takes in
* consideration any applicable sales tax An optional request parameter accepts a quote id that
* was received using shipping api
*
* @param quote
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/cart/{id}/total" }, method = RequestMethod.GET)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableOrderTotalSummary payment(@PathVariable final Long id, @RequestParam(value = "quote", required = false) Long quote, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(503, "Error while getting user details to calculate shipping quote");
}
ShoppingCart shoppingCart = shoppingCartFacade.getShoppingCartModel(id, merchantStore);
if (shoppingCart == null) {
response.sendError(404, "Cart id " + id + " does not exist");
return null;
}
if (shoppingCart.getCustomerId() == null) {
response.sendError(404, "Cart id " + id + " does not exist for exist for user " + userName);
return null;
}
if (shoppingCart.getCustomerId().longValue() != customer.getId().longValue()) {
response.sendError(404, "Cart id " + id + " does not exist for exist for user " + userName);
return null;
}
ShippingSummary shippingSummary = null;
// get shipping quote if asked for
if (quote != null) {
shippingSummary = shippingQuoteService.getShippingSummary(quote, merchantStore);
}
OrderTotalSummary orderTotalSummary = null;
OrderSummary orderSummary = new OrderSummary();
orderSummary.setShippingSummary(shippingSummary);
List<ShoppingCartItem> itemsSet = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems());
orderSummary.setProducts(itemsSet);
orderTotalSummary = orderService.caculateOrderTotal(orderSummary, customer, merchantStore, language);
ReadableOrderTotalSummary returnSummary = new ReadableOrderTotalSummary();
ReadableOrderSummaryPopulator populator = new ReadableOrderSummaryPopulator();
populator.setMessages(messages);
populator.setPricingService(pricingService);
populator.populate(orderTotalSummary, returnSummary, merchantStore, language);
return returnSummary;
} catch (Exception e) {
LOGGER.error("Error while calculating order summary", e);
try {
response.sendError(503, "Error while calculating order summary " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class AuthenticateCustomerApi method changePassword.
@RequestMapping(value = "/auth/customer/password", method = RequestMethod.POST, produces = { "application/json" })
@ApiOperation(httpMethod = "POST", value = "Sends a request to reset password", notes = "Password reset request is {\"username\":\"test@email.com\"}", response = ResponseEntity.class)
public ResponseEntity<?> changePassword(@RequestBody @Valid PasswordRequest passwordRequest, HttpServletRequest request) {
try {
MerchantStore merchantStore = storeFacade.getByCode(request);
Customer customer = customerFacade.getCustomerByUserName(passwordRequest.getUsername(), merchantStore);
if (customer == null) {
return ResponseEntity.notFound().build();
}
// need to validate if password matches
if (!customerFacade.passwordMatch(passwordRequest.getCurrent(), customer)) {
throw new ResourceNotFoundException("Username or password does not match");
}
if (!passwordRequest.getPassword().equals(passwordRequest.getRepeatPassword())) {
throw new ResourceNotFoundException("Both passwords do not match");
}
customerFacade.changePassword(customer, passwordRequest.getPassword());
return ResponseEntity.ok(Void.class);
} catch (Exception e) {
return ResponseEntity.badRequest().body("Exception when reseting password " + e.getMessage());
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class AuthenticateCustomerApi method setPassword.
@RequestMapping(value = "/private/customer/password", method = RequestMethod.PUT, produces = { "application/json" })
@ApiOperation(httpMethod = "PUT", value = "Change customer password", notes = "Change password request object is {\"username\":\"test@email.com\"}", response = ResponseEntity.class)
public ResponseEntity<?> setPassword(@RequestBody @Valid AuthenticationRequest authenticationRequest, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
String authenticatedUser = userFacade.authenticatedUser();
if (authenticatedUser == null) {
throw new UnauthorizedException();
}
userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
Customer customer = customerFacade.getCustomerByUserName(authenticationRequest.getUsername(), merchantStore);
if (customer == null) {
return ResponseEntity.notFound().build();
}
customerFacade.changePassword(customer, authenticationRequest.getPassword());
return ResponseEntity.ok(Void.class);
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerApi method delete.
@DeleteMapping("/auth/customer/")
@ApiOperation(httpMethod = "DELETE", value = "Deletes a loged in customer profile", notes = "Requires authentication", produces = "application/json", response = Void.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public void delete(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer;
try {
customer = customerFacade.getCustomerByUserName(userName, merchantStore);
if (customer == null) {
throw new ResourceNotFoundException("Customer [" + userName + "] not found");
}
customerFacade.delete(customer);
} catch (Exception e) {
throw new ServiceRuntimeException("An error occured while deleting customer [" + userName + "]");
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderApi method getOrder.
/**
* Get a given order by id
*
* @param id
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/orders/{id}" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrder getOrder(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while performing checkout customer not authorized");
return null;
}
ReadableOrder order = orderFacade.getReadableOrder(id, merchantStore, language);
if (order == null) {
LOGGER.error("Order is null for id " + id);
response.sendError(404, "Order is null for id " + id);
return null;
}
if (order.getCustomer() == null) {
LOGGER.error("Order is null for customer " + principal);
response.sendError(404, "Order is null for customer " + principal);
return null;
}
if (order.getCustomer().getId() != null && order.getCustomer().getId().longValue() != customer.getId().longValue()) {
LOGGER.error("Order is null for customer " + principal);
response.sendError(404, "Order is null for customer " + principal);
return null;
}
return order;
}
Aggregations