Subversion Repositories SmartDukaan

Rev

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

Rev 37629 Rev 37657
Line 34... Line 34...
34
 
34
 
35
import com.spice.profitmandi.common.enumuration.MessageType;
35
import com.spice.profitmandi.common.enumuration.MessageType;
36
import com.spice.profitmandi.common.model.CustomRetailer;
36
import com.spice.profitmandi.common.model.CustomRetailer;
37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
38
import com.spice.profitmandi.common.model.SendNotificationModel;
38
import com.spice.profitmandi.common.model.SendNotificationModel;
39
import com.spice.profitmandi.common.services.mandii.MandiiService;
-
 
40
import com.spice.profitmandi.common.web.util.ResponseSender;
39
import com.spice.profitmandi.common.web.util.ResponseSender;
41
import com.spice.profitmandi.dao.cart.CartService;
40
import com.spice.profitmandi.dao.cart.CartService;
42
import com.spice.profitmandi.dao.entity.auth.AuthUser;
41
import com.spice.profitmandi.dao.entity.auth.AuthUser;
43
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
42
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
44
import com.spice.profitmandi.dao.entity.cs.Position;
43
import com.spice.profitmandi.dao.entity.cs.Position;
Line 364... Line 363...
364
	}
363
	}
365
 
364
 
366
	@Autowired
365
	@Autowired
367
	WalletService walletService;
366
	WalletService walletService;
368
 
367
 
369
	@Autowired
-
 
370
	MandiiService mandiiService;
-
 
371
 
368
 
372
	@Autowired
369
	@Autowired
373
	UserWalletHistoryRepository userWalletHistoryRepository;
370
	UserWalletHistoryRepository userWalletHistoryRepository;
374
 
371
 
375
	@RequestMapping(value = "/cart/payment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
376
	public ResponseEntity<?> validateCartPayment(HttpServletRequest request,
-
 
377
			@RequestParam(defaultValue = "0") int paymentId, Model model) throws Exception {
-
 
378
		int userId = (int) request.getAttribute("userId");
-
 
379
		UserCart uc = userAccountRepository.getUserCart(userId);
-
 
380
 
-
 
381
		FofoPayment fofoPayment = fofoPaymentRepository.selectById(paymentId);
-
 
382
		if (fofoPayment == null || fofoPayment.getFofoId() != uc.getUserId()) {
-
 
383
			return responseSender.ok(false);
-
 
384
		}
-
 
385
		String gatewayReference = fofoPayment.getGatewayReference();
-
 
386
		List<UserWalletHistory> historyList = userWalletHistoryRepository
-
 
387
				.selectAllByreferenceIdandreferenceType(paymentId, WalletReferenceType.PAYMENT_GATEWAY);
-
 
388
		if (fofoPayment.getStatus().equals(PaymentStatus.INIT) && historyList.size() == 0) {
-
 
389
			String jsonString = mandiiService.getOrderStatus(gatewayReference);
-
 
390
			JSONObject jsonOrder = new JSONObject(jsonString);
-
 
391
			double orderAmount = jsonOrder.getDouble("order_amount");
-
 
392
			double capturedAmount = jsonOrder.getDouble("captured_amount");
-
 
393
			int merchantOrderId = jsonOrder.getInt("merchant_order_number");
-
 
394
			String status = jsonOrder.getString("status");
-
 
395
			if (merchantOrderId == paymentId && status.equals("SUCCESS") || status.equals("CAPTURED")) {
-
 
396
				if (orderAmount == fofoPayment.getAmount()) {
-
 
397
					fofoPayment.setStatus(PaymentStatus.SUCCESS);
-
 
398
					fofoPayment.setAmount(capturedAmount);
-
 
399
					walletService.addAmountToWallet(uc.getUserId(), paymentId, WalletReferenceType.PAYMENT_GATEWAY,
-
 
400
							"Amount added to wallet via SD Credit via Mandii", (float) fofoPayment.getAmount(),
-
 
401
							LocalDateTime.now());
-
 
402
					if (orderAmount == capturedAmount) {
-
 
403
						return responseSender.ok(true);
-
 
404
					}
-
 
405
				}
-
 
406
			}
-
 
407
		}
-
 
408
		return responseSender.ok(false);
-
 
409
	}
-
 
410
 
372
 
411
	@RequestMapping(value = "/partner/hidAllocation", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
373
	@RequestMapping(value = "/partner/hidAllocation", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
412
	@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
374
	@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
413
	public ResponseEntity<?> getItemHidAllocation(HttpServletRequest request) throws
375
	public ResponseEntity<?> getItemHidAllocation(HttpServletRequest request) throws
414
			Exception {
376
			Exception {