Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nutty About Hosting 22 posts 75 karma points
    May 25, 2016 @ 15:10
    Nutty About Hosting
    0

    Reinstate basket after failed payment

    Hi Guys,

    Does anybody know if it's possible to restore a basket after a failed checkout?

    It seems that once we create the invoice we need to check out with the basket disappears - then if the payment fails or the user cancels the payment - the basket is no longer available.

    On the failed/cancelled payment I am deleting the invoice - but need the user to have their original basket in place for them to try again.

    Perhaps I am doing something wrong and the basket shouldn't be disappearing to begin with :)

    Cheers, Sean

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Sep 06, 2016 @ 09:37
    Simon Dingley
    0

    Hi Sean,

    Did you find a solution to this? I'm using the Authorize.net payment provider and when a payment fails followed by a payment success there are duplicate invoices in the system which could potentially cause confusion.

    Do you have a custom payment provider and hooking into a specific event to delete the invoice for the failed payment?

    Thanks, Simon

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 06, 2016 @ 13:22
    Rusty Swayne
    0

    The basket should not clear on a failed credit card charge, but the checkout manager must save an invoice prior to doing any operation with a payment provider since, in many cases the gateway wants the invoice number.

    In order to do a retry payment, you should get the invoice from the IPaymentResult returned from the first attempt ... if it failed:

     var attempt = checkoutManager.Payment.AuthorizeCapture( ...
     if (!attempt.Payment.Success) 
     {
           // basket should still contain items
    
           // log the failure           
    
           // for retry we need the user to correct the CC number
           // so we need to get it from them
    
           // make sure the invoice key is returned to you retry 
           // note: it should be since it's in the IPaymentResult
            // e.g.    var invoice = attempt.Invoice;
            //            var invoiceKey = invoice.Key;
    
           // or async JS
           var result = new { success: false, invoiceKey: invoice.Key.ToString(), translatedErrors: myPaymentErrorTransaltor(attempt.Payment.Exception.Message)  };
    
           // redirect or async JS response with appropriate value
           return [some ActionResult]
     }
     else
     {
         // SUCCESS
         // basket should be empty if the default CheckoutContxt 
         // setting is left true (this is configurable**) 
    
          CustomerContext.SetValue("invoiceKey", invoiceKey.ToString());
    
         // redirect to receipt 
     }
    

    In the retry controller method

      var paymentMethodKey = [method parameter?]
      var invoiceKey = [method parameter?];
      var invoice = invoiceService.GetByKey(invoiceKey);
    
      if (invoice != null) 
      {
            var retryAttempt = invoice.CapturePayment(...
    
            if (!retryAttempt.Payment.Success) 
            {
                  // basket should still be populated
    
                  // repeat retry process
            }
            else
            {
                  // basket should be empty (depending on CheckoutManager CheckoutContext setting)
    
    
                 CustomerContext.SetValue("invoiceKey", invoiceKey.ToString());
    
                  // redirect to receipt
            }
      }
    

    ** You can set the basket to not clear through the CheckoutManagers CheckoutContext setting EmptyBasketOnPaymentSuccess - set this to false and you'll have to empty it manually.

    Unless you are comfortable with the inner workings of the CheckoutManager, It's a probably a good idea to make certain you are using the SAME settings each time you instantiate the CheckoutManager throughout the entire Checkout or you may get results you don't expect =)

    You can set the default values in the merchello.config file

       <checkoutContextSettings>
          <setting alias="InvoiceNumberPrefix" value="FT" />
          <setting alias="ApplyTaxesToInvoice" value="true" />
          <setting alias="RaiseCustomerEvents" value="false" />
          <setting alias="ResetCustomerManagerDataOnVersionChange" value="false" />
          <setting alias="ResetPaymentManagerDataOnVersionChange" value="true" />
          <setting alias="ResetExtendedManagerDataOnVersionChange" value="true" />
          <setting alias="ResetShippingManagerDataOnVersionChange" value="true" />
          <setting alias="ResetOfferManagerDataOnVersionChange" value="true" />
          <setting alias="EmptyBasketOnPaymentSuccess" value="true" />
    </checkoutContextSettings>
    
Please Sign in or register to post replies

Write your reply to:

Draft