Subversion Repositories SmartDukaan

Rev

Rev 36024 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36024 Rev 36064
Line 57... Line 57...
57
import com.spice.profitmandi.service.transaction.SDCreditService;
57
import com.spice.profitmandi.service.transaction.SDCreditService;
58
import com.spice.profitmandi.service.transaction.TransactionService;
58
import com.spice.profitmandi.service.transaction.TransactionService;
59
import com.spice.profitmandi.service.user.RetailerService;
59
import com.spice.profitmandi.service.user.RetailerService;
60
import com.spice.profitmandi.service.wallet.WalletService;
60
import com.spice.profitmandi.service.wallet.WalletService;
61
import com.spice.profitmandi.service.whatsapp.WhatsappMessageService;
61
import com.spice.profitmandi.service.whatsapp.WhatsappMessageService;
62
import com.spice.profitmandi.service.whatsapp.WhatsappMessageType;
-
 
63
import com.spice.profitmandi.web.model.LoginDetails;
62
import com.spice.profitmandi.web.model.LoginDetails;
64
import com.spice.profitmandi.web.util.CookiesProcessor;
63
import com.spice.profitmandi.web.util.CookiesProcessor;
65
import com.spice.profitmandi.web.util.MVCResponseSender;
64
import com.spice.profitmandi.web.util.MVCResponseSender;
66
import in.shop2020.model.v1.order.WalletReferenceType;
65
import in.shop2020.model.v1.order.WalletReferenceType;
67
import org.apache.logging.log4j.LogManager;
66
import org.apache.logging.log4j.LogManager;
Line 82... Line 81...
82
 
81
 
83
import javax.mail.MessagingException;
82
import javax.mail.MessagingException;
84
import javax.servlet.http.HttpServletRequest;
83
import javax.servlet.http.HttpServletRequest;
85
import javax.servlet.http.HttpServletResponse;
84
import javax.servlet.http.HttpServletResponse;
86
import java.io.*;
85
import java.io.*;
87
import java.nio.charset.StandardCharsets;
-
 
88
import java.nio.file.Files;
86
import java.nio.file.Files;
89
import java.time.LocalDate;
87
import java.time.LocalDate;
90
import java.time.LocalDateTime;
88
import java.time.LocalDateTime;
91
import java.time.format.DateTimeFormatter;
89
import java.time.format.DateTimeFormatter;
92
import java.time.temporal.ChronoUnit;
90
import java.time.temporal.ChronoUnit;
Line 231... Line 229...
231
    PinelabsOfferCacheService pinelabsOfferCacheService;
229
    PinelabsOfferCacheService pinelabsOfferCacheService;
232
 
230
 
233
    @RequestMapping(value = "/wa-send-invoice", method = RequestMethod.GET)
231
    @RequestMapping(value = "/wa-send-invoice", method = RequestMethod.GET)
234
    public String sendWhatsappMessage(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) {
232
    public String sendWhatsappMessage(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) {
235
        try {
233
        try {
236
            this.sendWhatsappInvoice(fofoOrderRepository.selectByOrderId(orderId));
234
            FofoOrder fo = fofoOrderRepository.selectByOrderId(orderId);
-
 
235
            notificationService.sendWhatsappInvoice(fo.getCustomerId(), fo.getFofoId(), fo.getInvoiceNumber(), "");
237
        } catch (Exception e) {
236
        } catch (Exception e) {
238
            LOGGER.error("Could not send whatsapp message for order {}", orderId, e);
237
            LOGGER.error("Could not send whatsapp message for order {}", orderId, e);
239
        }
238
        }
240
        model.addAttribute("response1", true);
239
        model.addAttribute("response1", true);
241
        return "response";
240
        return "response";
Line 625... Line 624...
625
        }
624
        }
626
 
625
 
627
        return "response";
626
        return "response";
628
    }
627
    }
629
 
628
 
630
    private boolean sendWhatsappInvoice(FofoOrder fofoOrder) throws Exception {
-
 
631
        return this.sendWhatsappInvoice(fofoOrder, "");
-
 
632
    }
-
 
633
 
-
 
634
    private boolean sendWhatsappInvoice(FofoOrder fofoOrder, String whatsAppNo) throws Exception {
-
 
635
        boolean shouldSendWhatsappMessage = notificationService.shouldSendWhatsappMessage(whatsAppNo);
-
 
636
        boolean isSend = false;
-
 
637
        if (shouldSendWhatsappMessage) {
-
 
638
            Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
-
 
639
            String mobileNumber;
-
 
640
            if (!whatsAppNo.isEmpty()) {
-
 
641
                mobileNumber = whatsAppNo;
-
 
642
            } else {
-
 
643
                mobileNumber = customer.getMobileNumber();
-
 
644
            }
-
 
645
            CustomRetailer retailer = retailerService.getFofoRetailer(fofoOrder.getFofoId());
-
 
646
            String message = String.format("Dear %s,\n" +
-
 
647
                    "Thank you for your purchase from SmartDukaan store - %s, %s.\n" +
-
 
648
                    "Your purchase invoice is attached for your reference.\n" +
-
 
649
                    "\n" +
-
 
650
                    "Download our app for offers and updates on new products.\n" +
-
 
651
                    "https://www.smartdukaan.com/b2c\n" +
-
 
652
                    "\n" +
-
 
653
                    "Best Regards\n" +
-
 
654
                    "SmartDukaan", customer.getFirstName(), retailer.getBusinessName(), retailer.getAddress().getCity());
-
 
655
 
-
 
656
            isSend = notificationService.sendWhatsappMediaMessage(message, mobileNumber, this.getPublicInvoiceUrl(fofoOrder.getInvoiceNumber()),
-
 
657
                    this.getFileName(fofoOrder.getInvoiceNumber()), WhatsappMessageType.DOCUMENT);
-
 
658
        }
-
 
659
        return isSend;
-
 
660
    }
-
 
661
 
-
 
662
    private String getFileName(String invoiceNumber) {
-
 
663
        return "INV-" + invoiceNumber.replace("/", "-") + ".pdf";
-
 
664
    }
-
 
665
 
-
 
666
    private String getPublicInvoiceUrl(String invoiceNumber) {
-
 
667
        String base64Encoded = Base64.getMimeEncoder().encodeToString(invoiceNumber.getBytes(StandardCharsets.UTF_8));
-
 
668
        String publicUrl = "https://partners.smartdukaan.com/wa-invoice-send/" + base64Encoded + ".pdf";
-
 
669
        LOGGER.info("Public Whatsapp Url for Invoice Message - {}", publicUrl);
-
 
670
        return publicUrl;
-
 
671
    }
-
 
672
 
629
 
673
    @RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
630
    @RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
674
    public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
631
    public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
675
                                       Model model) throws ProfitMandiBusinessException {
632
                                       Model model) throws ProfitMandiBusinessException {
676
        LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
633
        LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
Line 1435... Line 1392...
1435
        } catch (Exception e) {
1392
        } catch (Exception e) {
1436
            LOGGER.error("Exception during processScratchOffer for order {}: {}", fofoOrderId, e.getMessage(), e);
1393
            LOGGER.error("Exception during processScratchOffer for order {}: {}", fofoOrderId, e.getMessage(), e);
1437
        }
1394
        }
1438
 
1395
 
1439
        LOGGER.info("Order has been created successfully...");
1396
        LOGGER.info("Order has been created successfully...");
-
 
1397
 
-
 
1398
        if (createOrderRequest.isSendInvoiceOnWhatsApp()) {
-
 
1399
            try {
-
 
1400
                FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(fofoOrderId);
-
 
1401
                if (fofoOrder != null && fofoOrder.getInvoiceNumber() != null) {
-
 
1402
                    notificationService.sendWhatsappInvoice(fofoOrder.getCustomerId(), fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber(), "");
-
 
1403
                    LOGGER.info("WhatsApp invoice sent automatically for order {}", fofoOrderId);
-
 
1404
                }
-
 
1405
            } catch (Exception e) {
-
 
1406
                LOGGER.error("Failed to auto-send WhatsApp invoice for order {}", fofoOrderId, e);
-
 
1407
            }
-
 
1408
        }
-
 
1409
 
1440
        return "redirect:/get-order/?orderId=" + fofoOrderId;
1410
        return "redirect:/get-order/?orderId=" + fofoOrderId;
1441
    }
1411
    }
1442
 
1412
 
1443
    @GetMapping("/billedOrders")
1413
    @GetMapping("/billedOrders")
1444
    public String getBilledOrders(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
1414
    public String getBilledOrders(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
Line 2106... Line 2076...
2106
        return "response";
2076
        return "response";
2107
    }
2077
    }
2108
 
2078
 
2109
    @PutMapping(value = "/sendInvoiceOnWhatsApp")
2079
    @PutMapping(value = "/sendInvoiceOnWhatsApp")
2110
    public String sendInvoiceOnWhatsApp(HttpServletRequest request, @RequestParam int orderId, @RequestParam String whatsAppMobile, Model model) throws Exception {
2080
    public String sendInvoiceOnWhatsApp(HttpServletRequest request, @RequestParam int orderId, @RequestParam String whatsAppMobile, Model model) throws Exception {
-
 
2081
        FofoOrder fo = fofoOrderRepository.selectByOrderId(orderId);
2111
        boolean isSend = this.sendWhatsappInvoice(fofoOrderRepository.selectByOrderId(orderId), whatsAppMobile);
2082
        boolean isSend = notificationService.sendWhatsappInvoice(fo.getCustomerId(), fo.getFofoId(), fo.getInvoiceNumber(), whatsAppMobile);
2112
        model.addAttribute("response1", isSend);
2083
        model.addAttribute("response1", isSend);
2113
        return "response";
2084
        return "response";
2114
    }
2085
    }
2115
 
2086
 
2116
    @Autowired
2087
    @Autowired