Subversion Repositories SmartDukaan

Rev

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