| 34444 |
vikas.jang |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
5 |
import com.spice.profitmandi.common.req.CreateOrderRequest;
|
|
|
6 |
import com.spice.profitmandi.common.req.CreatePaymentRequest;
|
|
|
7 |
import com.spice.profitmandi.common.req.ValidateEmiRequest;
|
|
|
8 |
import com.spice.profitmandi.common.res.EmiResponse;
|
|
|
9 |
import com.spice.profitmandi.common.services.PineLabService;
|
|
|
10 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
11 |
import com.spice.profitmandi.common.req.CalculateEmiRequest;
|
|
|
12 |
import okhttp3.Response;
|
|
|
13 |
import org.apache.logging.log4j.LogManager;
|
|
|
14 |
import org.apache.logging.log4j.Logger;
|
|
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
16 |
import org.springframework.http.ResponseEntity;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
19 |
import org.springframework.web.bind.annotation.*;
|
|
|
20 |
|
|
|
21 |
import java.io.IOException;
|
|
|
22 |
import java.util.HashMap;
|
|
|
23 |
import java.util.Map;
|
|
|
24 |
|
|
|
25 |
@Controller
|
|
|
26 |
@RequestMapping("/payments")
|
|
|
27 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
28 |
public class PaymentsController {
|
|
|
29 |
|
|
|
30 |
@Autowired
|
|
|
31 |
private ResponseSender<?> responseSender;
|
|
|
32 |
|
|
|
33 |
@Autowired
|
|
|
34 |
private PineLabService pineLabService;
|
|
|
35 |
|
|
|
36 |
private static final Logger LOGGER = LogManager.getLogger(PaymentsController.class);
|
|
|
37 |
|
|
|
38 |
@PostMapping("/get-emi-options")
|
|
|
39 |
public ResponseEntity<?> getEmiOptions(@RequestBody CalculateEmiRequest calculateEmiRequest) throws ProfitMandiBusinessException {
|
|
|
40 |
try {
|
|
|
41 |
Map<String, Object> params = new HashMap<>();
|
|
|
42 |
EmiResponse response = null;
|
|
|
43 |
if (calculateEmiRequest.getProvider().equals("pinelabs")) {
|
|
|
44 |
params.put("amount_in_paisa", calculateEmiRequest.getAmountInPaisa());
|
|
|
45 |
params.put("product_details", calculateEmiRequest.getProductDetails());
|
|
|
46 |
response = pineLabService.getEmiOptions(params);
|
|
|
47 |
}
|
|
|
48 |
return responseSender.ok(response);
|
|
|
49 |
} catch (ProfitMandiBusinessException e){
|
|
|
50 |
return responseSender.badRequest(e);
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@PostMapping("/emi/plans")
|
|
|
55 |
public ResponseEntity<?> getEmiPlans(@RequestBody CalculateEmiRequest calculateEmiRequest) throws IOException {
|
|
|
56 |
Response response;
|
|
|
57 |
Map<String, Object> params = new HashMap<>();
|
|
|
58 |
if (calculateEmiRequest.getProvider().equals("pinelabs")) {
|
|
|
59 |
Map<String, Object> orderAmount = new HashMap<>();
|
|
|
60 |
orderAmount.put("value", calculateEmiRequest.getAmountInPaisa());
|
|
|
61 |
orderAmount.put("currency", "INR");
|
|
|
62 |
|
|
|
63 |
params.put("order_amount", orderAmount);
|
|
|
64 |
|
|
|
65 |
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
66 |
String requestBody = objectMapper.writeValueAsString(params);
|
|
|
67 |
response = pineLabService.getEMIs(requestBody);
|
|
|
68 |
LOGGER.info("plural controller response: {}",response);
|
|
|
69 |
if (response.isSuccessful()){
|
|
|
70 |
return responseSender.ok(response.body());
|
|
|
71 |
} else {
|
|
|
72 |
return responseSender.ok(response.message());
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
return responseSender.ok(null);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@PostMapping("/emi/validate")
|
|
|
79 |
public ResponseEntity<?> validateEmiPlans(@RequestBody ValidateEmiRequest validateEmiRequest) throws IOException {
|
|
|
80 |
if (validateEmiRequest.getProvider().equals("pinelabs")) {
|
|
|
81 |
Response response;
|
|
|
82 |
Map<String, Object> params = new HashMap<>();
|
|
|
83 |
|
|
|
84 |
params.put("order_amount", validateEmiRequest.getOrderAmount());
|
|
|
85 |
params.put("payment_amount", validateEmiRequest.getPaymentAmount());
|
|
|
86 |
params.put("offer_data", validateEmiRequest.getOfferData());
|
|
|
87 |
params.put("payment_method", validateEmiRequest.getPaymentMethod());
|
|
|
88 |
|
|
|
89 |
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
90 |
String requestBody = objectMapper.writeValueAsString(params);
|
|
|
91 |
response = pineLabService.getEMIs(requestBody);
|
|
|
92 |
|
|
|
93 |
if (response.isSuccessful()){
|
|
|
94 |
return responseSender.ok(response.body());
|
|
|
95 |
} else {
|
|
|
96 |
return responseSender.ok(response.message());
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
return responseSender.ok(null);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
@PostMapping("/emi/place-order")
|
|
|
103 |
public ResponseEntity<?> placeEMIOrder(@RequestBody CreateOrderRequest createOrderRequest) throws IOException {
|
|
|
104 |
if (createOrderRequest.getProvider().equals("pinelabs")) {
|
|
|
105 |
Response response;
|
|
|
106 |
Map<String, Object> params = new HashMap<>();
|
|
|
107 |
|
|
|
108 |
params.put("order_amount", createOrderRequest.getOrderAmount());
|
|
|
109 |
params.put("pre_auth", false);
|
|
|
110 |
params.put("callback_url", createOrderRequest.getCallbackUrl());
|
|
|
111 |
params.put("failure_callback_url", createOrderRequest.getFailureCallbackUrl());
|
|
|
112 |
params.put("allowed_payment_methods", createOrderRequest.getAllowedPaymentMethods());
|
|
|
113 |
params.put("notes", createOrderRequest.getNotes());
|
|
|
114 |
params.put("purchase_details", createOrderRequest.getPurchaseDetails());
|
|
|
115 |
params.put("cart_coupon_discount_amount", createOrderRequest.getCartCouponDiscountAmount());
|
|
|
116 |
|
|
|
117 |
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
118 |
String requestBody = objectMapper.writeValueAsString(params);
|
|
|
119 |
response = pineLabService.placeOrder(requestBody);
|
|
|
120 |
|
|
|
121 |
if (response.isSuccessful()){
|
|
|
122 |
return responseSender.ok(response.body());
|
|
|
123 |
} else {
|
|
|
124 |
return responseSender.ok(response.message());
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
return responseSender.ok(null);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
@PostMapping("/emi/create-payment")
|
|
|
131 |
public ResponseEntity<?> placeCreatePayment(@RequestBody CreatePaymentRequest createPaymentRequest) throws IOException {
|
|
|
132 |
if (createPaymentRequest.getProvider().equals("pinelabs")) {
|
|
|
133 |
Response response;
|
|
|
134 |
Map<String, Object> params = new HashMap<>();
|
|
|
135 |
|
|
|
136 |
params.put("payments", createPaymentRequest.getPayments());
|
|
|
137 |
|
|
|
138 |
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
139 |
String requestBody = objectMapper.writeValueAsString(params);
|
|
|
140 |
response = pineLabService.placeOrder(requestBody);
|
|
|
141 |
|
|
|
142 |
if (response.isSuccessful()){
|
|
|
143 |
return responseSender.ok(response.body());
|
|
|
144 |
} else {
|
|
|
145 |
return responseSender.ok(response.message());
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
return responseSender.ok(null);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
}
|