Copied to clipboard

Flag this post as spam?

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


  • Ben McKean 272 posts 549 karma points
    Aug 25, 2016 @ 12:57
    Ben McKean
    0

    Merchello - Duplicate orders when doing authorize before capture

    Hi,

    I'm using a custom payment provider for Stripe payments. In my checkout flow, I authorise the payment midway through the process and then I capture the payment on the final step. All of this works fine apart from two orders are created in Merchello. Everything in Stripe is fine, the initial auth is captured (no duplicates) but in Merchello I get a new order and therefore the order IDs that I have are out of sync between Merchello and Stripe.

    Anybody had anything similar, anything to look out for?

    Thanks

    Ben

  • Ben McKean 272 posts 549 karma points
    Aug 25, 2016 @ 13:54
    Ben McKean
    0

    Think I've found a way round this for anybody else who comes across it.

    Previously I was using:

    checkoutManager.Payment.AuthorizeCapturePayment

    which was creating another order, so I've changed this to:

    paymentMethod.CapturePayment

    and it works correctly now

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 25, 2016 @ 15:15
    Rusty Swayne
    0

    Hey Ben,

    It makes sense that two orders were created if you were calling Authorize and then AuthorizeCapture.

    An invoice is saved with both the Authorize and the AuthorizeCapture (which is returned in the IPaymentResult even if the result itself is not successful).

    The use case:

    Customer attempts to authorize a payment used credit card 1 - which fails.

    You can then grab the invoice from the payment result and authorize again using a second credit using the invoice created during the first operation on the retry. IInvoice has as set of extension methods to handle payments as well.

     var invoice = attempt1.Invoice;
      invoice.Authorize( ... 2nd payment method ... );
    

    Likewise you can capture the payment directly from the invoice.

    When calling AuthorizeCapture, the payment provider generally tries to perform both operations at the same time (as a single operation - like a credit card charge) - but it still returns an invoice in the IPaymentResult.

    So in the event of AuthorizeCapture attempt Success == false you can then grab the invoice from the first result and then capture the payment via the invoice returned as a retry ...

    Make sense?

    Alternatively, like in the PayPalExpressProvider where we have to authorize and then capture (due to the redirects), on a retry, we have to delete the first invoice and then allow the second authorize to create another one for the capture. If I remember correctly, there are some code comments around this in that provider and possibly a TODO to see if it can be refactored since the bump in invoice number sequence is not optimal - but it works well and accomplishes what it needs to.

  • Ben McKean 272 posts 549 karma points
    Aug 26, 2016 @ 14:28
    Ben McKean
    0

    Hi Rusty,

    Now that I have implemented this, my GetCheckoutManager no longer seems to be getting saved.

    The flow of my checkout is

    1. Billing details
    2. Card details (authorise)
    3. Additional field (saved as note using Extend
    4. Confirm (which now uses invoice.capture)

    Previously, when I was doing an authroziecapture at the end it was adding my note but its no longer doing this.

    Am I missing something?

    Thanks

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 26, 2016 @ 17:34
    Rusty Swayne
    0

    The CheckoutManager associates the notes when it prepares the invoice. If you need to add a note after the invoice has been prepared, add it to the invoice directly and resave the invoice.

    This is how the notes are added when the invoice is created:

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/Workflow/InvoiceCreation/CheckoutManager/AddNotesToInvoiceTask.cs

  • Ben McKean 272 posts 549 karma points
    Aug 25, 2016 @ 15:27
    Ben McKean
    0

    Thanks Rusty, that makes sense.

    I've done it with paymentMethod.Capture for now

Please Sign in or register to post replies

Write your reply to:

Draft