I am currently wiring up a single-page checkout, starting with the walkthrough here (http://merchello.com/documentation/getting-started/how-to/Simple-Checkout-Process) and here (http://merchello.com/documentation/api/basket/orderprep). I also had to piece together additional documentation to get the Stripe payment gateway, and shippable items (using a simple US flat-rate and Everywhere Else flat-rate) working. So far, it works.. somewhat. The issues I am running into with the code below are:
Even though my country code is "US", the system returns the "Everywhere Else" shipping method when I call `shipment.ShipmentRateQuotes(false)`
If credit card payment fails (i.e. invalid CC#), I still see an invoice generated in the dashboard.
If credit card payment fails, each successive failure adds the shipping amount again, resulting in a wrong subtotal. If the original subtotal is $15 with $5 shipping, the first invoice shows total $20, the 2nd invoice shows total $25, third $30, and so on. Even stranger, opening the invoice only shows the $15 worth of items and $5 shipping total, with a $30 balance due?
Any help will be greatly appreciated. Obviously, this is rough and will be cleaned up once I get it all working, so I apologize if it's hard to read. I'm hoping something obvious is out of place:
[HttpPost] public ActionResult Checkout(CheckoutViewModel model) { // STEP 1: Save Billing/Shipping Address var preparation = base.Cart.SalePreparation(); var billaddress = model.BillingAddress.ToAddress(); preparation.SaveBillToAddress(billaddress); var shipaddress = model.ShippingAddress.ToAddress(); preparation.SaveShipToAddress(shipaddress);
// STEP 2: Package into shipments var shipments = base.Cart.PackageBasket(shipaddress);
// STEP 3: Shipping Method foreach (var shipment in shipments) { var quotes = shipment.ShipmentRateQuotes(false); preparation.SaveShipmentRateQuote(quotes.FirstOrDefault()); }
// STEP 4: Payment // has error occurred bool error = false; // do we raise events bool raiseEvents = false; // payment attempt result information IPaymentResult attempt = null; // get payment method var paymentMethod = Payment.GetPaymentGatewayMethodByKey(model.PaymentMethodKey).PaymentMethod;
// get customer, items // Save the payment method selection preparation.SavePaymentMethod(paymentMethod); // make sure there is a billing address - it can be empty - it just has to exist if (!preparation.IsReadyToInvoice()) return Redirect("/cart");
var args = new ProcessorArgumentCollection(); args.Add("cardholderName", preparation.GetBillToAddress().Name); args.Add("cardNumber", model.CreditCardNumber); args.Add("expireMonth", model.ExpirationMonth); args.Add("expireYear", model.ExpirationYear); args.Add("cardCode", model.Cvv); attempt = preparation.AuthorizePayment(paymentMethod.Key, args);
// if payment isn't successful, grab some information if (!attempt.Payment.Success) { error = true; // TBD - Not in Merchello yet // Notification.Trigger("OrderConfirmationFailure", attempt, new[] { preparation.GetBillToAddress().Email }); _log.CreateAuditLogWithKey("Checkout failed - attempt payment failure", preparation.Customer.ExtendedData); return CurrentUmbracoPage(); }
// STEP 5: Create the invoice preparation.PrepareInvoice(); // trigger the order notification confirmation Notification.Trigger("OrderConfirmation", attempt, new[] { preparation.GetBillToAddress().Email });
RESOLVED - The country code wasn't being saved correctly, so the incorrect shipping method is my fault
NOT RESOLVED - I found that the invoice is being created on following line. Is this by design? Am I supposed to delete the invoice if payment fails? If so, how?
RESOLVED - Apparently I need to clear the shipment rate quotes prior to looping through the shipments and adding shipping costs via preparation.ClearShipmentRateQuotes();
Merchello splits the concepts of an invoice and a payment, so that you can e.g. take a manual payment at a later point. As you discovered the invoice is being created by your payment method's base AuthorizePayment. (so you don't need to create in manually in Step 5)
You can delete the invoice if payment fails with something like the following
Checkout issues
I am currently wiring up a single-page checkout, starting with the walkthrough here (http://merchello.com/documentation/getting-started/how-to/Simple-Checkout-Process) and here (http://merchello.com/documentation/api/basket/orderprep). I also had to piece together additional documentation to get the Stripe payment gateway, and shippable items (using a simple US flat-rate and Everywhere Else flat-rate) working. So far, it works.. somewhat. The issues I am running into with the code below are:
Any help will be greatly appreciated. Obviously, this is rough and will be cleaned up once I get it all working, so I apologize if it's hard to read. I'm hoping something obvious is out of place:
Update:
RESOLVED - Apparently I need to clear the shipment rate quotes prior to looping through the shipments and adding shipping costs via
preparation.ClearShipmentRateQuotes();
Still haven't figured this one out yet - does anyone know why a new invoice is being created when payment fails, based on my code above?
Hi Keith,
Merchello splits the concepts of an invoice and a payment, so that you can e.g. take a manual payment at a later point. As you discovered the invoice is being created by your payment method's base AuthorizePayment. (so you don't need to create in manually in Step 5)
You can delete the invoice if payment fails with something like the following
is working on a reply...