/// <summary> /// Performs the capture payment operation. /// </summary> /// <param name="invoice"> /// The invoice. /// </param> /// <param name="payment"> /// The payment. /// </param> /// <param name="amount"> /// The amount. /// </param> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="IPaymentResult"/>. /// </returns> protected override IPaymentResult PerformCapturePayment(IInvoice invoice, IPayment payment, decimal amount, ProcessorArgumentCollection args) { // We need to determine if the entire amount authorized has been collected before marking // the payment collected. var appliedPayments = GatewayProviderService.GetAppliedPaymentsByPaymentKey(payment.Key); var applied = appliedPayments.Sum(x => x.Amount); var isPartialPayment = amount - applied <= 0; var processor = new PayPalExpressCheckoutPaymentProcessor(_paypalApiService); var record = processor.VerifySuccessAuthorziation(invoice, payment); if (record.Success) { record = _paypalApiService.ExpressCheckout.Capture(invoice, payment, amount, isPartialPayment); payment.SavePayPalTransactionRecord(record); payment.Collected = (amount + applied) == payment.Amount; payment.Authorized = true; GatewayProviderService.Save(payment); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "PayPal ExpressCheckout SUCCESS payment", amount); return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0)); } return(new PaymentResult(Attempt <IPayment> .Fail(payment), invoice, false)); }
/// <summary> /// Performs the capture payment operation. /// </summary> /// <param name="invoice"> /// The invoice. /// </param> /// <param name="payment"> /// The payment. /// </param> /// <param name="amount"> /// The amount. /// </param> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="IPaymentResult"/>. /// </returns> protected override IPaymentResult PerformCapturePayment(IInvoice invoice, IPayment payment, decimal amount, ProcessorArgumentCollection args) { // We need to determine if the entire amount authorized has been collected before marking // the payment collected. var appliedPayments = GatewayProviderService.GetAppliedPaymentsByPaymentKey(payment.Key); var applied = appliedPayments.Sum(x => x.Amount); var isPartialPayment = amount - applied <= 0; var processor = new PayPalExpressCheckoutPaymentProcessor(_paypalApiService); var record = processor.VerifySuccessAuthorziation(invoice, payment); if (record.Success) { record = _paypalApiService.ExpressCheckout.Capture(invoice, payment, amount, isPartialPayment); payment.SavePayPalTransactionRecord(record); payment.Collected = (amount + applied) == payment.Amount; payment.Authorized = true; GatewayProviderService.Save(payment); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "PayPal ExpressCheckout SUCCESS payment", amount); return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0); } return new PaymentResult(Attempt<IPayment>.Fail(payment), invoice, false); }