| 1905 |
chandransh |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import org.apache.log4j.Logger;
|
|
|
4 |
|
|
|
5 |
import in.shop2020.config.ConfigException;
|
|
|
6 |
import in.shop2020.model.v1.order.Order;
|
|
|
7 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
8 |
import in.shop2020.payments.Payment;
|
|
|
9 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
|
|
10 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
11 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
12 |
|
|
|
13 |
public class EbsPayController {
|
|
|
14 |
|
|
|
15 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
16 |
|
|
|
17 |
private static String accountId;
|
|
|
18 |
|
|
|
19 |
private static String returnUrl;
|
|
|
20 |
|
|
|
21 |
private static String mode;
|
|
|
22 |
|
|
|
23 |
static{
|
|
|
24 |
try {
|
|
|
25 |
accountId = ConfigClient.getClient().get("ebs_account_id");
|
|
|
26 |
returnUrl = ConfigClient.getClient().get("ebs_return_url");
|
|
|
27 |
mode = ConfigClient.getClient().get("ebs_pay_mode");
|
|
|
28 |
} catch (ConfigException e) {
|
|
|
29 |
log.error("Unable to get EBS payment configuration.");
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
private String id;
|
|
|
34 |
|
|
|
35 |
private double amount;
|
|
|
36 |
|
|
|
37 |
private ContactDetails billingDetails;
|
|
|
38 |
|
|
|
39 |
public String show(){
|
|
|
40 |
PaymentServiceClient paymentServiceClient = null;
|
|
|
41 |
Payment payment = null;
|
|
|
42 |
try {
|
|
|
43 |
long paymentId = Long.parseLong(this.id);
|
|
|
44 |
paymentServiceClient = new PaymentServiceClient();
|
|
|
45 |
payment = paymentServiceClient.getClient().getPayment(paymentId);
|
|
|
46 |
} catch (Exception e) {
|
|
|
47 |
log.error("Error while getting payment client");
|
|
|
48 |
e.printStackTrace();
|
|
|
49 |
return "fail";
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
Order order = null;
|
|
|
53 |
try {
|
|
|
54 |
long txnId = payment.getMerchantTxnId();
|
|
|
55 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
56 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
|
|
|
57 |
Transaction transaction = txnClient.getTransaction(txnId);
|
|
|
58 |
order = transaction.getOrders().get(0);
|
|
|
59 |
} catch (Exception e) {
|
|
|
60 |
e.printStackTrace();
|
|
|
61 |
return "fail";
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
this.amount = payment.getAmount();
|
|
|
65 |
this.billingDetails = new ContactDetails(order.getCustomer_name(),
|
|
|
66 |
order.getCustomer_email(), order.getCustomer_address1(),
|
|
|
67 |
order.getCustomer_city(), order.getCustomer_state(),
|
|
|
68 |
order.getCustomer_pincode(), "IND",
|
|
|
69 |
order.getCustomer_mobilenumber());
|
|
|
70 |
|
|
|
71 |
log.info(billingDetails);
|
|
|
72 |
|
|
|
73 |
return "show";
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public void setId(String id) {
|
|
|
77 |
this.id = id;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public String getId() {
|
|
|
81 |
return id;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public String getAccountId() {
|
|
|
85 |
return accountId;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public static String getReturnUrl() {
|
|
|
89 |
return returnUrl;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
public static String getMode() {
|
|
|
93 |
return mode;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public double getAmount() {
|
|
|
97 |
return amount;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public ContactDetails getBillingDetails() {
|
|
|
101 |
return billingDetails;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
public static class ContactDetails{
|
|
|
105 |
private String name;
|
|
|
106 |
private String email;
|
|
|
107 |
private String address;
|
|
|
108 |
private String city;
|
|
|
109 |
private String state;
|
|
|
110 |
private String postalCode;
|
|
|
111 |
private String country;
|
|
|
112 |
private String phone;
|
|
|
113 |
|
|
|
114 |
public ContactDetails(String name, String email, String address,
|
|
|
115 |
String city, String state, String postalCode, String country,
|
|
|
116 |
String phone) {
|
|
|
117 |
this.name = name;
|
|
|
118 |
this.email = email;
|
|
|
119 |
this.address = address;
|
|
|
120 |
this.city = city;
|
|
|
121 |
this.state = state;
|
|
|
122 |
this.postalCode = postalCode;
|
|
|
123 |
this.country = country;
|
|
|
124 |
this.phone = phone;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
@Override
|
|
|
128 |
public String toString() {
|
|
|
129 |
return "ContactDetails [name=" + name + ", email=" + email
|
|
|
130 |
+ ", address=" + address + ", city=" + city + ", state="
|
|
|
131 |
+ state + ", postalCode=" + postalCode + ", country="
|
|
|
132 |
+ country + ", phone=" + phone + "]";
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public String getName() {
|
|
|
136 |
return name;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public String getEmail() {
|
|
|
140 |
return email;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public String getAddress() {
|
|
|
144 |
return address;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
public String getCity() {
|
|
|
148 |
return city;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
public String getState() {
|
|
|
152 |
return state;
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
public String getPostalCode() {
|
|
|
156 |
return postalCode;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
public String getCountry() {
|
|
|
160 |
return country;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
public String getPhone() {
|
|
|
164 |
return phone;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|