Subversion Repositories SmartDukaan

Rev

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