Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8842 anupam.sin 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.payments.Attribute;
4
import in.shop2020.payments.Payment;
5
import in.shop2020.payments.PaymentStatus;
6
import in.shop2020.thrift.clients.PaymentClient;
7
 
8
import java.util.ArrayList;
9
import java.util.List;
10
 
11
import org.apache.log4j.Logger;
12
 
13
public class HdfcEmiPaymentService implements IPaymentService {
14
    private static Logger log = Logger.getLogger(HdfcEmiPaymentService.class);
15
 
16
    private String redirectURL;
17
 
18
    public HdfcEmiPaymentService() {
19
 
20
    }
21
 
22
    public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
23
        log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through HDFC EMI");
24
        CommonPaymentService cps = new CommonPaymentService();
25
        if(!cps.createPayment(userId, txnId, gatewayId)){
26
            log.error("Error while creating the basic payment");
27
            return PAYMENT_NOT_CREATED;
28
        }else{
29
            return initializePayment(cps.getPaymentId(), paymentOption);
30
        }
31
    }
32
 
33
    private long initializePayment(long merchantPaymentId, String paymentOption){
34
        List<Attribute> attributes = new ArrayList<Attribute>();
35
        attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
36
        PaymentClient paymentServiceClient = null;
37
        try {
38
            paymentServiceClient = new PaymentClient();
39
        } catch (Exception e) {
40
            log.error("Error while getting payment client", e);
41
            return PAYMENT_NOT_CREATED;
42
        }
43
 
44
        try {
45
            paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
46
            this.redirectURL = paymentServiceClient.getClient().initializeHdfcEmiPayment(merchantPaymentId);
47
            return merchantPaymentId;
48
        }catch (Exception e) {
49
            log.error("Error while initializing payment.", e);
50
            return PAYMENT_NOT_CREATED;
51
        }
52
    }
53
 
54
    public String getRedirectUrl(){
55
        return this.redirectURL;
56
    }
57
 
58
    public static void main(String args[]){
59
        Payment payment = new Payment();
60
        payment.setPaymentId(216);
61
        payment.setAmount(40000);
62
        payment.setGatewayPaymentId("TESTSTSTS");
63
 
64
        // The underlying method calls are no longer valid since all the
65
        // information required to capture a payment is read from the database
66
        // itself and can't be specified through the call.
67
 
68
        //This test checks what happens when the txn id is left blank
69
        //capturePayment(payment, "");                  //Result: !ERROR!-GW00205-Invalid Subsequent Transaction.
70
 
71
        //This test checks what happends with an invalid txn id 
72
        //capturePayment(payment, "6022630101411740");  //Result: !ERROR!-GW00201-Transaction not found.
73
 
74
        //The next three tests require a valid AUTH transaction id.
75
        //This test checks what happens when we attempt to capture an amount greater than what was authorized.
76
        //capturePayment(payment, "9644960021411730");  //Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.
77
 
78
        //This test checks what happens when we attempt to capture a valid transaction with the right amount. This transaction should be CAPTURED.
79
        //payment.setAmount(21698);
80
        //capturePayment(payment, "9644960021411730");  //Result: CAPTURED
81
 
82
        //This test tries to capture an already captured payment.
83
        //capturePayment(payment, "9644960021411730");  //Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.
84
    }
85
 
86
}