Is there a way to get current invoice object during checkout?
From BasketCheckoutPaymentManager.cs file, there is a method (AuthorizePayment). Inside this method, there is a way to get invoice object:
/// <summary>
/// Attempts to process a payment
/// </summary>
/// <param name="paymentGatewayMethod">The <see cref="IPaymentGatewayMethod"/> to use in processing the payment</param>
/// <param name="args">Additional arguments required by the payment processor</param>
/// <returns>The <see cref="IPaymentResult"/></returns>
public override IPaymentResult AuthorizePayment(IPaymentGatewayMethod paymentGatewayMethod, ProcessorArgumentCollection args)
{
Mandate.ParameterNotNull(paymentGatewayMethod, "paymentGatewayMethod");
if (!this.IsReadyToInvoice()) return new PaymentResult(Attempt<IPayment>.Fail(new InvalidOperationException("SalesPreparation is not ready to invoice")), null, false);
// invoice
var invoice = this.PrepareInvoice(this.InvoiceBuilder);
this.Context.Services.InvoiceService.Save(invoice);
var result = invoice.AuthorizePayment(paymentGatewayMethod, args);
if (result.Payment.Success && this.Context.Settings.EmptyBasketOnPaymentSuccess) this.Context.Customer.Basket().Empty();
this.OnFinalizing(result);
return result;
}
var invoice = this.PrepareInvoice(this.InvoiceBuilder);
My work is focus on My Payment Controller Base. So how can I get invoice object in Process method?
Note: When user click Finish & Pay. The debug line will stop at Process method inside my payment controller base class. From there, I want to get current invoice to do some stuff like retrieve order total, order items, etc...
As you've found, the PrepareInvoice method builds an invoice from the checkout manager data but does not save it. This is the method of generating an sales summary without generating a bunch of invoice numbers and persisted records.
However, to clarify your finding above, the invoice IS saved internally in the CheckoutManager payment methods -
CheckoutManager.Payment.Authorize
CheckoutManager.Payment.AuthorizeCapture
so you should not need to save again once you get the payment result.
How to get current invoice?
Hello,
Is there a way to get current invoice object during checkout?
From BasketCheckoutPaymentManager.cs file, there is a method (AuthorizePayment). Inside this method, there is a way to get invoice object:
My work is focus on My Payment Controller Base. So how can I get invoice object in Process method?
Note: When user click Finish & Pay. The debug line will stop at Process method inside my payment controller base class. From there, I want to get current invoice to do some stuff like retrieve order total, order items, etc...
From other post, I have got a way to prepare an invoice in my payment base class.
If the payment is success, don't forget to then save the invoice after you are done with it.
See the following resources for additional information which might help you:
https://merchello.readme.io/docs/checkoutmanager
https://merchello.readme.io/docs/checkoutmanager#icheckoutpaymentmanager
Hey Nguyen,
As you've found, the
PrepareInvoice
method builds an invoice from the checkout manager data but does not save it. This is the method of generating an sales summary without generating a bunch of invoice numbers and persisted records.However, to clarify your finding above, the invoice IS saved internally in the CheckoutManager payment methods -
so you should not need to save again once you get the payment result.
is working on a reply...