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 :)
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?
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
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
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
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:
In the retry controller method
** 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
is working on a reply...