Subversion Repositories SmartDukaan

Rev

Rev 34168 | Rev 34181 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34168 Rev 34179
Line 539... Line 539...
539
 
539
 
540
        return "response";
540
        return "response";
541
    }
541
    }
542
 
542
 
543
    private void sendWhatsappInvoice(FofoOrder fofoOrder) throws Exception {
543
    private void sendWhatsappInvoice(FofoOrder fofoOrder) throws Exception {
-
 
544
        this.sendWhatsappInvoice(fofoOrder, "");
-
 
545
    }
-
 
546
 
-
 
547
    private void sendWhatsappInvoice(FofoOrder fofoOrder, String whatsAppNo) throws Exception {
544
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
548
        Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
545
        CustomRetailer retailer = retailerService.getFofoRetailer(fofoOrder.getFofoId());
549
        CustomRetailer retailer = retailerService.getFofoRetailer(fofoOrder.getFofoId());
546
        String message = String.format("Dear %s,\n" +
550
        String message = String.format("Dear %s,\n" +
547
                "Thank you for your purchase from SmartDukaan store - %s, %s.\n" +
551
                "Thank you for your purchase from SmartDukaan store - %s, %s.\n" +
548
                "Your purchase invoice is attached for your reference.\n" +
552
                "Your purchase invoice is attached for your reference.\n" +
Line 550... Line 554...
550
                "Download our app for offers and updates on new products.\n" +
554
                "Download our app for offers and updates on new products.\n" +
551
                "https://www.smartdukaan.com/b2c\n" +
555
                "https://www.smartdukaan.com/b2c\n" +
552
                "\n" +
556
                "\n" +
553
                "Best Regards\n" +
557
                "Best Regards\n" +
554
                "SmartDukaan", customer.getFirstName(), retailer.getBusinessName(), retailer.getAddress().getCity());
558
                "SmartDukaan", customer.getFirstName(), retailer.getBusinessName(), retailer.getAddress().getCity());
-
 
559
        String mobileNumber;
-
 
560
        if (!whatsAppNo.isEmpty()) {
-
 
561
            mobileNumber = whatsAppNo;
-
 
562
        } else {
-
 
563
            mobileNumber = customer.getMobileNumber();
-
 
564
        }
555
        boolean shouldSendWhatsappMessage = notificationService.shouldSendWhatsappMessage(customer.getMobileNumber());
565
        boolean shouldSendWhatsappMessage = notificationService.shouldSendWhatsappMessage(mobileNumber);
556
        if (shouldSendWhatsappMessage) {
566
        if (shouldSendWhatsappMessage) {
557
            notificationService.sendWhatsappMediaMessage(message, customer.getMobileNumber(), this.getPublicInvoiceUrl(fofoOrder.getInvoiceNumber()),
567
            notificationService.sendWhatsappMediaMessage(message, mobileNumber, this.getPublicInvoiceUrl(fofoOrder.getInvoiceNumber()),
558
                    this.getFileName(fofoOrder.getInvoiceNumber()), WhatsappMessageType.DOCUMENT);
568
                    this.getFileName(fofoOrder.getInvoiceNumber()), WhatsappMessageType.DOCUMENT);
559
        }
569
        }
560
    }
570
    }
561
 
571
 
562
    private String getFileName(String invoiceNumber) {
572
    private String getFileName(String invoiceNumber) {
Line 1155... Line 1165...
1155
        // throw new ProfitMandiBusinessException("Billing is on hold temporarily",
1165
        // throw new ProfitMandiBusinessException("Billing is on hold temporarily",
1156
        // "Billing is on hold temporarily", "Billing is on hold temporarily");
1166
        // "Billing is on hold temporarily", "Billing is on hold temporarily");
1157
        LOGGER.info("request at uri {}", request.getRequestURI());
1167
        LOGGER.info("request at uri {}", request.getRequestURI());
1158
        LOGGER.info("request body {}", createOrderRequest);
1168
        LOGGER.info("request body {}", createOrderRequest);
1159
        LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
1169
        LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
1160
 
-
 
1161
        int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
1170
        int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
1162
 
-
 
1163
        LOGGER.info("Order has been created successfully...");
1171
        LOGGER.info("Order has been created successfully...");
1164
        try {
-
 
1165
            this.sendWhatsappInvoice(fofoOrderRepository.selectByOrderId(fofoOrderId));
-
 
1166
        } catch (Exception e) {
-
 
1167
            LOGGER.info("Could not send whatsapp message");
-
 
1168
            e.printStackTrace();
-
 
1169
        }
1172
 
1170
        return "redirect:/get-order/?orderId=" + fofoOrderId;
1173
        return "redirect:/get-order/?orderId=" + fofoOrderId;
1171
    }
1174
    }
1172
 
1175
 
1173
    @GetMapping("/billedOrders")
1176
    @GetMapping("/billedOrders")
1174
    public String getBilledOrders(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
1177
    public String getBilledOrders(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
Line 1726... Line 1729...
1726
            order.setIrnGenerated(null);
1729
            order.setIrnGenerated(null);
1727
        });
1730
        });
1728
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1731
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
1729
        return "response";
1732
        return "response";
1730
    }
1733
    }
-
 
1734
 
-
 
1735
    @PutMapping (value = "/sendInvoiceOnWhatsApp")
-
 
1736
    public String sendInvoiceOnWhatsApp(HttpServletRequest request ,@RequestParam int orderId,@RequestParam String whatsAppMobile, Model model) throws Exception {
-
 
1737
        try {
-
 
1738
            this.sendWhatsappInvoice(fofoOrderRepository.selectByOrderId(orderId),whatsAppMobile);
-
 
1739
            model.addAttribute("response1", true);
-
 
1740
            LOGGER.info(" Invoice send on whatsapp");
-
 
1741
        } catch (Exception e) {
-
 
1742
            LOGGER.info("Invoice not send on whatsapp");
-
 
1743
            model.addAttribute("response1", false);
-
 
1744
            e.printStackTrace();
-
 
1745
        }
-
 
1746
        return "response";
-
 
1747
    }
-
 
1748
 
-
 
1749
 
1731
}
1750
}
1732
 
1751
 
1733
 
1752
 
1734
 
1753
 
1735
 
1754