Class OrderServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.OrderServiceImpl
-
- All Implemented Interfaces:
OrderService
@Service public class OrderServiceImpl extends java.lang.Object implements OrderService
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description OrderServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAttachment(java.lang.String orderId, Attachment attachment)
Adds attachment to the last timeline.boolean
approve(java.lang.String orderId)
Approves order.java.util.Map<java.lang.String,java.lang.Object>
calculateItemsTotalBruttoAmount(java.lang.String orderId)
Calculates total gross amount for order.java.util.Map<java.lang.String,java.lang.Object>
calculatePayoutAmount(java.lang.String orderId)
Calculates payout amount for order.java.util.Map<java.lang.String,java.lang.Object>
calculateServiceFeeBruttoAmount(java.lang.String orderId)
Calculates service fee for order.java.util.Map<java.lang.String,java.lang.Object>
calculateTaxAmountPrice(java.lang.String orderId)
Calculates tax amount for order.java.util.Map<java.lang.String,java.lang.Object>
calculateTotalPrice(java.lang.String orderId)
Sums prices of commerce items.boolean
canAddAttachment(java.lang.String orderId)
Checks if current user can add an Attachment.private boolean
canCancel(OrderStatus status)
boolean
canCancel(java.lang.String orderId)
Checks if order is cancelable.boolean
cancel(java.lang.String orderId)
Cancels an order.boolean
canChangeStatus(java.lang.String orderId)
Checks if current user can change the status of given order.boolean
changeAddress(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)
Changes shipping address of the order.boolean
changePaymentMethod(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.String> pmParams)
Changes payment method for the order's payment intent.private Order
changeStatus(java.lang.String orderId, OrderStatus status, SellerType nextStepPerformer)
private boolean
checkTransition(OrderStatus newStatus, OrderStatus oldStatus)
Attachment
createInvoiceBuyerToVendor(java.lang.String orderId)
This method make an invoice from buyer to vendorjava.util.List<OrderDTO>
createOrdersFromShoppingCart(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)
Create list of orders from shopping cart.private java.util.List<OrderTimeLineBean>
createTimeLineList(java.lang.String orderId)
boolean
deliver(java.lang.String orderId)
Deliver order.java.lang.String
getInvoiceTemplate(java.lang.String orderId)
This method makes the process of compiling the invoice templateOrderTimeLineBean
getLastOrderTimelineBean(java.lang.String orderId)
This method returns bean.private Address
getOrCreateAddress(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params, Seller buyer)
private java.lang.String
getOrCreatePaymentMethod(java.util.Map<java.lang.String,java.lang.String> pmParams)
OrderDTO
getOrder(java.lang.String orderId)
Gets order by id.java.util.List<OrderDTO>
getOrders()
Retrieves orders of current user.java.util.List<OrderTimeLineBean>
getOrderTimeLine(java.lang.String orderId)
This method returns beans as list.OrderRepository
getRepository()
java.util.Set<Address>
getShippingAddresses()
Get saved shipping addresses.private Order.Tax
getTax(Seller buyer, Seller seller, java.util.Map<java.lang.String,com.stripe.model.TaxRate> taxRates)
boolean
isUserParticipatesInOrder(java.lang.String orderId, boolean asVendor)
This method checks is database entity belong to other database entity.private OrderDTO
mapOrder(Order order)
boolean
mustAddAttachments(java.lang.String orderId)
Checks if attachments must be added on the current step but currently absent.java.lang.String
obtain3DSecureLink(java.lang.String orderId)
Obtains a payment authorization link;private java.util.Map<CommerceItem,Inventory>
obtainItemToInventoryMap(java.util.List<CommerceItem> items)
private java.util.Map<Seller,java.util.List<CommerceItem>>
obtainSellerToItemsMap(ShoppingCart cart)
java.util.List<OrderDTO>
orderCheckout()
Checkout the orders for the given shopping cart id.PaymentStatus
pay(java.lang.String orderId)
Commits payment for the order.java.lang.String
payout(java.lang.String orderId)
Commits payout.boolean
prepareItemsToShipment(java.util.List<CommerceItem> items)
This method does reserve for the items which are paid already.boolean
removeAttachment(java.lang.String orderId, java.lang.String attachmentName)
Removes attachment from the last timeline.boolean
removeCommerceItemFromOrder(java.lang.String orderId, java.lang.String commerceItemId)
This method removes relationship between database entities.void
removeOrder(java.lang.String orderId)
This method removes database entities.void
sendOrderConfirmationEmail(java.util.LinkedHashMap<java.lang.String,java.lang.Object> emailData)
Sends a success email for the order.boolean
ship(java.lang.String orderId)
Ships order.private boolean
updateInventoriesLockedQuantity(java.util.Map<CommerceItem,Inventory> map, boolean increase)
private boolean
updateInventoriesOnShip(java.util.Map<CommerceItem,Inventory> map)
private void
updateItems(Order order, java.util.List<CommerceItem> items)
-
-
-
Field Detail
-
sellerRepository
@Autowired private SellerRepository sellerRepository
-
orderRepository
@Autowired private OrderRepository orderRepository
-
accessManagementService
@Autowired private AccessManagementService accessManagementService
-
inventoryRepository
@Autowired private InventoryRepository inventoryRepository
-
commerceItemRepository
@Autowired private CommerceItemRepository commerceItemRepository
-
sequenceGenerator
@Autowired private SequenceGeneratorService sequenceGenerator
-
commerceProperties
@Autowired private CommerceProperties commerceProperties
-
commerceItemService
@Autowired private CommerceItemService commerceItemService
-
shoppingCartRepository
@Autowired private ShoppingCartRepository shoppingCartRepository
-
shoppingCartService
@Autowired private ShoppingCartService shoppingCartService
-
geoLocationService
@Autowired private GeoLocationService geoLocationService
-
stripeService
@Autowired private StripeService stripeService
-
stripeConnectService
@Autowired private StripeConnectService stripeConnectService
-
commonProperties
@Autowired private CommonProperties commonProperties
-
templateLocatorService
@Autowired private TemplateLocatorService templateLocatorService
-
pageRenderService
@Autowired private PageRenderService pageRenderService
-
frameworkOperationService
@Autowired private FrameworkOperationService frameworkOperationService
-
fileManagerService
@Autowired private co.mastermindcms.modules.filestorage.services.FileManagerService fileManagerService
-
billingService
@Autowired private BillingService billingService
-
emailSenderService
@Autowired private EmailSenderService emailSenderService
-
emailProperties
@Autowired private EmailProperties emailProperties
-
mapper
private static final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Method Detail
-
getRepository
public OrderRepository getRepository()
- Specified by:
getRepository
in interfaceOrderService
-
createOrdersFromShoppingCart
@Transactional public java.util.List<OrderDTO> createOrdersFromShoppingCart(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)
Description copied from interface:OrderService
Create list of orders from shopping cart. Orders includeCommerceItem
-s grouped bySeller
. So for items CommerceItem1 (with Seller1), CommerceItem2 (with Seller1) and CommerceItem3 (with Seller2) will be created 2 Orders - with [CommerceItem1, CommerceItem2] and [CommerceItem3] respectively.- Specified by:
createOrdersFromShoppingCart
in interfaceOrderService
- Parameters:
params
- params, including key-values: shippingAddress - id orAddress
fields as a map paymentMethod - id orPaymentMethod
fields as a map- Returns:
- list of Order DTOs
-
orderCheckout
public java.util.List<OrderDTO> orderCheckout()
Description copied from interface:OrderService
Checkout the orders for the given shopping cart id.- Specified by:
orderCheckout
in interfaceOrderService
- Returns:
- the list of OrderDTOs representing the checked out orders
-
sendOrderConfirmationEmail
public void sendOrderConfirmationEmail(java.util.LinkedHashMap<java.lang.String,java.lang.Object> emailData)
Description copied from interface:OrderService
Sends a success email for the order.This method sends a success email for the order specified by the given email message.
- Specified by:
sendOrderConfirmationEmail
in interfaceOrderService
- Parameters:
emailData
- the email message object containing the details of the success email
-
getTax
private Order.Tax getTax(Seller buyer, Seller seller, java.util.Map<java.lang.String,com.stripe.model.TaxRate> taxRates)
-
getOrCreateAddress
private Address getOrCreateAddress(java.util.LinkedHashMap<java.lang.String,java.lang.Object> params, Seller buyer)
-
createInvoiceBuyerToVendor
public Attachment createInvoiceBuyerToVendor(java.lang.String orderId)
Description copied from interface:OrderService
This method make an invoice from buyer to vendor- Specified by:
createInvoiceBuyerToVendor
in interfaceOrderService
- Parameters:
orderId
- order- Returns:
- value as attachment
-
getOrCreatePaymentMethod
private java.lang.String getOrCreatePaymentMethod(java.util.Map<java.lang.String,java.lang.String> pmParams)
-
createTimeLineList
private java.util.List<OrderTimeLineBean> createTimeLineList(java.lang.String orderId)
-
obtainSellerToItemsMap
private java.util.Map<Seller,java.util.List<CommerceItem>> obtainSellerToItemsMap(ShoppingCart cart)
-
obtainItemToInventoryMap
private java.util.Map<CommerceItem,Inventory> obtainItemToInventoryMap(java.util.List<CommerceItem> items)
-
updateItems
private void updateItems(Order order, java.util.List<CommerceItem> items)
-
updateInventoriesLockedQuantity
private boolean updateInventoriesLockedQuantity(java.util.Map<CommerceItem,Inventory> map, boolean increase)
-
updateInventoriesOnShip
private boolean updateInventoriesOnShip(java.util.Map<CommerceItem,Inventory> map)
-
removeOrder
@Transactional public void removeOrder(java.lang.String orderId)
Description copied from interface:OrderService
This method removes database entities.- Specified by:
removeOrder
in interfaceOrderService
- Parameters:
orderId
- identification for database entity which will be removed
-
removeCommerceItemFromOrder
@Transactional public boolean removeCommerceItemFromOrder(java.lang.String orderId, java.lang.String commerceItemId)
Description copied from interface:OrderService
This method removes relationship between database entities.- Specified by:
removeCommerceItemFromOrder
in interfaceOrderService
- Parameters:
orderId
- identification for database entity which will be removedcommerceItemId
- identification for database entity which will be updated- Returns:
- the status of the action, whether it was successful or not
-
getOrders
@Transactional public java.util.List<OrderDTO> getOrders()
Description copied from interface:OrderService
Retrieves orders of current user.- Specified by:
getOrders
in interfaceOrderService
- Returns:
- order
-
getOrder
@Transactional public OrderDTO getOrder(java.lang.String orderId)
Description copied from interface:OrderService
Gets order by id.- Specified by:
getOrder
in interfaceOrderService
- Parameters:
orderId
- identification for filter and return data- Returns:
- order DTO
-
approve
public boolean approve(java.lang.String orderId)
Description copied from interface:OrderService
Approves order.- Specified by:
approve
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
pay
@Transactional public PaymentStatus pay(java.lang.String orderId)
Description copied from interface:OrderService
Commits payment for the order.- Specified by:
pay
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- status of the payment
-
obtain3DSecureLink
public java.lang.String obtain3DSecureLink(java.lang.String orderId)
Description copied from interface:OrderService
Obtains a payment authorization link;- Specified by:
obtain3DSecureLink
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- the link
-
ship
public boolean ship(java.lang.String orderId)
Description copied from interface:OrderService
Ships order.- Specified by:
ship
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
deliver
public boolean deliver(java.lang.String orderId)
Description copied from interface:OrderService
Deliver order.- Specified by:
deliver
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
payout
public java.lang.String payout(java.lang.String orderId)
Description copied from interface:OrderService
Commits payout.- Specified by:
payout
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- status of the payout
-
cancel
public boolean cancel(java.lang.String orderId)
Description copied from interface:OrderService
Cancels an order.- Specified by:
cancel
in interfaceOrderService
- Parameters:
orderId
- order id- Returns:
- true on success
-
changeStatus
private Order changeStatus(java.lang.String orderId, OrderStatus status, SellerType nextStepPerformer)
-
checkTransition
private boolean checkTransition(OrderStatus newStatus, OrderStatus oldStatus)
-
getOrderTimeLine
public java.util.List<OrderTimeLineBean> getOrderTimeLine(java.lang.String orderId)
Description copied from interface:OrderService
This method returns beans as list.- Specified by:
getOrderTimeLine
in interfaceOrderService
- Parameters:
orderId
- identification for database entity which related beans list be returned- Returns:
- beans as list
-
isUserParticipatesInOrder
public boolean isUserParticipatesInOrder(java.lang.String orderId, boolean asVendor)
Description copied from interface:OrderService
This method checks is database entity belong to other database entity.- Specified by:
isUserParticipatesInOrder
in interfaceOrderService
- Parameters:
orderId
- identification for database entity which will be checkedasVendor
-true
- for checking as vendor,false
- if as buyer- Returns:
- value as boolean
-
getLastOrderTimelineBean
public OrderTimeLineBean getLastOrderTimelineBean(java.lang.String orderId)
Description copied from interface:OrderService
This method returns bean.- Specified by:
getLastOrderTimelineBean
in interfaceOrderService
- Parameters:
orderId
- identification for database entity which found last bean and returned- Returns:
- bean
-
addAttachment
public boolean addAttachment(java.lang.String orderId, Attachment attachment)
Description copied from interface:OrderService
Adds attachment to the last timeline.- Specified by:
addAttachment
in interfaceOrderService
- Parameters:
orderId
- id of the orderattachment
- attachment- Returns:
- success or not
-
removeAttachment
public boolean removeAttachment(java.lang.String orderId, java.lang.String attachmentName)
Description copied from interface:OrderService
Removes attachment from the last timeline.- Specified by:
removeAttachment
in interfaceOrderService
- Parameters:
orderId
- id of the orderattachmentName
- attachment name- Returns:
- success or not
-
getShippingAddresses
public java.util.Set<Address> getShippingAddresses()
Description copied from interface:OrderService
Get saved shipping addresses.- Specified by:
getShippingAddresses
in interfaceOrderService
- Returns:
- addresses set
-
canCancel
public boolean canCancel(java.lang.String orderId)
Description copied from interface:OrderService
Checks if order is cancelable.- Specified by:
canCancel
in interfaceOrderService
- Parameters:
orderId
- id of the order- Returns:
- true if order status could be changed to
OrderStatus.CANCELED
orOrderStatus.DENIED
-
canCancel
private boolean canCancel(OrderStatus status)
-
canAddAttachment
public boolean canAddAttachment(java.lang.String orderId)
Description copied from interface:OrderService
Checks if current user can add an Attachment.- Specified by:
canAddAttachment
in interfaceOrderService
- Parameters:
orderId
- order ID- Returns:
- true if the user has rights to add an attachment to the order.
-
changeAddress
@Transactional public boolean changeAddress(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.Object> params)
Description copied from interface:OrderService
Changes shipping address of the order.- Specified by:
changeAddress
in interfaceOrderService
- Parameters:
orderId
- order idparams
- params of address- Returns:
- true if successful
-
changePaymentMethod
@Transactional public boolean changePaymentMethod(java.lang.String orderId, java.util.LinkedHashMap<java.lang.String,java.lang.String> pmParams)
Description copied from interface:OrderService
Changes payment method for the order's payment intent.- Specified by:
changePaymentMethod
in interfaceOrderService
- Parameters:
orderId
- order idpmParams
- params of a new payment intent- Returns:
- true if successful
-
canChangeStatus
public boolean canChangeStatus(java.lang.String orderId)
Description copied from interface:OrderService
Checks if current user can change the status of given order.- Specified by:
canChangeStatus
in interfaceOrderService
- Parameters:
orderId
- order- Returns:
- true if user can change the status
-
mustAddAttachments
public boolean mustAddAttachments(java.lang.String orderId)
Description copied from interface:OrderService
Checks if attachments must be added on the current step but currently absent.- Specified by:
mustAddAttachments
in interfaceOrderService
- Parameters:
orderId
- order- Returns:
- true if attachments must be added
-
prepareItemsToShipment
public boolean prepareItemsToShipment(java.util.List<CommerceItem> items)
Description copied from interface:OrderService
This method does reserve for the items which are paid already.- Specified by:
prepareItemsToShipment
in interfaceOrderService
- Parameters:
items
- commerce items which will be reserved- Returns:
- true if it successful
-
getInvoiceTemplate
public java.lang.String getInvoiceTemplate(java.lang.String orderId)
Description copied from interface:OrderService
This method makes the process of compiling the invoice template- Specified by:
getInvoiceTemplate
in interfaceOrderService
- Parameters:
orderId
- order- Returns:
- compiled invoice template as a string
-
calculateTotalPrice
public java.util.Map<java.lang.String,java.lang.Object> calculateTotalPrice(java.lang.String orderId)
Description copied from interface:OrderService
Sums prices of commerce items.- Specified by:
calculateTotalPrice
in interfaceOrderService
- Parameters:
orderId
- order identifier- Returns:
- items total amount as map-property
-
calculateTaxAmountPrice
public java.util.Map<java.lang.String,java.lang.Object> calculateTaxAmountPrice(java.lang.String orderId)
Description copied from interface:OrderService
Calculates tax amount for order.- Specified by:
calculateTaxAmountPrice
in interfaceOrderService
- Parameters:
orderId
- order identifier- Returns:
- tax amount as map-property
-
calculateItemsTotalBruttoAmount
public java.util.Map<java.lang.String,java.lang.Object> calculateItemsTotalBruttoAmount(java.lang.String orderId)
Description copied from interface:OrderService
Calculates total gross amount for order.- Specified by:
calculateItemsTotalBruttoAmount
in interfaceOrderService
- Parameters:
orderId
- order identifier- Returns:
- order gross amount as map-property
-
calculateServiceFeeBruttoAmount
public java.util.Map<java.lang.String,java.lang.Object> calculateServiceFeeBruttoAmount(java.lang.String orderId)
Description copied from interface:OrderService
Calculates service fee for order.- Specified by:
calculateServiceFeeBruttoAmount
in interfaceOrderService
- Parameters:
orderId
- order identifier- Returns:
- service fee amount as map-property
-
calculatePayoutAmount
public java.util.Map<java.lang.String,java.lang.Object> calculatePayoutAmount(java.lang.String orderId)
Description copied from interface:OrderService
Calculates payout amount for order.- Specified by:
calculatePayoutAmount
in interfaceOrderService
- Parameters:
orderId
- order identifier- Returns:
- payout amount as map-property
-
-