Subversion Repositories SmartDukaan

Rev

Rev 3616 | Rev 6390 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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