Subversion Repositories SmartDukaan

Rev

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

Rev 3561 Rev 3583
Line 1... Line 1...
1
package in.shop2020.serving.services;
1
package in.shop2020.serving.services;
2
 
2
 
3
import in.shop2020.payments.Attribute;
3
import in.shop2020.payments.Attribute;
4
import in.shop2020.payments.Payment;
-
 
5
import in.shop2020.payments.PaymentStatus;
4
import in.shop2020.payments.PaymentStatus;
6
import in.shop2020.payments.PaymentService.Client;
-
 
7
import in.shop2020.thrift.clients.PaymentClient;
5
import in.shop2020.thrift.clients.PaymentClient;
8
 
6
 
9
import java.util.ArrayList;
7
import java.util.ArrayList;
10
import java.util.HashMap;
-
 
11
import java.util.List;
8
import java.util.List;
12
import java.util.Map;
-
 
13
 
9
 
14
import org.apache.log4j.Logger;
10
import org.apache.log4j.Logger;
15
 
11
 
16
public class EbsPaymentService implements IPaymentService{
12
public class EbsPaymentService implements IPaymentService{
17
	
13
	
Line 56... Line 52...
56
		}
52
		}
57
 
53
 
58
		return paymentId;
54
		return paymentId;
59
	}
55
	}
60
 
56
 
61
	/**
-
 
62
	 * Capture the amount which was authorized for this payment Id. Makes
-
 
63
	 * requests over the network and so internet connectivity is must for it to
-
 
64
	 * succeed.
-
 
65
	 * 
-
 
66
	 * @param amount
-
 
67
	 *            The amount to be captured. Must be the same value which was
-
 
68
	 *            authorized for this payment.
-
 
69
	 * @param gatewayPaymentId
-
 
70
	 *            The payment ID generated by the gateway.
-
 
71
	 * @return A Map. The Map will definitely have status and will have error
-
 
72
	 *         information in case of error and txn information in case of
-
 
73
	 *         success. In case there is an error in processing, the returned
-
 
74
	 *         result map will be empty.
-
 
75
	 */
-
 
76
	public static Map<String, String> capturePayment(Payment payment, String gatewayPaymentId){
-
 
77
		String amount = "" + payment.getAmount();
-
 
78
		log.info("Capturing amount: Rs " + amount + " for payment Id: " + gatewayPaymentId);
-
 
79
	    Map<String, String> resultMap = new HashMap<String, String>();
-
 
80
 
-
 
81
	    //Prepare resultMap to elicit failure behaviour in case anything goes wrong.
-
 
82
	    resultMap.put(STATUS, "");
-
 
83
	    
-
 
84
		try {
-
 
85
			PaymentClient paymentServiceClient = new PaymentClient();
-
 
86
			Client paymentClient = paymentServiceClient.getClient();
-
 
87
			resultMap = paymentClient.captureEbsPayment(payment.getPaymentId());
-
 
88
		} catch (Exception e) {
-
 
89
			log.error("Unable to capture payment", e);
-
 
90
			resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
-
 
91
			resultMap.put(ERROR, "Unable to capture transaction.");
-
 
92
		}
-
 
93
	    
-
 
94
		return resultMap;
-
 
95
	}
-
 
96
 
-
 
97
	public static void main(String[] args){
57
	public static void main(String[] args){
98
		//capturePayment(30450.00, "2412653");
58
		//capturePayment(30450.00, "2412653");
99
		
59
		
100
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
60
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
101
 
61