• Welcome to KonaKart Community Forum. Please login or sign up.
 

NullPointer when calling Paypal

Started by innes, June 09, 2008, 12:33:29 pm

Previous topic - Next topic

innes

Hi

I am planning to use Paypal for my payment gateway, however I have some free digital download products and I do not want to send my Customers to Paypal and back (not even sure how PayPal handles a free product) in order to enable the download link.

My solution (which may not be the best) was to create a Free payment gateway and a wrapper gateway that delegated to PayPal if the value is greater than zero or Free otherwise.

However, I get a null pointer when I call Paypal from my code.

The error is:
09-Jun 12:23:45 DEBUG (Eatacd.java:getPaymentDetails:115) Use PayPal Payment Gateway. Amount = 1.79000
09-Jun 12:23:45 ERROR (Eatacd.java:getPaymentDetails:124) Error getting Payment details (amount =  1.79000)
java.lang.NullPointerException
   at com.konakart.bl.modules.payment.paypal.Paypal.getPaymentDetails(Paypal.java:291)
   at com.konakart.bl.modules.payment.eatacd.Eatacd.getPaymentDetails(Eatacd.java:117)
   at com.konakart.bl.modules.payment.PaymentMgr.getPaymentGatewaysPrivate(Unknown Source)
   at com.konakart.bl.modules.payment.PaymentMgr.getPaymentGateways(Unknown Source)
   at com.konakart.app.KKEng.getPaymentGateways(Unknown Source)
   at com.konakart.app.GetPaymentGateways.getPaymentGateways(Unknown Source)
   at com.konakart.app.KKCustomEng.getPaymentGateways(KKCustomEng.java:2612)
   at com.konakart.server.KKGWTServiceImpl.getPaymentGateways(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:528)
   at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
   at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:187)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   at java.lang.Thread.run(Unknown Source)
09-Jun 12:23:45 INFO  (Eatacd.java:getPaymentDetails:127) Payment Details: null

My code is:

public PaymentDetails getPaymentDetails(Order order, PaymentInfo info)
         throws Exception {

      log.info("Order: " + order.getId());

      /*
       * Set PaymentInfo to require full details. Not sure why I need to
       * do this, suspect that it relates to disabling Free & PayPal and using
       * the EATCD Payment Gateway.
       */
      info.setReturnDetails(true);
      log.info("PaymentInfo: " + info.getStoreName() + " "
            + info.isReturnDetails() + " " + info.getLocale());
      PaymentDetails paymentDetails = null;
      BigDecimal amount = order.getTotalIncTax();

      try {
         if (amount.compareTo(BigDecimal.ZERO) == 0) {
            log.debug("Use Free Download Payment Gateway. Amount = "
                  + amount.toString());
            paymentDetails = this.freePaymentGateway.getPaymentDetails(
                  order, info);
         } else {
            log.debug("Use PayPal Payment Gateway. Amount = "
                  + amount.toString());
            paymentDetails = this.paypalPaymentGateway.getPaymentDetails(
                  order, info);
         }
      } catch (KKException e) {
         log.error("Error getting Payment details (amount =  "
               + amount.toString() + ")", e);
      } catch (Exception e) {
         log.error("Error getting Payment details (amount =  "
               + amount.toString() + ")", e);
      }
      log.info("Payment Details: " + paymentDetails);
      log.info("Order : " + order.toString());
      return paymentDetails;
   }


The error seems to be thrown at line 291 in Paypal.java:
for (int i = 0; i < order.getOrderTotals().length; i++)

I have tried following stack trace back to find where orderTotals is initialised but it seems to be in KKGWTServiceImpl?

Can you provide any guidance as to where orderTotals is initialised?

Couple of other things:  I have installed all 3 payment gateways (so their configurations are all in the DB) but have disabled Paypal and Free so that they are not provided in the Drop Down list on the confirmation page.

Thanks,

Innes

pete

Take a look at CheckoutConfirmationSubmitAction(). Maybe a nicer way of achieving your goal could be to detect that the total of the order is zero and do something similar to what you would do for COD (cash on delivery) except that the status of the order could be set to Delivered rather than Pending.