Subversion Repositories SmartDukaan

Rev

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