| 1318 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import org.apache.log4j.Logger;
|
|
|
7 |
|
| 6050 |
anupam.sin |
8 |
import in.shop2020.model.v1.order.RechargeOrder;
|
| 1318 |
rajveer |
9 |
import in.shop2020.payments.Attribute;
|
| 2334 |
chandransh |
10 |
import in.shop2020.payments.Payment;
|
| 1318 |
rajveer |
11 |
import in.shop2020.payments.PaymentStatus;
|
| 3126 |
rajveer |
12 |
import in.shop2020.thrift.clients.PaymentClient;
|
| 1318 |
rajveer |
13 |
|
| 1905 |
chandransh |
14 |
public class HdfcPaymentService implements IPaymentService {
|
| 1318 |
rajveer |
15 |
private static final long serialVersionUID = 1L;
|
|
|
16 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
17 |
|
|
|
18 |
private String redirectURL;
|
| 2758 |
chandransh |
19 |
private static int gatewayId=1;
|
| 1318 |
rajveer |
20 |
|
|
|
21 |
public HdfcPaymentService() {
|
|
|
22 |
|
|
|
23 |
}
|
|
|
24 |
|
| 6390 |
rajveer |
25 |
public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
|
| 2199 |
chandransh |
26 |
log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through HDFC");
|
| 1905 |
chandransh |
27 |
CommonPaymentService cps = new CommonPaymentService();
|
| 6390 |
rajveer |
28 |
if(!cps.createPayment(userId, txnId, gatewayId)){
|
| 1905 |
chandransh |
29 |
log.error("Error while creating the basic payment");
|
|
|
30 |
return PAYMENT_NOT_CREATED;
|
| 2758 |
chandransh |
31 |
}else{
|
|
|
32 |
return initializePayment(cps.getPaymentId(), paymentOption);
|
| 1318 |
rajveer |
33 |
}
|
| 2758 |
chandransh |
34 |
}
|
|
|
35 |
|
| 6228 |
anupam.sin |
36 |
public long createPayment(RechargeOrder rechargeOrder, String paymentOption, String phone) {
|
| 6050 |
anupam.sin |
37 |
log.info("Creating payment for the txn#: " + rechargeOrder.getId() + " for the user: " + rechargeOrder.getUserId() + " for processing through HDFC");
|
| 10968 |
amit.gupta |
38 |
log.info("createPayment phone---- " + phone);
|
| 6050 |
anupam.sin |
39 |
CommonPaymentService cps = new CommonPaymentService();
|
|
|
40 |
if(!cps.createPayment(rechargeOrder, gatewayId)){
|
|
|
41 |
log.error("Error while creating the basic payment");
|
|
|
42 |
return PAYMENT_NOT_CREATED;
|
|
|
43 |
}else{
|
| 6228 |
anupam.sin |
44 |
return initializePayment(rechargeOrder, cps.getPaymentId(), paymentOption, phone);
|
| 6050 |
anupam.sin |
45 |
}
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
private long initializePayment(RechargeOrder rechargeOrder, long merchantPaymentId,
|
| 6228 |
anupam.sin |
49 |
String paymentOption, String phone) {
|
| 6050 |
anupam.sin |
50 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
|
|
51 |
attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
|
| 10968 |
amit.gupta |
52 |
log.info("initializePayment phone---- " + phone);
|
| 6050 |
anupam.sin |
53 |
PaymentClient paymentServiceClient = null;
|
|
|
54 |
try {
|
|
|
55 |
paymentServiceClient = new PaymentClient();
|
|
|
56 |
} catch (Exception e) {
|
|
|
57 |
log.error("Error while getting payment client", e);
|
|
|
58 |
return PAYMENT_NOT_CREATED;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
try {
|
|
|
62 |
paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
|
| 10269 |
amit.gupta |
63 |
this.redirectURL = paymentServiceClient.getClient().doHdfcPaymentForDigitalOrder(merchantPaymentId, rechargeOrder.getId(), phone, false);
|
| 6050 |
anupam.sin |
64 |
return merchantPaymentId;
|
|
|
65 |
}catch (Exception e) {
|
|
|
66 |
log.error("Error while initializing payment.", e);
|
|
|
67 |
return PAYMENT_NOT_CREATED;
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
private long initializePayment(long merchantPaymentId, String paymentOption){
|
| 2758 |
chandransh |
72 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
|
|
73 |
attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
|
| 3126 |
rajveer |
74 |
PaymentClient paymentServiceClient = null;
|
| 1905 |
chandransh |
75 |
try {
|
| 3126 |
rajveer |
76 |
paymentServiceClient = new PaymentClient();
|
| 1905 |
chandransh |
77 |
} catch (Exception e) {
|
| 2758 |
chandransh |
78 |
log.error("Error while getting payment client", e);
|
| 1905 |
chandransh |
79 |
return PAYMENT_NOT_CREATED;
|
|
|
80 |
}
|
| 1318 |
rajveer |
81 |
|
|
|
82 |
try {
|
| 2758 |
chandransh |
83 |
paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
|
| 10269 |
amit.gupta |
84 |
this.redirectURL = paymentServiceClient.getClient().initializeHdfcPayment(merchantPaymentId, false);
|
| 2758 |
chandransh |
85 |
return merchantPaymentId;
|
| 1318 |
rajveer |
86 |
}catch (Exception e) {
|
| 2334 |
chandransh |
87 |
log.error("Error while initializing payment.", e);
|
| 2758 |
chandransh |
88 |
return PAYMENT_NOT_CREATED;
|
| 1318 |
rajveer |
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
public String getRedirectUrl(){
|
|
|
93 |
return this.redirectURL;
|
|
|
94 |
}
|
| 2334 |
chandransh |
95 |
|
|
|
96 |
public static void main(String args[]){
|
|
|
97 |
Payment payment = new Payment();
|
|
|
98 |
payment.setPaymentId(216);
|
|
|
99 |
payment.setAmount(40000);
|
|
|
100 |
payment.setGatewayPaymentId("TESTSTSTS");
|
|
|
101 |
|
| 3010 |
chandransh |
102 |
// The underlying method calls are no longer valid since all the
|
|
|
103 |
// information required to capture a payment is read from the database
|
|
|
104 |
// itself and can't be specified through the call.
|
|
|
105 |
|
| 2334 |
chandransh |
106 |
//This test checks what happens when the txn id is left blank
|
| 3010 |
chandransh |
107 |
//capturePayment(payment, ""); //Result: !ERROR!-GW00205-Invalid Subsequent Transaction.
|
| 2334 |
chandransh |
108 |
|
|
|
109 |
//This test checks what happends with an invalid txn id
|
| 3010 |
chandransh |
110 |
//capturePayment(payment, "6022630101411740"); //Result: !ERROR!-GW00201-Transaction not found.
|
| 2334 |
chandransh |
111 |
|
|
|
112 |
//The next three tests require a valid AUTH transaction id.
|
|
|
113 |
//This test checks what happens when we attempt to capture an amount greater than what was authorized.
|
| 3010 |
chandransh |
114 |
//capturePayment(payment, "9644960021411730"); //Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.
|
| 2334 |
chandransh |
115 |
|
|
|
116 |
//This test checks what happens when we attempt to capture a valid transaction with the right amount. This transaction should be CAPTURED.
|
| 3010 |
chandransh |
117 |
//payment.setAmount(21698);
|
|
|
118 |
//capturePayment(payment, "9644960021411730"); //Result: CAPTURED
|
| 2334 |
chandransh |
119 |
|
|
|
120 |
//This test tries to capture an already captured payment.
|
| 3010 |
chandransh |
121 |
//capturePayment(payment, "9644960021411730"); //Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.
|
| 2334 |
chandransh |
122 |
}
|
| 1318 |
rajveer |
123 |
}
|