Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
121 ashish 1
namespace java in.shop2020.payments
420 ashish 2
namespace py shop2020.thriftpy.payments
121 ashish 3
 
4
/**
5
Various structures
6
**/
7
enum PaymentGatewayStatus{
8
	AVAILABLE,
9
	BLOCKED
10
}
11
 
12
enum PaymentStatus{
13
	INIT,
14
	PENDING,
1854 chandransh 15
	SUCCESS,	// HDFC Status: CAPTURED; EBS Status: Captured
16
	FAILED,		// HDFC status: NOT CAPTURED, DENIED BY RISK, HOST TIMEOUT, CANCELLED
17
	AUTHORIZED  // EBS Status: Pending
121 ashish 18
}
19
 
2303 ankur.sing 20
const map<string,string> PAYMENT_METHOD = {
21
	'1001' : 'EBS-TEST Payment'
22
	'1004' : 'EBS-AXIS Bank Account'
23
	'1007' : 'EBS-HDFC Bank Account'
24
	'1008' : 'EBS-VISA'
25
	'1009' : 'EBS-Citi Bank Debit Card'
26
	'1010' : 'EBS-Diners Club'
27
	'1012' : 'EBS-ItzCash'
28
	'1015' : 'EBS-JK Bank Account'
29
	'1016' : 'EBS-ICICI Bank Account'
30
	'1017' : 'EBS-MasterCard'
31
	'1029' : 'EBS-Federal Bank Account'
32
	'1032' : 'EBS-State Bank of India Netbanking'
33
	'1033' : 'EBS-State Bank of Bikaner and Jaipur Netbanking'
34
	'1034' : 'EBS-State Bank of Hyderabad Netbanking'
35
	'1035' : 'EBS-State Bank of Patiala Netbanking'
36
	'1036' : 'EBS-State Bank of Shaurashtra Netbanking'
37
	'1037' : 'EBS-State Bank of Indore Netbanking'
38
	'1038' : 'EBS-State Bank of Mysore Netbanking'
39
	'1039' : 'EBS-State Bank of Travancore Netbanking'
40
	'1040' : 'EBS-Citi Bank Reward Point'
41
	'1127' : 'EBS-Citi Bank Account'
42
	'1132' : 'EBS-Done Card'
2574 chandransh 43
	'1133' : 'EBS-Karnataka Bank Account'
44
	'1134' : 'EBS-ICash'
45
	'1135' : 'EBS-Corporation Bank Account'
46
 	'2000' : 'HDFC-VISA/VISA Electron Debit Card'
2461 chandransh 47
	'2008' : 'HDFC-VISA'
48
	'2017' : 'HDFC-MasterCard'
2303 ankur.sing 49
}
50
 
680 rajveer 51
struct Attribute{
52
	1:string name,
53
	2:string value
121 ashish 54
}
55
 
420 ashish 56
struct PaymentGateway{
121 ashish 57
	1:i64 id,
680 rajveer 58
	2:string name,
59
	3:string url,
60
	4:i64 addedOn,
61
	5:string aliasName,
62
	6:string responseUrl,
63
	7:string errorUrl,
64
	8:PaymentGatewayStatus status
65
	9:list<Attribute> attributes  // list of all attributes for PG
121 ashish 66
}
67
 
68
struct Payment{
680 rajveer 69
	1:i64 paymentId,  				// trackId for bank, paymentid for us and id for table.
70
	2:i64 gatewayId, 				//payment gateway used
71
	3:string gatewayPaymentId
704 chandransh 72
	4:i64 merchantTxnId,			//merchant transaction id. This will be propagated further to order processing
680 rajveer 73
	5:string gatewayTxnId,			//bank trnasaction id
74
	6:double amount,
75
	7:string gatewayTxnStatus,  	// bank status will be stored here
76
	8:PaymentStatus status,
77
	9:i64 userId,					//The user for which payment has to be processed.This is here to speed up querying.
78
	10:string errorCode,
79
	11:string description,
80
	12:string authCode,
81
	13:string referenceCode,		// given by gateway
82
	14:string sessionId, 			// received from PG 
83
	15:string gatewayTxnDate,
84
	16:list<Attribute> attributes,  	// list of all attributes received from PG
85
	17:i64 initTimestamp,			//statring the payment processing timestamp
86
	18:i64 successTimestamp,		//timestamp when payment is captured
87
	19:i64 errorTimestamp,			// in case, error is received from PG
121 ashish 88
}
89
 
2747 chandransh 90
struct Refund{
91
	1:i64 id,
92
	2:i64 paymentId,
93
    3:i64 gatewayId,
94
    4:i64 orderId,
95
    5:double amount,
96
    6:string gatewayTxnId,
97
    7:i32 attempts,
98
    8:i64 createdAt,
99
    9:i64 processedAt,
100
    10:list<Attribute> attributes
101
}
121 ashish 102
 
103
exception PaymentException{
104
	1:i64 error_code,
105
	2:string message
106
}
107
 
108
service PaymentService{
680 rajveer 109
	/**
763 rajveer 110
	* For closing the open session in sqlalchemy
111
	*/
112
	void closeSession(),
113
 
114
	/**
680 rajveer 115
	*	create a new payment and return payment id, throws an exception if gateway is not active
116
	**/
117
	i64 createPayment(1:i64 userId, 2:double amount, 3:i64 gatewayId, 4:i64 txnId) throws (1:PaymentException pe),
121 ashish 118
 
680 rajveer 119
	/**
120
	* get payment for user. If status and gateway are null, it is ignored. Same for times as well.
121
	**/ 
122
	list<Payment> getPaymentsForUser(1:i64 userId, 2:i64 fromTime, 3:i64 toTime, 4:PaymentStatus status, 5:i64 gatewayId) throws (1:PaymentException pe),
121 ashish 123
 
680 rajveer 124
	/**
2059 ankur.sing 125
	* get all payments for user. If gatewayId is 0, then it is ignored while filtering.
680 rajveer 126
	**/ 
127
	list<Payment> getPayments(1:i64 fromTime, 2:i64 toTime, 3:PaymentStatus status, 4:i64 gatewayId) throws (1:PaymentException pe),
121 ashish 128
 
129
 
680 rajveer 130
	/** 
131
	* Get a particular gateway
132
	**/
133
	PaymentGateway getPaymentGateway(1:i64 id) throws (1:PaymentException pe),
134
 
135
	/** 
136
	* Get a particular payment info
137
	**/
420 ashish 138
	Payment getPayment(1:i64 id) throws (1:PaymentException pe),
680 rajveer 139
 
140
 
141
	/** 
142
	* Get a particular payment for a transaction. Will raise exception.
143
	**/
144
	list<Payment> getPaymentForTxnId(1:i64 txnId) throws (1:PaymentException pe),
121 ashish 145
 
680 rajveer 146
	/**
147
	* mark payment successful and store parameters
148
	**/
1118 rajveer 149
	bool updatePaymentDetails(1:i64 id, 2:string gatewayPaymentId, 3:string sessionId, 4:string gatewayTxnStatus, 5:string  description, 6:string gatewayTxnId, 7:string authCode, 8:string referenceCode, 9:string errorCode, 10:PaymentStatus  status, 11:string gatewayTxnDate, 12:list<Attribute> attributes) throws (1:PaymentException pe),
420 ashish 150
 
680 rajveer 151
	/**
152
	* mark payment failed and store parameters
694 rajveer 153
 
680 rajveer 154
	bool markPaymentFailed(1:i64 id, 2:string gatewayPaymentId, 3:string sessionId, 4:string gatewayTxnStatus, 5:string description, 6:string errorCode, 7:list<Attribute> attributes )  throws (1:PaymentException pe)
694 rajveer 155
	*/
1731 ankur.sing 156
 
1628 ankur.sing 157
	/**
1731 ankur.sing 158
	Returns the minimum and maximum amounts among successful payments.
159
	List contains two double values, first minimum and second maximum amount.
1628 ankur.sing 160
	*/
2461 chandransh 161
	list<double> getSuccessfulPaymentsAmountRange(),
162
 
163
	/**
164
	Update the authorization attributes of the payment and attempt to capture it in case it was authorized.
165
	If either the authorization failed or the capture attempt failed, the payment is marked as failed.
166
	*/
167
	Payment updateAndCaptureEbsPayment(1:map<string, string> paymentParams) throws (1:PaymentException pe),
168
 
169
	/**
2708 chandransh 170
	Captures an already authorized EBS Payment and returns a map containing the details of the captured transaction
2461 chandransh 171
	*/
2708 chandransh 172
	map<string, string> captureEbsPayment(1:i64 merchantPaymentId) throws (1:PaymentException pe),
173
 
174
	/**
175
	Captures an already authorized Hdfc Payment and returns a map containing the details of the captured transaction
176
	*/
2461 chandransh 177
	map<string, string> captureHdfcPayment(1:i64 merchantPaymentId) throws (1:PaymentException pe),
178
 
179
	/**
180
	Initialize the payment pipe for a HDFC payment. The URL the user should be redirected to is returned.
181
	In case of any processing error, an exception is raised. 
182
	*/
2689 chandransh 183
	string initializeHdfcPayment(1:i64 merchantPaymentId) throws (1:PaymentException pe),
184
 
185
	/**
186
	Create a refund of the given amount corresponding to the given order to be processed through the same
187
	payment gateway which processed the payment for the corresponding transaction.
188
	Returns the id of the newly created Refund.
189
	*/	
190
	i64 createRefund(1:i64 orderId, 2:i64 merchantTxnId, 3:double amount) throws (1:PaymentException pe)
121 ashish 191
}