Page 1 of 1

Custom payment module w/failure = empty cart

Posted: Tue Aug 13, 2013 11:40 pm
by tduffey
I must be missing something...I implemented my own payment module and when there is a failure I set the transaction success to false. This redirects the customer back to the checkout page with the expected error processing payment. What's weird is that the rest of the checkout workflow continues, including completing the order, and then something is resetting the cart. If you try to fix the problem, e.g., re-enter your credit card information, you get a number of errors because the cart has been reset to NullCartImpl.

How can I prevent losing the customer's cart when payment processing fails to let them try again?

Tom

Re: Custom payment module w/failure = empty cart

Posted: Wed Aug 14, 2013 12:00 am
by tduffey
Digging a little deeper I see that during a subsequent request after failed checkout, the CartStateRequestProcessor filter is unable to find a cart for the customer and sets it back to the null order. This is because the order that was IN_PROCESS was set to SUBMITTED even though there was a payment error.

Did I miss some configuration or how do we stop the checkout workflow when a payment error occurs?

Tom

Re: Custom payment module w/failure = empty cart

Posted: Wed Aug 14, 2013 7:57 am
by tduffey
Figured out one part of this. There is a setting that controls whether or not a "single payment failure" stops the checkout process. I put this in common-shared.properties:

Code: Select all

stop.checkout.on.single.payment.failure=true


This preserves the customer's cart but of course now there is a duplicate key exception if the customer tries to place the order again...

Re: Custom payment module w/failure = empty cart

Posted: Wed Aug 14, 2013 9:41 am
by phillipuniverse
Which version of Broadleaf are you on?

Re: Custom payment module w/failure = empty cart

Posted: Wed Aug 14, 2013 9:43 am
by tduffey
3.0.1-GA although the original DemoSite we started from might have been 3.0.0

Re: Custom payment module w/failure = empty cart

Posted: Wed Aug 14, 2013 11:09 am
by tduffey
Looking at the diff from DemoSite 3.0.0 to 3.0.1 I don't see anything real important (Besides the pom updates to use Broadleaf 3.0.1-GA, which we have already incorporated). Here is the error we're getting. I will have more time to dig into this later today.

Code: Select all

org.springframework.dao.DataIntegrityViolationException: ERROR: duplicate key value violates unique constraint "uk9517a14fd790debd"
  Detail: Key (reference_number)=(1201) already exists.; SQL [n/a]; constraint [uk9517a14fd790debd]; nested exception is org.hibernate.exception.ConstraintViolationException: ERROR: duplicate key value violates unique constraint "uk9517a14fd790debd"
  Detail: Key (reference_number)=(1201) already exists.
   org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:643)
   org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:105)
   org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
   org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
   org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
   org.broadleafcommerce.core.order.service.OrderServiceImpl.finalizeTransaction(OrderServiceImpl.java:321)
   org.broadleafcommerce.core.order.service.OrderServiceImpl.save(OrderServiceImpl.java:231)
   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
   com.sun.proxy.$Proxy255.save(Unknown Source)
   org.broadleafcommerce.core.checkout.service.CheckoutServiceImpl.performCheckout(CheckoutServiceImpl.java:69)
   org.broadleafcommerce.core.web.controller.checkout.BroadleafCheckoutController.completeSecureCreditCardCheckout(BroadleafCheckoutController.java:416)
   com.sartoricheese.controller.checkout.CheckoutController.completeSecureCreditCardCheckout(CheckoutController.java:127)
   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
        ...

Re: Custom payment module w/failure = empty cart

Posted: Wed Aug 14, 2013 5:50 pm
by tduffey
Seems to me that either OrderService.removePaymentsFromOrder() needs to also remove any related PaymentResponseItem records or that the delete should cascade. Feedback appreciated since I am new to Broadleaf and might have done something stupid but for now we'll override the OrderService method.

Tom

Re: Custom payment module w/failure = empty cart

Posted: Thu Aug 15, 2013 9:21 am
by tduffey