Subversion Repositories SmartDukaan

Rev

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

Rev 29625 Rev 30989
Line 118... Line 118...
118
	@Autowired
118
	@Autowired
119
	private PositionRepository positionRepository;
119
	private PositionRepository positionRepository;
120
 
120
 
121
	@Autowired
121
	@Autowired
122
	private FocusedModelByPassRepository focusedModelByPassRepository;
122
	private FocusedModelByPassRepository focusedModelByPassRepository;
123
	
123
 
124
	@Autowired
124
	@Autowired
125
	private FofoPaymentRepository fofoPaymentRepository;
125
	private FofoPaymentRepository fofoPaymentRepository;
126
 
126
 
127
	@Autowired
127
	@Autowired
128
	private RetailerService retailerService;
128
	private RetailerService retailerService;
Line 341... Line 341...
341
			byPassRequest.setStatus(ByPassRequestStatus.REJECTED);
341
			byPassRequest.setStatus(ByPassRequestStatus.REJECTED);
342
			byPassRequest.setUpdatedTimestamp(LocalDateTime.now());
342
			byPassRequest.setUpdatedTimestamp(LocalDateTime.now());
343
			byPassRequest.setReason(reason);
343
			byPassRequest.setReason(reason);
344
		}
344
		}
345
 
345
 
-
 
346
		String title = "Billing Request";
-
 
347
 
-
 
348
		String message = String.format("Your Billing  Request is " + status
-
 
349
				+ ". Please ensure to order the missing focus models as soon as possible.");
-
 
350
 
346
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
351
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
347
		sendNotificationModel.setCampaignName("Billing Request");
352
		sendNotificationModel.setCampaignName("Billing Request");
348
		sendNotificationModel.setTitle("Billing Request");
353
		sendNotificationModel.setTitle(title);
349
		sendNotificationModel.setMessage(String.format("Your Billing  Request is " + " " + status
354
		sendNotificationModel.setMessage(message);
350
				+ ". Please ensure to order the missing focus models as soon as possible"));
-
 
351
		sendNotificationModel.setType("url");
355
		sendNotificationModel.setType("url");
352
		sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
356
		sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
353
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
357
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
354
		sendNotificationModel.setMessageType(MessageType.notification);
358
		sendNotificationModel.setMessageType(MessageType.notification);
355
		sendNotificationModel
359
		sendNotificationModel
Line 357... Line 361...
357
 
361
 
358
		notificationService.sendNotification(sendNotificationModel);
362
		notificationService.sendNotification(sendNotificationModel);
359
 
363
 
360
		return responseSender.ok(true);
364
		return responseSender.ok(true);
361
	}
365
	}
-
 
366
 
362
	@Autowired
367
	@Autowired
363
	WalletService walletService;
368
	WalletService walletService;
364
	
369
 
365
	@Autowired
370
	@Autowired
366
	MandiiService mandiiService;
371
	MandiiService mandiiService;
367
	
372
 
-
 
373
	@Autowired
368
	@Autowired UserWalletHistoryRepository userWalletHistoryRepository;
374
	UserWalletHistoryRepository userWalletHistoryRepository;
-
 
375
 
369
	@RequestMapping(value = "/cart/payment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
376
	@RequestMapping(value = "/cart/payment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
370
	public ResponseEntity<?> validateCartPayment(HttpServletRequest request,
377
	public ResponseEntity<?> validateCartPayment(HttpServletRequest request,
371
			@RequestParam(defaultValue = "0") int paymentId, Model model) throws Exception {
378
			@RequestParam(defaultValue = "0") int paymentId, Model model) throws Exception {
372
		int userId = (int) request.getAttribute("userId");
379
		int userId = (int) request.getAttribute("userId");
373
		UserCart uc = userAccountRepository.getUserCart(userId);
380
		UserCart uc = userAccountRepository.getUserCart(userId);
374
 
381
 
375
		FofoPayment fofoPayment = fofoPaymentRepository.selectById(paymentId);
382
		FofoPayment fofoPayment = fofoPaymentRepository.selectById(paymentId);
376
		if(fofoPayment==null || fofoPayment.getFofoId()!=uc.getUserId()) {
383
		if (fofoPayment == null || fofoPayment.getFofoId() != uc.getUserId()) {
377
			return responseSender.ok(false);
384
			return responseSender.ok(false);
378
		}
385
		}
379
		String gatewayReference = fofoPayment.getGatewayReference();
386
		String gatewayReference = fofoPayment.getGatewayReference();
-
 
387
		List<UserWalletHistory> historyList = userWalletHistoryRepository
380
		List<UserWalletHistory> historyList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(paymentId, WalletReferenceType.PAYMENT_GATEWAY);
388
				.selectAllByreferenceIdandreferenceType(paymentId, WalletReferenceType.PAYMENT_GATEWAY);
381
		if (fofoPayment.getStatus().equals(PaymentStatus.INIT) && historyList.size() == 0) {
389
		if (fofoPayment.getStatus().equals(PaymentStatus.INIT) && historyList.size() == 0) {
382
			String jsonString = mandiiService.getOrderStatus(gatewayReference);
390
			String jsonString = mandiiService.getOrderStatus(gatewayReference);
383
			JSONObject jsonOrder = new JSONObject(jsonString);
391
			JSONObject jsonOrder = new JSONObject(jsonString);
384
			double orderAmount = jsonOrder.getDouble("order_amount");
392
			double orderAmount = jsonOrder.getDouble("order_amount");
385
			double capturedAmount = jsonOrder.getDouble("captured_amount");
393
			double capturedAmount = jsonOrder.getDouble("captured_amount");
386
			int merchantOrderId = jsonOrder.getInt("merchant_order_number");
394
			int merchantOrderId = jsonOrder.getInt("merchant_order_number");
387
			String status = jsonOrder.getString("status");
395
			String status = jsonOrder.getString("status");
388
			if(merchantOrderId == paymentId && status.equals("SUCCESS") || status.equals("CAPTURED")) {
396
			if (merchantOrderId == paymentId && status.equals("SUCCESS") || status.equals("CAPTURED")) {
389
				if(orderAmount == fofoPayment.getAmount()) {
397
				if (orderAmount == fofoPayment.getAmount()) {
390
					fofoPayment.setStatus(PaymentStatus.SUCCESS);
398
					fofoPayment.setStatus(PaymentStatus.SUCCESS);
391
					fofoPayment.setAmount(capturedAmount);
399
					fofoPayment.setAmount(capturedAmount);
392
					walletService.addAmountToWallet(uc.getUserId(), paymentId, WalletReferenceType.PAYMENT_GATEWAY, "Amount added to wallet via SD Credit via Mandii", (float)fofoPayment.getAmount(), LocalDateTime.now());
400
					walletService.addAmountToWallet(uc.getUserId(), paymentId, WalletReferenceType.PAYMENT_GATEWAY,
-
 
401
							"Amount added to wallet via SD Credit via Mandii", (float) fofoPayment.getAmount(),
-
 
402
							LocalDateTime.now());
393
					if(orderAmount == capturedAmount) {
403
					if (orderAmount == capturedAmount) {
394
						return responseSender.ok(true);
404
						return responseSender.ok(true);
395
					} 
405
					}
396
				}
406
				}
397
			}
407
			}
398
		}
408
		}
399
		return responseSender.ok(false);
409
		return responseSender.ok(false);
400
	}
410
	}