| 6060 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
| 13373 |
amit.gupta |
3 |
import in.shop2020.model.v1.order.RechargeOrder;
|
| 6060 |
rajveer |
4 |
import in.shop2020.payments.Attribute;
|
|
|
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 PayuPaymentService implements IPaymentService{
|
|
|
14 |
|
|
|
15 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
16 |
|
|
|
17 |
public static final String TXN_ID = "transactionId";
|
|
|
18 |
public static final String PAYMENT_ID = "paymentId";
|
|
|
19 |
public static final String AMOUNT = "amount";
|
|
|
20 |
public static final String DATE_TIME = "dateTime";
|
|
|
21 |
public static final String MODE = "mode";
|
|
|
22 |
public static final String REF_NO = "referenceNo";
|
|
|
23 |
public static final String TXN_TYPE = "transactionType";
|
|
|
24 |
|
| 13373 |
amit.gupta |
25 |
private static int gatewayId=19;
|
|
|
26 |
|
| 6060 |
rajveer |
27 |
private long paymentId;
|
|
|
28 |
|
|
|
29 |
@Override
|
| 20278 |
aman.kumar |
30 |
public long createPayment(long userId, long txnId, String paymentOption, int gatewayId, String paymentType){
|
| 13391 |
amit.gupta |
31 |
log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through PAYU");
|
| 6060 |
rajveer |
32 |
CommonPaymentService cps = new CommonPaymentService();
|
| 13391 |
amit.gupta |
33 |
if(!cps.createPayment(userId, txnId, PayuPaymentService.gatewayId)){
|
| 6060 |
rajveer |
34 |
log.error("Error while creating the basic payment");
|
|
|
35 |
return PAYMENT_NOT_CREATED;
|
|
|
36 |
}
|
|
|
37 |
paymentId = cps.getPaymentId();
|
|
|
38 |
|
|
|
39 |
if(paymentOption != null){
|
|
|
40 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
|
|
41 |
attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
|
| 20278 |
aman.kumar |
42 |
attributes.add(new Attribute(IPaymentService.PAYMENT_TYPE, paymentType));
|
| 6060 |
rajveer |
43 |
|
|
|
44 |
try {
|
|
|
45 |
PaymentClient paymentServiceClient = new PaymentClient();
|
|
|
46 |
paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
|
|
|
47 |
} catch (Exception e) {
|
|
|
48 |
log.error("Error while saving payment option attribute", e);
|
|
|
49 |
// TODO: We've already created the payment. We could allow the
|
|
|
50 |
// payment to go through. The customer will be a little
|
|
|
51 |
// annoyed to have to select from a host of options again but
|
|
|
52 |
// will be better than completely disallowing him.
|
|
|
53 |
return PAYMENT_NOT_CREATED;
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
return paymentId;
|
|
|
58 |
}
|
| 13373 |
amit.gupta |
59 |
|
| 20278 |
aman.kumar |
60 |
public long createPayment(RechargeOrder rechargeOrder, String paymentOption, String paymentType) {
|
| 13373 |
amit.gupta |
61 |
log.info("Creating payment for the txn#: " + rechargeOrder.getId() + " for the user: " + rechargeOrder.getUserId() + " for processing through Payu");
|
|
|
62 |
CommonPaymentService cps = new CommonPaymentService();
|
|
|
63 |
if(!cps.createPayment(rechargeOrder, gatewayId)){
|
|
|
64 |
log.error("Error while creating the basic payment");
|
|
|
65 |
return PAYMENT_NOT_CREATED;
|
|
|
66 |
}
|
|
|
67 |
paymentId = cps.getPaymentId();
|
|
|
68 |
|
|
|
69 |
if(paymentOption != null){
|
|
|
70 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
|
|
71 |
attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
|
| 20278 |
aman.kumar |
72 |
attributes.add(new Attribute(IPaymentService.PAYMENT_TYPE, paymentType));
|
| 13373 |
amit.gupta |
73 |
|
|
|
74 |
try {
|
|
|
75 |
PaymentClient paymentServiceClient = new PaymentClient();
|
|
|
76 |
paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
|
|
|
77 |
} catch (Exception e) {
|
|
|
78 |
log.error("Error while saving payment option attribute", e);
|
|
|
79 |
// TODO: We've already created the payment. We could allow the
|
|
|
80 |
// payment to go through. The customer will be a little
|
|
|
81 |
// annoyed to have to select from a host of options again but
|
|
|
82 |
// will be better than completely disallowing him.
|
|
|
83 |
return PAYMENT_NOT_CREATED;
|
|
|
84 |
}
|
|
|
85 |
}
|
| 6060 |
rajveer |
86 |
|
| 13373 |
amit.gupta |
87 |
return paymentId;
|
|
|
88 |
}
|
| 6060 |
rajveer |
89 |
|
| 13373 |
amit.gupta |
90 |
public static void main(String[] args){
|
| 6060 |
rajveer |
91 |
}
|
|
|
92 |
}
|