Subversion Repositories SmartDukaan

Rev

Rev 3126 | Rev 6050 | Go to most recent revision | 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 static int gatewayId=4;
17
    private long paymentId;
18
 
19
    @Override
3561 rajveer 20
    public long createPayment(long currentCartId, long userId, long txnId, String paymentOption, long sourceId) {
3063 chandransh 21
        log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through COD");
22
        CommonPaymentService cps = new CommonPaymentService();
3561 rajveer 23
        if(!cps.createPayment(currentCartId, userId, txnId, gatewayId, sourceId)){
3063 chandransh 24
            log.error("Error while creating the basic payment");
25
            return PAYMENT_NOT_CREATED;
26
        }
27
        paymentId = cps.getPaymentId();
28
 
29
        if(paymentOption != null){
30
            List<Attribute> attributes = new ArrayList<Attribute>();
31
            attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
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
}