Subversion Repositories SmartDukaan

Rev

Rev 7323 | Rev 7360 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7323 Rev 7343
Line 5... Line 5...
5
import java.util.Calendar;
5
import java.util.Calendar;
6
import java.util.Date;
6
import java.util.Date;
7
import java.util.List;
7
import java.util.List;
8
import java.util.Random;
8
import java.util.Random;
9
 
9
 
-
 
10
import org.apache.struts2.convention.annotation.Result;
-
 
11
import org.apache.struts2.convention.annotation.Results;
10
import org.apache.thrift.TException;
12
import org.apache.thrift.TException;
11
import org.apache.thrift.transport.TTransportException;
13
import org.apache.thrift.transport.TTransportException;
12
 
14
 
13
import in.shop2020.logistics.PickUpType;
15
import in.shop2020.logistics.PickUpType;
14
import in.shop2020.model.v1.catalog.Item;
16
import in.shop2020.model.v1.catalog.Item;
Line 32... Line 34...
32
import in.shop2020.utils.Mail;
34
import in.shop2020.utils.Mail;
33
 
35
 
34
import in.shop2020.serving.controllers.BaseController;
36
import in.shop2020.serving.controllers.BaseController;
35
import in.shop2020.serving.utils.FormattingUtils;
37
import in.shop2020.serving.utils.FormattingUtils;
36
 
38
 
-
 
39
@Results({
-
 
40
    @Result(name="order-success-redirect", type="redirectAction", params = {"actionName", "order-success", "paymentId", "${paymentId}", "userId", "${userId}"})
-
 
41
})
-
 
42
 
37
public class PaymentDetailsController  extends BaseController {
43
public class PaymentDetailsController  extends BaseController {
38
    
44
    
39
    /**
45
    /**
40
     * 
46
     * 
41
     */
47
     */
Line 58... Line 64...
58
    private Double advanceAmount;
64
    private Double advanceAmount;
59
    private String deliveryDate = "";
65
    private String deliveryDate = "";
60
    private String productName = "";
66
    private String productName = "";
61
    private String bestDealText = "";
67
    private String bestDealText = "";
62
    private String CatalogItemId = "";
68
    private String CatalogItemId = "";
-
 
69
    private long paymentId;
-
 
70
    private long userId;
-
 
71
    
63
    
72
    
64
    private FormattingUtils formattingUtils = new FormattingUtils();
-
 
65
    private StorePricing sp;
73
    private StorePricing sp;
66
    
74
    
67
    public String index() {
75
    public String index() {
68
        return INDEX;
76
        return INDEX;
69
    }
77
    }
Line 71... Line 79...
71
    public String create(){
79
    public String create(){
72
        return index();
80
        return index();
73
    }
81
    }
74
    
82
    
75
    public String persistTransaction() {
83
    public String persistTransaction() {
76
        
-
 
77
        /**
-
 
78
         * 0.Create user
-
 
79
         * 1.Make a transaction object comprised of Order which in turn contains lineitem.
-
 
80
         * 2.Call create_transaction
-
 
81
         * 3.retrieve that order
-
 
82
         */
-
 
83
        
-
 
84
        Transaction txnObj = new Transaction();
84
        Transaction txnObj = new Transaction();
85
        
85
        
86
        long tempUserId = -1;
-
 
87
        Long merchantPaymentId = 0l;
-
 
88
 
-
 
89
        if(email != null && !email.isEmpty()) {
86
        if(email != null && !email.isEmpty()) {
90
            tempUserId = createUserAndSendMail(email);
87
            userId = createUserAndSendMail(email);
91
        } else {
88
        } else {
92
            try {
89
            try {
93
                TransactionClient tcl = new TransactionClient();
90
                TransactionClient tcl = new TransactionClient();
94
                //Source Id for store website is 2 and our normal website is 1
91
                //Source Id for store website is 2 and our normal website is 1
95
                SourceDetail detail = tcl.getClient().getSourceDetail(2);
92
                SourceDetail detail = tcl.getClient().getSourceDetail(2);
96
                
93
                
97
                tempUserId = createUserAndSendMail(detail.getEmail());
94
                userId = createUserAndSendMail(detail.getEmail());
98
            } catch(Exception e) {
95
            } catch(Exception e) {
99
                log.error("Unable to get default source", e);
96
                log.error("Unable to get default source", e);
100
            }
97
            }
101
        }
98
        }
102
        
99
        
103
        if(tempUserId == -1) {
100
        if(userId == -1) {
104
            log.error("Unable to get a user, terminating the transaction");
101
            log.error("Unable to get a user, terminating the transaction");
105
            setErrorMsg("Unable to create a user for this order. Please try again.");
102
            setErrorMsg("Unable to create a user for this order. Please try again.");
106
            return "error-result";
103
            return "error-result";
107
        }
104
        }
108
        
105
        
109
        txnObj.setShoppingCartid(0);
106
        txnObj.setShoppingCartid(0);
110
        txnObj.setCustomer_id(tempUserId);
107
        txnObj.setCustomer_id(userId);
111
        txnObj.setCreatedOn(Calendar.getInstance().getTimeInMillis());
108
        txnObj.setCreatedOn(Calendar.getInstance().getTimeInMillis());
112
        txnObj.setTransactionStatus(TransactionStatus.INIT);
109
        txnObj.setTransactionStatus(TransactionStatus.INIT);
113
        txnObj.setStatusDescription("New Store Order");
110
        txnObj.setStatusDescription("New Store Order");
114
        txnObj.setCoupon_code("");
111
        txnObj.setCoupon_code("");
115
        txnObj.setEmiSchemeId(0);
112
        txnObj.setEmiSchemeId(0);
116
        
113
        
117
        Order order = createOrder(tempUserId);
114
        Order order = createOrder(userId);
118
        
115
        
119
        if(order ==  null) {
116
        if(order ==  null) {
120
            log.error("Unable to create transaction");
117
            log.error("Unable to create transaction");
121
            setErrorMsg("Unable to create order. Please try again.");
118
            setErrorMsg("Unable to create order. Please try again.");
122
            return "error-result";
119
            return "error-result";
Line 136... Line 133...
136
        }
133
        }
137
        
134
        
138
        PaymentClient pcl;
135
        PaymentClient pcl;
139
        try {
136
        try {
140
            pcl = new PaymentClient();
137
            pcl = new PaymentClient();
141
            merchantPaymentId = pcl.getClient().createPayment(tempUserId, price, 10, txnId, true);
138
            paymentId = pcl.getClient().createPayment(userId, price, 10, txnId, true);
142
            //Update payment status as authorized
139
            //Update payment status as authorized
143
            pcl.getClient().updatePaymentDetails(merchantPaymentId, "", "", "0", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
140
            pcl.getClient().updatePaymentDetails(paymentId, "", "", "0", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
144
            txnId = pcl.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
141
            txnId = pcl.getClient().getPayment(paymentId).getMerchantTxnId();
145
        } catch(Exception e) {
142
        } catch(Exception e) {
146
            log.error("Unable to create payment for this order");
143
            log.error("Unable to create payment for this order");
147
            setErrorMsg("Unable to create order. Please try again.");
144
            setErrorMsg("Unable to create order. Please try again.");
148
            return "error-result";
145
            return "error-result";
149
        }
146
        }
Line 165... Line 162...
165
            log.error("Unable to create transaction", e);
162
            log.error("Unable to create transaction", e);
166
            setErrorMsg("Unable to create order. Please try again.");
163
            setErrorMsg("Unable to create order. Please try again.");
167
            return "error-result";
164
            return "error-result";
168
        }
165
        }
169
        
166
        
170
        
-
 
171
        try {
-
 
172
            pcl = new PaymentClient();
-
 
173
            
-
 
174
            orders = tcl.getClient().getOrdersForTransaction(txnId, tempUserId);
-
 
175
        } catch (Exception e) {
-
 
176
            log.error("Unable to retrieve orders");
-
 
177
            setErrorMsg("Order was created but due to some error we could not display it. Please try again.");
-
 
178
        }
-
 
179
        
-
 
180
        return "order-success";
167
        return "order-success-redirect";
181
    }
168
    }
182
    
169
    
183
    public Order createOrder(long userId) {
170
    public Order createOrder(long userId) {
184
        LineItem lineObj = createLineItem();
171
        LineItem lineObj = createLineItem();
185
        if (lineObj == null) {
172
        if (lineObj == null) {
Line 422... Line 409...
422
 
409
 
423
    public String getDeliveryDate() {
410
    public String getDeliveryDate() {
424
        return deliveryDate;
411
        return deliveryDate;
425
    }
412
    }
426
    
413
    
427
    public String formatPrice(double price)    {
-
 
428
        return formattingUtils.formatPrice(price);
-
 
429
    }
-
 
430
    
-
 
431
    public static String formatDate(long timestamp){
-
 
432
        SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
-
 
433
        return dateformat.format(new Date(timestamp));  
-
 
434
    }
-
 
435
 
-
 
436
    public String getProductName() {
414
    public String getProductName() {
437
        return productName;
415
        return productName;
438
    }
416
    }
439
 
417
 
440
    public void setProductName(String productName) {
418
    public void setProductName(String productName) {
Line 459... Line 437...
459
    }
437
    }
460
 
438
 
461
    public void setCatalogItemId(String catalogItemId) {
439
    public void setCatalogItemId(String catalogItemId) {
462
        CatalogItemId = catalogItemId;
440
        CatalogItemId = catalogItemId;
463
    }
441
    }
-
 
442
 
-
 
443
    public long getPaymentId() {
-
 
444
        return paymentId;
-
 
445
    }
-
 
446
 
-
 
447
    public void setPaymentId(long paymentId) {
-
 
448
        this.paymentId = paymentId;
-
 
449
    }
-
 
450
 
-
 
451
    public long getUserId() {
-
 
452
        return userId;
-
 
453
    }
-
 
454
 
-
 
455
    public void setUserId(long userId) {
-
 
456
        this.userId = userId;
-
 
457
    }
464
}
458
}