Subversion Repositories SmartDukaan

Rev

Rev 6390 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3063 chandransh 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.payments.Attribute;
4
import in.shop2020.payments.PaymentStatus;
3126 rajveer 5
import in.shop2020.thrift.clients.PaymentClient;
3063 chandransh 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
20278 aman.kumar 19
    public long createPayment(long userId, long txnId, String paymentOption, int gatewayId,String paymentType) {
3063 chandransh 20
        log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through COD");
21
        CommonPaymentService cps = new CommonPaymentService();
6390 rajveer 22
        if(!cps.createPayment(userId, txnId, gatewayId)){
3063 chandransh 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));
20278 aman.kumar 31
            attributes.add(new Attribute(IPaymentService.PAYMENT_TYPE, paymentType));
3063 chandransh 32
 
33
            try {
3126 rajveer 34
                PaymentClient paymentServiceClient = new PaymentClient();
3063 chandransh 35
                paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
36
            } catch (Exception e) {
37
                log.error("Error while saving payment option attribute", e);
38
                // TODO: We've already created the payment. We could allow the
39
                // payment to go through. The customer will be a little
40
                // annoyed to have to select from a host of options again but
41
                // will be better than completely disallowing him.
42
                return PAYMENT_NOT_CREATED;
43
            }
44
        }
45
 
46
        return paymentId;
47
    }
48
}