protected override IPaymentResult PerformCapturePayment(IInvoice invoice, IPayment payment, decimal amount, ProcessorArgumentCollection args) { var payedTotalList = invoice.AppliedPayments().Select(item => item.Amount).ToList(); var payedTotal = (payedTotalList.Count == 0 ? 0 : payedTotalList.Aggregate((a, b) => a + b)); var isPartialPayment = amount + payedTotal < invoice.Total; var result = _processor.CapturePayment(invoice, payment, amount, isPartialPayment); //GatewayProviderService.Save(payment); if (!result.Payment.Success) { //payment.VoidPayment(invoice, payment.PaymentMethodKey.Value); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, "PayPal: request capture error: " + result.Payment.Exception.Message, 0); } else { GatewayProviderService.Save(payment); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "PayPal: captured", amount); //GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.CaptureTransactionResult), amount); } return(result); }
protected override IPaymentResult PerformCapturePayment(IInvoice invoice, IPayment payment, decimal amount, ProcessorArgumentCollection args) { var payedTotalList = invoice.AppliedPayments().Select(item => item.Amount).ToList(); var payedTotal = (payedTotalList.Count == 0 ? 0 : payedTotalList.Aggregate((a, b) => a + b)); var isPartialPayment = amount + payedTotal < invoice.Total; var result = _processor.CapturePayment(invoice, payment, amount, isPartialPayment); //GatewayProviderService.Save(payment); if (!result.Payment.Success) { //payment.VoidPayment(invoice, payment.PaymentMethodKey.Value); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, "PayPal: request capture error: " + result.Payment.Exception.Message, 0); } else { GatewayProviderService.Save(payment); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "PayPal: captured", amount); //GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.CaptureTransactionResult), amount); } return result; }
private decimal CalculateTotalOwed(IInvoice invoice) { var applied = invoice.AppliedPayments(GatewayProviderService).ToArray(); var owed = applied.Where( x => x.TransactionType.Equals(AppliedPaymentType.Debit)) .Select(y => y.Amount) .Sum() - applied.Where( x => x.TransactionType.Equals(AppliedPaymentType.Credit)) .Select(y => y.Amount) .Sum(); return(owed); }
/// <summary> /// The calculate total owed. /// </summary> /// <param name="invoice"> /// The invoice. /// </param> /// <returns> /// The <see cref="decimal"/>. /// </returns> protected decimal CalculateTotalOwed(IInvoice invoice) { var applied = invoice.AppliedPayments(this.GatewayProviderService).ToArray(); var owed = applied.Where( x => x.AppliedPaymentTfKey.Equals( EnumTypeFieldConverter.AppliedPayment.GetTypeField(AppliedPaymentType.Debit).TypeKey)) .Select(y => y.Amount) .Sum() - applied.Where( x => x.AppliedPaymentTfKey.Equals( EnumTypeFieldConverter.AppliedPayment.GetTypeField(AppliedPaymentType.Credit).TypeKey)) .Select(y => y.Amount) .Sum(); return(owed); }
/// <summary> /// Returns a collection of <see cref="IAppliedPayment"/> for this <see cref="IInvoice"/> /// </summary> /// <param name="invoice">The <see cref="IInvoice"/></param> /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param> /// <returns>A collection of <see cref="IAppliedPayment"/></returns> internal static IEnumerable <IAppliedPayment> AppliedPayments( this IInvoice invoice, IMerchelloContext merchelloContext) { return(invoice.AppliedPayments(merchelloContext.Services.GatewayProviderService)); }
/// <summary> /// Returns a collection of <see cref="IAppliedPayment"/> for the invoice /// </summary> /// <param name="invoice">The <see cref="IInvoice"/></param> /// <returns>A collection of <see cref="IAppliedPayment"/></returns> public static IEnumerable <IAppliedPayment> AppliedPayments(this IInvoice invoice) { return(invoice.AppliedPayments(MerchelloContext.Current)); }
/// <summary> /// The calculate total owed. /// </summary> /// <param name="invoice"> /// The invoice. /// </param> /// <returns> /// The <see cref="decimal"/>. /// </returns> private decimal CalculateTotalOwed(IInvoice invoice) { var applied = invoice.AppliedPayments(GatewayProviderService).ToArray(); var owed = applied.Where( x => x.AppliedPaymentTfKey.Equals( EnumTypeFieldConverter.AppliedPayment.GetTypeField(AppliedPaymentType.Debit).TypeKey)) .Select(y => y.Amount) .Sum() - applied.Where( x => x.AppliedPaymentTfKey.Equals( EnumTypeFieldConverter.AppliedPayment.GetTypeField(AppliedPaymentType.Credit).TypeKey)) .Select(y => y.Amount) .Sum(); return owed; }