/// <summary> /// Does the actual work of authorizing and capturing a payment /// </summary> /// <param name="invoice">The <see cref="IInvoice"/></param> /// <param name="amount">The amount to capture</param> /// <param name="args">Any arguments required to process the payment.</param> /// <returns>The <see cref="IPaymentResult"/></returns> protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args) { var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, amount, PaymentMethod.Key); payment.CustomerKey = invoice.CustomerKey; payment.PaymentMethodName = PaymentMethod.Name; payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber(); payment.Collected = true; payment.Authorized = true; var po = args.AsPurchaseOrderFormData(); if (string.IsNullOrEmpty(po.PurchaseOrderNumber)) { return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception("Error Purchase Order Number is empty")), invoice, false)); } invoice.PoNumber = po.PurchaseOrderNumber; MerchelloContext.Current.Services.InvoiceService.Save(invoice); GatewayProviderService.Save(payment); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Cash payment", amount); return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0)); }
private IPaymentResult ProcessPayment(IInvoice invoice, TransactionMode transactionMode, decimal amount, ProcessorArgumentCollection args) { var po = args.AsPurchaseOrderFormData(); var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, invoice.Total, PaymentMethod.Key); payment.CustomerKey = invoice.CustomerKey; payment.Authorized = false; payment.Collected = false; payment.PaymentMethodName = "Purchase Order"; var result = _processor.ProcessPayment(invoice, payment, amount, po); GatewayProviderService.Save(payment); if (!result.Payment.Success) { GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, result.Payment.Exception.Message, 0); } else { MerchelloContext.Current.Services.InvoiceService.Save(invoice, false); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.AuthorizationTransactionResult) + (transactionMode == TransactionMode.AuthorizeAndCapture ? string.Empty : " to show record of Authorization"), transactionMode == TransactionMode.AuthorizeAndCapture ? invoice.Total : 0); } return result; }
/// <summary> /// The process payment. /// </summary> /// <param name="invoice"> /// The invoice. /// </param> /// <param name="transactionMode"> /// The transaction mode. /// </param> /// <param name="amount"> /// The amount. /// </param> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="IPaymentResult"/>. /// </returns> private IPaymentResult ProcessPayment(IInvoice invoice, TransactionMode transactionMode, decimal amount, ProcessorArgumentCollection args) { var po = args.AsPurchaseOrderFormData(); var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, invoice.Total, PaymentMethod.Key); payment.CustomerKey = invoice.CustomerKey; payment.Authorized = false; payment.Collected = false; payment.PaymentMethodName = "Purchase Order"; var result = _processor.ProcessPayment(invoice, payment, amount, po); GatewayProviderService.Save(payment); if (!result.Payment.Success) { GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, result.Payment.Exception.Message, 0); } else { MerchelloContext.Current.Services.InvoiceService.Save(invoice, false); GatewayProviderService.ApplyPaymentToInvoice( payment.Key, invoice.Key, AppliedPaymentType.Debit, payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.AuthorizationTransactionResult) + (transactionMode == TransactionMode.AuthorizeAndCapture ? string.Empty : " to show record of Authorization"), transactionMode == TransactionMode.AuthorizeAndCapture ? invoice.Total : 0); } return(result); }
/// <summary> /// Does the actual work of creating and processing the payment /// </summary> /// <param name="invoice">The <see cref="IInvoice"/></param> /// <param name="args">Any arguments required to process the payment.</param> /// <returns>The <see cref="IPaymentResult"/></returns> protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args) { var po = args.AsPurchaseOrderFormData(); var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, invoice.Total, PaymentMethod.Key); payment.CustomerKey = invoice.CustomerKey; payment.PaymentMethodName = PaymentMethod.Name; payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber(); payment.Collected = false; payment.Authorized = true; if (string.IsNullOrEmpty(po.PurchaseOrderNumber)) { return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception("Error Purchase Order Number is empty")), invoice, false)); } invoice.PoNumber = po.PurchaseOrderNumber; MerchelloContext.Current.Services.InvoiceService.Save(invoice); GatewayProviderService.Save(payment); // In this case, we want to do our own Apply Payment operation as the amount has not been collected - // so we create an applied payment with a 0 amount. Once the payment has been "collected", another Applied Payment record will // be created showing the full amount and the invoice status will be set to Paid. GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, string.Format("To show promise of a {0} payment", PaymentMethod.Name), 0); //// If this were using a service we might want to store some of the transaction data in the ExtendedData for record ////payment.ExtendData return(new PaymentResult(Attempt.Succeed(payment), invoice, false)); }
/// <summary> /// Does the actual work of creating and processing the payment /// </summary> /// <param name="invoice">The <see cref="IInvoice"/></param> /// <param name="args">Any arguments required to process the payment.</param> /// <returns>The <see cref="IPaymentResult"/></returns> protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args) { var po = args.AsPurchaseOrderFormData(); var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, invoice.Total, PaymentMethod.Key); payment.CustomerKey = invoice.CustomerKey; payment.PaymentMethodName = PaymentMethod.Name; payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber(); payment.Collected = false; payment.Authorized = true; if (string.IsNullOrEmpty(po.PurchaseOrderNumber)) { return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Error Purchase Order Number is empty")), invoice, false); } invoice.PoNumber = po.PurchaseOrderNumber; MerchelloContext.Current.Services.InvoiceService.Save(invoice); GatewayProviderService.Save(payment); // In this case, we want to do our own Apply Payment operation as the amount has not been collected - // so we create an applied payment with a 0 amount. Once the payment has been "collected", another Applied Payment record will // be created showing the full amount and the invoice status will be set to Paid. GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, string.Format("To show promise of a {0} payment", PaymentMethod.Name), 0); //// If this were using a service we might want to store some of the transaction data in the ExtendedData for record ////payment.ExtendData return new PaymentResult(Attempt.Succeed(payment), invoice, false); }
/// <summary> /// Does the actual work of authorizing and capturing a payment /// </summary> /// <param name="invoice">The <see cref="IInvoice"/></param> /// <param name="amount">The amount to capture</param> /// <param name="args">Any arguments required to process the payment.</param> /// <returns>The <see cref="IPaymentResult"/></returns> protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args) { var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, amount, PaymentMethod.Key); payment.CustomerKey = invoice.CustomerKey; payment.PaymentMethodName = PaymentMethod.Name; payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber(); payment.Collected = true; payment.Authorized = true; var po = args.AsPurchaseOrderFormData(); if (string.IsNullOrEmpty(po.PurchaseOrderNumber)) { return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Error Purchase Order Number is empty")), invoice, false); } invoice.PoNumber = po.PurchaseOrderNumber; MerchelloContext.Current.Services.InvoiceService.Save(invoice); GatewayProviderService.Save(payment); GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Cash payment", amount); return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0); }