Subversion Repositories SmartDukaan

Rev

Rev 1905 | Rev 2118 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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