Subversion Repositories SmartDukaan

Rev

Rev 6420 | Rev 6503 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6420 Rev 6491
Line 45... Line 45...
45
    private static final String currencyCode = "356";
45
    private static final String currencyCode = "356";
46
	private static final String resourceFileName = "resource.cgn";
46
	private static final String resourceFileName = "resource.cgn";
47
	
47
	
48
    private enum ActionType{
48
    private enum ActionType{
49
        PURCHASE("1"),
49
        PURCHASE("1"),
-
 
50
        REFUND ("2"),
50
        AUTH ("4"),
51
        AUTH ("4"),
51
        CAPTURE("5");
52
        CAPTURE("5");
52
        private String value;
53
        private String value;
53
        ActionType(String value) {
54
        ActionType(String value) {
54
            this.value = value;
55
            this.value = value;
Line 170... Line 171...
170
        }
171
        }
171
                        
172
                        
172
        return resultMap;
173
        return resultMap;
173
    }
174
    }
174
    
175
    
-
 
176
    public static Map<String, String> refundPayment(Payment payment, double amount){
-
 
177
    	String ramount = "" + amount;
-
 
178
        String gatewayPaymentId = payment.getGatewayPaymentId();
-
 
179
        log.info("Refunding amount: Rs " + amount + " for payment Id: " + gatewayPaymentId);
-
 
180
        
-
 
181
        String aliasName = null;
-
 
182
		try {
-
 
183
			aliasName = ConfigClient.getClient().get("emi_payment_alias_name" + payment.getGatewayId());
-
 
184
		} catch (ConfigException e1) {
-
 
185
			e1.printStackTrace();
-
 
186
		}
-
 
187
		String resourceDirPath = "/tmp/emi-resource/" + payment.getGatewayId() + "/";
-
 
188
 
-
 
189
        //Prepare resultMap to elicit failure behaviour in case anything goes wrong.
-
 
190
        Map<String, String> resultMap = new HashMap<String, String>();
-
 
191
        resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
-
 
192
        resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
-
 
193
        resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
-
 
194
        
-
 
195
        e24TranPipe pipe = new e24TranPipe();
-
 
196
        pipe.setResourcePath(resourceDirPath);
-
 
197
        pipe.setAlias(aliasName);
-
 
198
        pipe.setAction(ActionType.REFUND.value());
-
 
199
        pipe.setAmt(ramount);
-
 
200
        pipe.setTrackId("" + payment.getId());
-
 
201
        pipe.setMember("SAHOLIC");
-
 
202
        pipe.setCurrencyCode(currencyCode);
-
 
203
        pipe.setTransId(payment.getGatewayTxnId());
-
 
204
        
-
 
205
        //Check if the values have been set properly
-
 
206
        log.info("Pipe Amount: " + pipe.getAmt());
-
 
207
        log.info("Pipe Action Code: " + pipe.getAction());
-
 
208
        log.info("Pipe Currency Code: " + pipe.getCurrencyCode());
-
 
209
        log.info("Pipe Track Id: " + pipe.getTrackId());
-
 
210
        log.info("Pipe Trans Id:" + pipe.getTransId());
-
 
211
        
-
 
212
        int refundStatus = e24TranPipe.FAILURE;
-
 
213
        try {
-
 
214
            refundStatus = pipe.performTransaction();
-
 
215
            
-
 
216
            log.info("Refund Status: " + refundStatus);
-
 
217
            log.info("Gateway Txn Status: " + pipe.getResult());
-
 
218
            log.info("Debug Msg: " + pipe.getDebugMsg());
-
 
219
            log.info("Auth: " + pipe.getAuth());
-
 
220
            log.info("Ref: " + pipe.getRef());
-
 
221
            log.info("TransId:" + pipe.getTransId());
-
 
222
            log.info("Amount: " + pipe.getAmt());
-
 
223
            
-
 
224
            resultMap.put(STATUS, "" + refundStatus);
-
 
225
            String result = pipe.getResult();
-
 
226
            resultMap.put(GATEWAY_STATUS, result.substring(0, Math.min(result.length(), 20)).trim());       //This will return the result of the transaction. (Successful or Failed)
-
 
227
            if(refundStatus != e24TranPipe.SUCCESS || !"CAPTURED".equals(result)){
-
 
228
                resultMap.put(ERROR, pipe.getErrorMsg());               // In case of any error, we only need to get the error message
-
 
229
 
-
 
230
                if (refundStatus == CAPTURE_STATUS_FOR_CONNECTION_ISSUE) {
-
 
231
                    resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
-
 
232
                }
-
 
233
            }
-
 
234
            else {
-
 
235
                resultMap.put(CAPTURE_AUTH_ID, pipe.getAuth());         // Unique ID generated by Authorizer of the transaction
-
 
236
                resultMap.put(CAPTURE_REF_ID, pipe.getRef());           // Unique reference number generated during the transaction
-
 
237
                resultMap.put(CAPTURE_TXN_ID, pipe.getTransId());       // Unique Transaction ID generated after every successful transaction
-
 
238
                resultMap.put(CAPTURE_AMNT, pipe.getAmt());         // Original Amount of the transaction
-
 
239
            }
-
 
240
        } catch (NotEnoughDataException e) {
-
 
241
            log.error(Errors.CAPTURE_FAILURE.message, e);
-
 
242
            resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
-
 
243
            resultMap.put(ERROR, e.getMessage());
-
 
244
        }
-
 
245
                        
-
 
246
        return resultMap;
-
 
247
    }
-
 
248
    
-
 
249
    
175
    public static String initializeHdfcPayment(Payment payment, PaymentServiceHandler handler) throws Exception{
250
    public static String initializeHdfcPayment(Payment payment, PaymentServiceHandler handler) throws Exception{
176
        long merchantPaymentId = payment.getId();
251
        long merchantPaymentId = payment.getId();
177
        double amount = payment.getAmount();
252
        double amount = payment.getAmount();
178
        e24PaymentPipe pipe = new e24PaymentPipe();
253
        e24PaymentPipe pipe = new e24PaymentPipe();
179
        
254