Subversion Repositories SmartDukaan

Rev

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