| Line 10... |
Line 10... |
| 10 |
import in.shop2020.model.v1.user.PromotionException;
|
10 |
import in.shop2020.model.v1.user.PromotionException;
|
| 11 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
11 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 12 |
import in.shop2020.payments.Payment;
|
12 |
import in.shop2020.payments.Payment;
|
| 13 |
import in.shop2020.payments.PaymentException;
|
13 |
import in.shop2020.payments.PaymentException;
|
| 14 |
import in.shop2020.serving.utils.Utils;
|
14 |
import in.shop2020.serving.utils.Utils;
|
| 15 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
15 |
import in.shop2020.thrift.clients.PaymentClient;
|
| 16 |
import in.shop2020.thrift.clients.PromotionServiceClient;
|
16 |
import in.shop2020.thrift.clients.PromotionClient;
|
| 17 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
17 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 18 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
18 |
import in.shop2020.thrift.clients.UserClient;
|
| 19 |
|
19 |
|
| 20 |
import java.util.HashMap;
|
20 |
import java.util.HashMap;
|
| 21 |
import java.util.List;
|
21 |
import java.util.List;
|
| 22 |
import java.util.Map;
|
22 |
import java.util.Map;
|
| 23 |
|
23 |
|
| Line 64... |
Line 64... |
| 64 |
* @param gatewayId
|
64 |
* @param gatewayId
|
| 65 |
* @return True if the payment object is successfully created, False
|
65 |
* @return True if the payment object is successfully created, False
|
| 66 |
* otherwise.
|
66 |
* otherwise.
|
| 67 |
*/
|
67 |
*/
|
| 68 |
public boolean createPayment(long currentCartId, long userId, long txnId, int gatewayId){
|
68 |
public boolean createPayment(long currentCartId, long userId, long txnId, int gatewayId){
|
| 69 |
PaymentServiceClient paymentServiceClient = null;
|
69 |
PaymentClient paymentServiceClient = null;
|
| 70 |
try {
|
70 |
try {
|
| 71 |
paymentServiceClient = new PaymentServiceClient();
|
71 |
paymentServiceClient = new PaymentClient();
|
| 72 |
} catch (Exception e) {
|
72 |
} catch (Exception e) {
|
| 73 |
log.error("Error while getting payment client", e);
|
73 |
log.error("Error while getting payment client", e);
|
| 74 |
return PAYMENT_NOT_CREATED;
|
74 |
return PAYMENT_NOT_CREATED;
|
| 75 |
}
|
75 |
}
|
| 76 |
|
76 |
|
| Line 127... |
Line 127... |
| 127 |
* @param userServiceClient
|
127 |
* @param userServiceClient
|
| 128 |
* A user context service client to use.
|
128 |
* A user context service client to use.
|
| 129 |
* @param transactionServiceClient
|
129 |
* @param transactionServiceClient
|
| 130 |
* A transaction service client to use.
|
130 |
* A transaction service client to use.
|
| 131 |
*/
|
131 |
*/
|
| 132 |
public static void processSuccessfulTxn(long txnId, UserContextServiceClient userServiceClient, TransactionServiceClient transactionServiceClient) {
|
132 |
public static void processSuccessfulTxn(long txnId, UserClient userServiceClient, TransactionClient transactionServiceClient) {
|
| 133 |
Transaction transaction = null;
|
133 |
Transaction transaction = null;
|
| 134 |
try {
|
134 |
try {
|
| 135 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
135 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
| 136 |
transactionClient.changeTransactionStatus(txnId, TransactionStatus.AUTHORIZED, "Payment authorized for the order");
|
136 |
transactionClient.changeTransactionStatus(txnId, TransactionStatus.AUTHORIZED, "Payment authorized for the order");
|
| 137 |
transaction = transactionClient.getTransaction(txnId);
|
137 |
transaction = transactionClient.getTransaction(txnId);
|
| Line 150... |
Line 150... |
| 150 |
*
|
150 |
*
|
| 151 |
* @param txnId
|
151 |
* @param txnId
|
| 152 |
* The id of the transaction which has to be marked as failed.
|
152 |
* The id of the transaction which has to be marked as failed.
|
| 153 |
* @param transactionServiceClient
|
153 |
* @param transactionServiceClient
|
| 154 |
*/
|
154 |
*/
|
| 155 |
public static void processFailedTxn(long txnId, TransactionServiceClient transactionServiceClient) {
|
155 |
public static void processFailedTxn(long txnId, TransactionClient transactionServiceClient) {
|
| 156 |
try {
|
156 |
try {
|
| 157 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
157 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
| 158 |
transactionClient.changeTransactionStatus(txnId, TransactionStatus.FAILED, "Payment failed for the transaction.");
|
158 |
transactionClient.changeTransactionStatus(txnId, TransactionStatus.FAILED, "Payment failed for the transaction.");
|
| 159 |
} catch(TException e){
|
159 |
} catch(TException e){
|
| 160 |
log.error("Thrift exception while getting information from transaction service.", e);
|
160 |
log.error("Thrift exception while getting information from transaction service.", e);
|
| Line 184... |
Line 184... |
| 184 |
* The COD transaction which should be marked as verification
|
184 |
* The COD transaction which should be marked as verification
|
| 185 |
* pending.
|
185 |
* pending.
|
| 186 |
*/
|
186 |
*/
|
| 187 |
public static void processCodTxn(long txnId){
|
187 |
public static void processCodTxn(long txnId){
|
| 188 |
try {
|
188 |
try {
|
| 189 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
189 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 190 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
190 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
|
| 191 |
transactionClient.changeTransactionStatus(txnId, TransactionStatus.COD_IN_PROCESS, "COD payment awaited");
|
191 |
transactionClient.changeTransactionStatus(txnId, TransactionStatus.COD_IN_PROCESS, "COD payment awaited");
|
| 192 |
Transaction transaction = transactionClient.getTransaction(txnId);
|
192 |
Transaction transaction = transactionClient.getTransaction(txnId);
|
| 193 |
transactionClient.enqueueTransactionInfoEmail(txnId);
|
193 |
transactionClient.enqueueTransactionInfoEmail(txnId);
|
| 194 |
|
194 |
|
| 195 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
195 |
UserClient userServiceClient = new UserClient();
|
| 196 |
trackCouponUsage(transaction);
|
196 |
trackCouponUsage(transaction);
|
| 197 |
resetCart(transaction, userServiceClient);
|
197 |
resetCart(transaction, userServiceClient);
|
| 198 |
} catch (TException e1) {
|
198 |
} catch (TException e1) {
|
| 199 |
log.error("Unable to update status of transaction. Thrift Exception:", e1);
|
199 |
log.error("Unable to update status of transaction. Thrift Exception:", e1);
|
| 200 |
} catch (TransactionServiceException e) {
|
200 |
} catch (TransactionServiceException e) {
|
| Line 216... |
Line 216... |
| 216 |
* @throws TException
|
216 |
* @throws TException
|
| 217 |
*/
|
217 |
*/
|
| 218 |
private double calculatePaymentAmount(long cartId) throws ShoppingCartException, TException{
|
218 |
private double calculatePaymentAmount(long cartId) throws ShoppingCartException, TException{
|
| 219 |
double totalAmount = 0;
|
219 |
double totalAmount = 0;
|
| 220 |
Cart cart;
|
220 |
Cart cart;
|
| 221 |
UserContextServiceClient userContextServiceClient = null;
|
221 |
UserClient userContextServiceClient = null;
|
| 222 |
try {
|
222 |
try {
|
| 223 |
userContextServiceClient = new UserContextServiceClient();
|
223 |
userContextServiceClient = new UserClient();
|
| 224 |
} catch (Exception e) {
|
224 |
} catch (Exception e) {
|
| 225 |
log.error("Unable to initialize user context service client", e);
|
225 |
log.error("Unable to initialize user context service client", e);
|
| 226 |
throw new ShoppingCartException(100, "Unable to initialize the user service client");
|
226 |
throw new ShoppingCartException(100, "Unable to initialize the user service client");
|
| 227 |
}
|
227 |
}
|
| 228 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
228 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| Line 252... |
Line 252... |
| 252 |
* @param transaction
|
252 |
* @param transaction
|
| 253 |
* The transaction whose items have to be removed from the
|
253 |
* The transaction whose items have to be removed from the
|
| 254 |
* shopping cart.
|
254 |
* shopping cart.
|
| 255 |
* @param userServiceClient
|
255 |
* @param userServiceClient
|
| 256 |
*/
|
256 |
*/
|
| 257 |
private static void resetCart(Transaction transaction, UserContextServiceClient userServiceClient) {
|
257 |
private static void resetCart(Transaction transaction, UserClient userServiceClient) {
|
| 258 |
Map<Long, Double> items = new HashMap<Long, Double>();
|
258 |
Map<Long, Double> items = new HashMap<Long, Double>();
|
| 259 |
for(Order order: transaction.getOrders()){
|
259 |
for(Order order: transaction.getOrders()){
|
| 260 |
for(LineItem lineitem: order.getLineitems()){
|
260 |
for(LineItem lineitem: order.getLineitems()){
|
| 261 |
Long itemId = lineitem.getItem_id();
|
261 |
Long itemId = lineitem.getItem_id();
|
| 262 |
Double quantity = items.get(itemId);
|
262 |
Double quantity = items.get(itemId);
|
| Line 295... |
Line 295... |
| 295 |
private static void trackCouponUsage(Transaction transaction) {
|
295 |
private static void trackCouponUsage(Transaction transaction) {
|
| 296 |
try {
|
296 |
try {
|
| 297 |
String couponCode = transaction.getCoupon_code();
|
297 |
String couponCode = transaction.getCoupon_code();
|
| 298 |
|
298 |
|
| 299 |
if (couponCode != null && !couponCode.isEmpty()) {
|
299 |
if (couponCode != null && !couponCode.isEmpty()) {
|
| 300 |
PromotionServiceClient promotionServiceClient = new PromotionServiceClient();
|
300 |
PromotionClient promotionServiceClient = new PromotionClient();
|
| 301 |
promotionServiceClient.getClient().trackCouponUsage(couponCode, transaction.getId(), transaction.getCustomer_id());
|
301 |
promotionServiceClient.getClient().trackCouponUsage(couponCode, transaction.getId(), transaction.getCustomer_id());
|
| 302 |
}
|
302 |
}
|
| 303 |
} catch (PromotionException e) {
|
303 |
} catch (PromotionException e) {
|
| 304 |
log.error("Promotion Exception: " + e);
|
304 |
log.error("Promotion Exception: " + e);
|
| 305 |
} catch (TException e) {
|
305 |
} catch (TException e) {
|