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