Subversion Repositories SmartDukaan

Rev

Rev 6050 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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