I created a simple controller to process payments (the gateway uses jquery and it's rather simple so I didn't create a payment gateway, just a custom form).
I then use the GatewayProviderService to create an IPayment, save it and apply it using ApplyPaymentToInvoice (I saw these from the payment providers' demo).
The payment shows up fine in Merchello, and balance is zero, but in the sales listing the invoice still shows an Unpaid Status. How do we change this to correctly reflect the payment?
@Pantelis - typically this is done in the PaymentGatewayMethodBase which internally uses a private method to assert the invoice status:
I think in your case, the method can be simplified since you know it is an authorize or capture by your result during execution, but the entire method is
/// <summary>
/// Validates the invoice status is correct after a payment request
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
private void AssertInvoiceStatus(IInvoice invoice)
{
var appliedPayments = _gatewayProviderService.GetAppliedPaymentsByInvoiceKey(invoice.Key).ToArray();
var appliedTotal =
appliedPayments.Where(x => x.TransactionType == AppliedPaymentType.Debit).Sum(x => x.Amount) -
appliedPayments.Where(x => x.TransactionType == AppliedPaymentType.Credit).Sum(x => x.Amount);
var statuses = GatewayProviderService.GetAllInvoiceStatuses().ToArray();
if (invoice.Total > appliedTotal && invoice.InvoiceStatusKey != Core.Constants.DefaultKeys.InvoiceStatus.Partial)
invoice.InvoiceStatus = statuses.First(x => x.Key == Core.Constants.DefaultKeys.InvoiceStatus.Partial);
if (appliedTotal == 0 && invoice.InvoiceStatusKey != Core.Constants.DefaultKeys.InvoiceStatus.Unpaid)
invoice.InvoiceStatus = statuses.First(x => x.Key == Core.Constants.DefaultKeys.InvoiceStatus.Unpaid);
if (invoice.Total <= appliedTotal && invoice.InvoiceStatusKey != Core.Constants.DefaultKeys.InvoiceStatus.Paid)
invoice.InvoiceStatus = statuses.First(x => x.Key == Core.Constants.DefaultKeys.InvoiceStatus.Paid);
if(invoice.IsDirty()) GatewayProviderService.Save(invoice);
}
Properly capture a custom payment
Hi,
I created a simple controller to process payments (the gateway uses jquery and it's rather simple so I didn't create a payment gateway, just a custom form).
I then use the GatewayProviderService to create an IPayment, save it and apply it using ApplyPaymentToInvoice (I saw these from the payment providers' demo).
The payment shows up fine in Merchello, and balance is zero, but in the sales listing the invoice still shows an Unpaid Status. How do we change this to correctly reflect the payment?
Thank you, Pantelis
@Pantelis - typically this is done in the PaymentGatewayMethodBase which internally uses a private method to assert the invoice status:
I think in your case, the method can be simplified since you know it is an authorize or capture by your result during execution, but the entire method is
is working on a reply...