Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
9103 anupam.sin 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.payments.Attribute;
4
import in.shop2020.payments.PaymentStatus;
5
import in.shop2020.thrift.clients.PaymentClient;
6
 
7
import java.util.ArrayList;
8
import java.util.List;
9
 
10
import org.apache.log4j.Logger;
11
 
12
public class CodPaymentService implements IPaymentService {
13
 
14
    private static Logger log = Logger.getLogger(Class.class);
15
 
16
    private long paymentId;
17
 
18
    @Override
19
    public long createPayment(long userId, long txnId, String paymentOption, int gatewayId) {
20
        log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through COD");
21
        CommonPaymentService cps = new CommonPaymentService();
22
        if(!cps.createPayment(userId, txnId, gatewayId)){
23
            log.error("Error while creating the basic payment");
24
            return PAYMENT_NOT_CREATED;
25
        }
26
        paymentId = cps.getPaymentId();
27
 
28
        if(paymentOption != null){
29
            List<Attribute> attributes = new ArrayList<Attribute>();
30
            attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
31
 
32
            try {
33
                PaymentClient paymentServiceClient = new PaymentClient();
34
                paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
35
            } catch (Exception e) {
36
                log.error("Error while saving payment option attribute", e);
37
                // TODO: We've already created the payment. We could allow the
38
                // payment to go through. The customer will be a little
39
                // annoyed to have to select from a host of options again but
40
                // will be better than completely disallowing him.
41
                return PAYMENT_NOT_CREATED;
42
            }
43
        }
44
 
45
        return paymentId;
46
    }
47
}