Subversion Repositories SmartDukaan

Rev

Rev 6482 | Rev 6503 | 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
 
3374 rajveer 4
include "GenericService.thrift"
5
 
121 ashish 6
/**
7
Various structures
8
**/
9
enum PaymentGatewayStatus{
10
	AVAILABLE,
11
	BLOCKED
12
}
13
 
14
enum PaymentStatus{
15
	INIT,
16
	PENDING,
1854 chandransh 17
	SUCCESS,	// HDFC Status: CAPTURED; EBS Status: Captured
18
	FAILED,		// HDFC status: NOT CAPTURED, DENIED BY RISK, HOST TIMEOUT, CANCELLED
3956 chandransh 19
	AUTHORIZED,  // EBS Status: Pending, HDFC Status: APPROVED
4421 mandeep.dh 20
	PARTIALLY_CAPTURED, //In case of COD
21
	CAPTURE_IN_PROCESS, // In case first few attempts to capture failed due to transient connections issues
6482 rajveer 22
	PROVISIONALLY_CAPTURED, // In case payment is not getting
23
	REFUNDED 
121 ashish 24
}
25
 
3270 vikas 26
// If new paymethod is added here, sales database for pentaho must also be updated.
2303 ankur.sing 27
const map<string,string> PAYMENT_METHOD = {
28
	'1001' : 'EBS-TEST Payment'
29
	'1004' : 'EBS-AXIS Bank Account'
30
	'1007' : 'EBS-HDFC Bank Account'
31
	'1008' : 'EBS-VISA'
32
	'1009' : 'EBS-Citi Bank Debit Card'
33
	'1010' : 'EBS-Diners Club'
34
	'1012' : 'EBS-ItzCash'
35
	'1015' : 'EBS-JK Bank Account'
36
	'1016' : 'EBS-ICICI Bank Account'
37
	'1017' : 'EBS-MasterCard'
38
	'1029' : 'EBS-Federal Bank Account'
39
	'1032' : 'EBS-State Bank of India Netbanking'
40
	'1033' : 'EBS-State Bank of Bikaner and Jaipur Netbanking'
41
	'1034' : 'EBS-State Bank of Hyderabad Netbanking'
42
	'1035' : 'EBS-State Bank of Patiala Netbanking'
43
	'1036' : 'EBS-State Bank of Shaurashtra Netbanking'
44
	'1037' : 'EBS-State Bank of Indore Netbanking'
45
	'1038' : 'EBS-State Bank of Mysore Netbanking'
46
	'1039' : 'EBS-State Bank of Travancore Netbanking'
47
	'1040' : 'EBS-Citi Bank Reward Point'
48
	'1127' : 'EBS-Citi Bank Account'
49
	'1132' : 'EBS-Done Card'
2574 chandransh 50
	'1133' : 'EBS-Karnataka Bank Account'
51
	'1134' : 'EBS-ICash'
52
	'1135' : 'EBS-Corporation Bank Account'
53
 	'2000' : 'HDFC-VISA/VISA Electron Debit Card'
2461 chandransh 54
	'2008' : 'HDFC-VISA'
5538 anupam.sin 55
	'2017' : 'HDFC-MasterCard Credit Card'
56
	'2018' : 'HDFC-MasterCard Debit Card'
3164 chandransh 57
	'3000' : 'COD'
3270 vikas 58
	'2001' : 'Cheque'
3274 vikas 59
	'1026' : 'EBS-ICICI Bank Debit Card'
60
    '1027' : 'EBS-SBI Debit Card'
3709 chandransh 61
    '2020' : 'HDFC Credit Card 3-month EMI'
6459 rajveer 62
    '5001' : 'HDFC Credit Card 3-month EMI'
63
    '5002' : 'HDFC Credit Card 6-month EMI'
64
    '5003' : 'HDFC Credit Card 9-month EMI'
65
    '5004' : 'HDFC Credit Card 12-month EMI'
5102 phani.kuma 66
    '1139' : 'EBS-VISA Credit Card 3-months EMI'
67
    '1140' : 'EBS-MasterCard Credit Card 3-months EMI'
68
    '1141' : 'EBS-VISA Credit Card 6-months EMI'
69
    '1142' : 'EBS-MasterCard Credit Card 6-months EMI'
70
    '1143' : 'EBS-Indian Bank Netbanking'
71
    '1164' : 'EBS-Maestro Debit Card'
3724 vikas 72
    '4000' : 'BULK'
3274 vikas 73
}
2303 ankur.sing 74
 
680 rajveer 75
struct Attribute{
76
	1:string name,
77
	2:string value
121 ashish 78
}
79
 
420 ashish 80
struct PaymentGateway{
121 ashish 81
	1:i64 id,
680 rajveer 82
	2:string name,
83
	3:string url,
84
	4:i64 addedOn,
85
	5:string aliasName,
86
	6:string responseUrl,
87
	7:string errorUrl,
88
	8:PaymentGatewayStatus status
89
	9:list<Attribute> attributes  // list of all attributes for PG
121 ashish 90
}
91
 
92
struct Payment{
680 rajveer 93
	1:i64 paymentId,  				// trackId for bank, paymentid for us and id for table.
94
	2:i64 gatewayId, 				//payment gateway used
95
	3:string gatewayPaymentId
704 chandransh 96
	4:i64 merchantTxnId,			//merchant transaction id. This will be propagated further to order processing
680 rajveer 97
	5:string gatewayTxnId,			//bank trnasaction id
98
	6:double amount,
99
	7:string gatewayTxnStatus,  	// bank status will be stored here
100
	8:PaymentStatus status,
101
	9:i64 userId,					//The user for which payment has to be processed.This is here to speed up querying.
102
	10:string errorCode,
103
	11:string description,
104
	12:string authCode,
105
	13:string referenceCode,		// given by gateway
106
	14:string sessionId, 			// received from PG 
107
	15:string gatewayTxnDate,
108
	16:list<Attribute> attributes,  	// list of all attributes received from PG
109
	17:i64 initTimestamp,			//statring the payment processing timestamp
110
	18:i64 successTimestamp,		//timestamp when payment is captured
111
	19:i64 errorTimestamp,			// in case, error is received from PG
6050 anupam.sin 112
	20:i64 provisionalCaptureTimestamp, // in case, error is received from PG
113
	21:bool isDigital
121 ashish 114
}
115
 
2747 chandransh 116
struct Refund{
117
	1:i64 id,
118
	2:i64 paymentId,
119
    3:i64 gatewayId,
120
    4:i64 orderId,
121
    5:double amount,
122
    6:string gatewayTxnId,
123
    7:i32 attempts,
124
    8:i64 createdAt,
125
    9:i64 processedAt,
126
    10:list<Attribute> attributes
127
}
121 ashish 128
 
129
exception PaymentException{
130
	1:i64 error_code,
131
	2:string message
132
}
133
 
4008 mandeep.dh 134
enum ExtraPaymentProcessingType {
4421 mandeep.dh 135
    FAILED_PAYMENTS,
136
    PENDING_CAPTURE
4008 mandeep.dh 137
}
138
 
3374 rajveer 139
service PaymentService extends GenericService.GenericService{
680 rajveer 140
	/**
4141 chandransh 141
	create a new payment and return payment id, throws an exception if gateway is not active
142
	*/
6050 anupam.sin 143
	i64 createPayment(1:i64 userId, 2:double amount, 3:i64 gatewayId, 4:i64 txnId, 5:bool isDigital) throws (1:PaymentException pe),
121 ashish 144
 
680 rajveer 145
	/**
4141 chandransh 146
	Get all payments for user. If status and gateway are null, they are ignored. Same for times as well.
147
	*/ 
680 rajveer 148
	list<Payment> getPaymentsForUser(1:i64 userId, 2:i64 fromTime, 3:i64 toTime, 4:PaymentStatus status, 5:i64 gatewayId) throws (1:PaymentException pe),
121 ashish 149
 
680 rajveer 150
	/**
4141 chandransh 151
	Get all payments in the given status for the given gateway. If gatewayId is 0, then it is ignored.
152
	*/ 
680 rajveer 153
	list<Payment> getPayments(1:i64 fromTime, 2:i64 toTime, 3:PaymentStatus status, 4:i64 gatewayId) throws (1:PaymentException pe),
121 ashish 154
 
4141 chandransh 155
	/**
156
	Get all payments for the given gateway which were captured between the given dates. If the gatewayId is 0, it's ignored.
157
	*/
158
	list<Payment> getPaymentsByCapturedDate(1:i64 fromTime, 2:i64 toTime, 3:i64 gatewayId) throws (1:PaymentException pe),	
121 ashish 159
 
680 rajveer 160
	/** 
4141 chandransh 161
	Get the gateway for the given id. 
162
	*/
680 rajveer 163
	PaymentGateway getPaymentGateway(1:i64 id) throws (1:PaymentException pe),
4600 varun.gupt 164
 
165
	/**
166
	 *Get all active Payment Gateways
167
	 **/
168
	list<PaymentGateway> getActivePaymentGateways() throws (1:PaymentException pe),
169
 
680 rajveer 170
	/** 
171
	* Get a particular payment info
172
	**/
420 ashish 173
	Payment getPayment(1:i64 id) throws (1:PaymentException pe),
680 rajveer 174
 
175
 
176
	/** 
4600 varun.gupt 177
	* Get payments for a transaction. Will raise exception.
680 rajveer 178
	**/
179
	list<Payment> getPaymentForTxnId(1:i64 txnId) throws (1:PaymentException pe),
121 ashish 180
 
4600 varun.gupt 181
	/** 
182
	* Get successful payment for a transaction. Will raise exception.
183
	**/
184
	Payment getSuccessfulPaymentForTxnId(1:i64 txnId) throws (1:PaymentException pe),
185
 
680 rajveer 186
	/**
187
	* mark payment successful and store parameters
188
	**/
1118 rajveer 189
	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 190
 
680 rajveer 191
	/**
192
	* mark payment failed and store parameters
694 rajveer 193
 
680 rajveer 194
	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 195
	*/
1731 ankur.sing 196
 
1628 ankur.sing 197
	/**
1731 ankur.sing 198
	Returns the minimum and maximum amounts among successful payments.
199
	List contains two double values, first minimum and second maximum amount.
1628 ankur.sing 200
	*/
2461 chandransh 201
	list<double> getSuccessfulPaymentsAmountRange(),
202
 
203
	/**
204
	Initialize the payment pipe for a HDFC payment. The URL the user should be redirected to is returned.
3010 chandransh 205
	In case of any processing error, an exception is raised.
2461 chandransh 206
	*/
2689 chandransh 207
	string initializeHdfcPayment(1:i64 merchantPaymentId) throws (1:PaymentException pe),
208
 
209
	/**
6050 anupam.sin 210
	Initialize the payment pipe for a HDFC payment in case of a digital order. The URL the user should be redirected to is returned.
6228 anupam.sin 211
	In case of any processing error, an exception is raised. The phone is a madatory field and is required in case of dth payments.
6050 anupam.sin 212
	*/
6228 anupam.sin 213
	string doHdfcPaymentForDigitalOrder(1:i64 merchantPaymentId, 2:i64 rechargeOrderId, string phone) throws (1:PaymentException pe),
6050 anupam.sin 214
 
215
	/**
3616 chandransh 216
	Initialize the payment pipe for a HDFC EMI payment. The URL the user should be redirected to is returned.
217
	In case of any processing error, an exception is raised.
218
	*/
219
	string initializeHdfcEmiPayment(1:i64 merchantPaymentId) throws (1:PaymentException pe),
220
 
221
	/**
2689 chandransh 222
	Create a refund of the given amount corresponding to the given order to be processed through the same
223
	payment gateway which processed the payment for the corresponding transaction.
224
	Returns the id of the newly created Refund.
225
	*/	
3010 chandransh 226
	i64 createRefund(1:i64 orderId, 2:i64 merchantTxnId, 3:double amount) throws (1:PaymentException pe),
227
 
228
	/**
229
	Capture the payment for the given merchant transaction id. It processes the last payment for the given
4421 mandeep.dh 230
	transaction. If the capture attempt failed, the payment is marked as failed. PaymentException with error 
6486 rajveer 231
	code 104 is	thrown in case no payments are found for the transaction id passed. PaymentException is also
232
	thrown with error code 106 in case capture was not possible due to connection
233
	issue. 
234
	*/
235
	bool capturePayment(1:i64 merchantTxnId) throws (1:PaymentException pe),
236
 
237
	/**
238
	Refund the payment for the given merchant transaction id. It processes the last payment for the given
239
	transaction. PaymentException with error code 104 is thrown in case no payments are found for the transaction id passed.
4421 mandeep.dh 240
	PaymentException is also thrown with error code 106 in case capture was not possible due to connection
241
	issue. Here, we	payment also gets updated to CAPTURE_INPROCESS state
3010 chandransh 242
	*/
6486 rajveer 243
	bool refundPayment(1:i64 merchantTxnId, 2:double amount, 3:bool isDigital) throws (1:PaymentException pe),
3956 chandransh 244
 
6486 rajveer 245
 
3956 chandransh 246
	/**
247
	Adds the given amount to the captured amount of a COD payment.
248
	Updates the captured amount for the corresponding payment and marks it as PARTIALLY CAPTURED.
249
	If the captured amount becomes equal to total amount, then the payment status is set as SUCCESS.
250
	Also sets the name of the entity which transferred the money, the date on which it was transferred
251
	and the corresponding transaction id.
252
 
253
	Returns false if the payment couldn't be captured.
254
	Throws exception if no such payment could be found or if the captured amount will exceed the total amount after capturing.
255
	*/
4008 mandeep.dh 256
	bool partiallyCapturePayment(1:i64 merchantTxnId, 2:double amount, 3:string xferBy, 4:string xferTxnId, 5:i64 xferDate) throws (1:PaymentException pe),
257
 
258
    /**
259
     * Returns the list of payments that require some extra processing and
260
     * which belong to a particular category. This is currently used by CRM
261
     * application.
262
     */
263
    list<i64> getPaymentsRequiringExtraProcessing(1:ExtraPaymentProcessingType category),
264
 
265
    /**
266
     * Marks a particular payment as processed for a particular cateogory.
267
     * It essentially deletes the payment if it is processed for a particular
268
     * category. This is currently used by CRM application.
269
     */
270
    void markPaymentAsProcessed(1:i64 paymentId, 2:ExtraPaymentProcessingType category)
121 ashish 271
}