/// <summary> /// Does the actual work of voiding a payment /// </summary> /// <param name="invoice">The invoice to which the payment is associated</param> /// <param name="payment">The payment to be voided</param> /// <param name="args">Additional arguements required by the payment processor</param> /// <returns>A <see cref="IPaymentResult"/></returns> protected override IPaymentResult PerformVoidPayment(IInvoice invoice, IPayment payment, ProcessorArgumentCollection args) { var result = _processor.VoidPayment(invoice, payment); if (!result.Payment.Success) { GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, result.Payment.Exception.Message, 0); return(result); } // use the overloaded AppliedPayments method here for testing if we don't have // a MerchelloContext foreach (var applied in payment.AppliedPayments(GatewayProviderService)) { applied.TransactionType = AppliedPaymentType.Refund; applied.Amount = 0; applied.Description += " - **Void**"; GatewayProviderService.Save(applied); } payment.Voided = true; GatewayProviderService.Save(payment); return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, false)); }