001: /*
002: * Created on Oct 5, 2004
003: */
004: package org.openedit.cart.paypal;
005:
006: import org.apache.commons.logging.Log;
007: import org.apache.commons.logging.LogFactory;
008: import org.openedit.store.CreditPaymentMethod;
009: import org.openedit.store.Store;
010: import org.openedit.store.StoreException;
011: import org.openedit.store.orders.BaseOrderProcessor;
012: import org.openedit.store.orders.Order;
013: import org.openedit.store.orders.OrderProcessor;
014:
015: import com.openedit.ModuleManager;
016: import com.openedit.WebPageRequest;
017: import com.openedit.modules.email.PostMail;
018: import com.openedit.page.manage.PageManager;
019:
020: /**
021: * @author Ian Miller, ian@ijsolutions.ca
022: *
023: */
024: public class PaypalOrderProcessor extends BaseOrderProcessor implements
025: OrderProcessor {
026: private static final Log log = LogFactory
027: .getLog(PaypalOrderProcessor.class);
028: protected PageManager fieldPageManager;
029: private PostMail postMail;
030: protected PaypalUtil fieldPaypalUtil;
031: protected ModuleManager fieldModuleManager;
032:
033: public ModuleManager getModuleManager() {
034: return fieldModuleManager;
035: }
036:
037: public void setModuleManager(ModuleManager moduleManager) {
038: this .fieldModuleManager = moduleManager;
039: }
040:
041: public PostMail getPostMail() {
042: return postMail;
043: }
044:
045: public void setPostMail(PostMail postMail) {
046: this .postMail = postMail;
047: }
048:
049: /* (non-javadoc)
050: * @see com.openedit.store.OrderArchive#exportNewOrder(com.openedit.store.Cart)
051: */
052: public void processNewOrder(WebPageRequest inContext,
053: Store inStore, Order inOrder) throws StoreException {
054: String usepaypal = inContext.getPageProperty("usepaypal");
055: if (Boolean.parseBoolean(usepaypal)) {
056: try {
057: String result = getPaypalUtil().handlePDT(inContext);
058: inContext.putPageValue("paymentResult", result);
059: if ("SUCCESS".equals(result)) {
060:
061: CreditPaymentMethod creditCard = (CreditPaymentMethod) inOrder
062: .getPaymentMethod();
063: creditCard
064: .setNote(creditCard.getNote()
065: + "(This was a paypal credit card payment)");
066: inOrder.getOrderState().setOk(true);
067:
068: } else {
069: log.info("paypal validation false");
070: inOrder.getOrderState().setOk(false);
071: }
072: } catch (Exception e) {
073: return;
074: }
075:
076: //inOrder.getOrderState().setDescription("Order accepted");
077: }
078: return;
079:
080: }
081:
082: /**
083: * @param inOrder
084: * @return
085: */
086: protected boolean requiresValidation(Order inOrder) {
087:
088: return inOrder.getPaymentMethod().requiresValidation();
089: }
090:
091: protected PageManager getPageManager() {
092: return fieldPageManager;
093: }
094:
095: public void setPageManager(PageManager inPageManager) {
096: fieldPageManager = inPageManager;
097: }
098:
099: public PaypalUtil getPaypalUtil() {
100: if (fieldPaypalUtil == null) {
101: fieldPaypalUtil = new PaypalUtil();
102:
103: }
104:
105: return fieldPaypalUtil;
106: }
107:
108: public void setPaypalUtil(PaypalUtil paypalUtil) {
109: this.fieldPaypalUtil = paypalUtil;
110: }
111:
112: }
|