/// <summary> /// Authorizes and Captures a Payment /// </summary> /// <param name="invoice">The invoice to be paid</param> /// <param name="amount">The amount of the payment to the invoice</param> /// <param name="args">Additional arguments required by the payment processor</param> /// <returns>A <see cref="IPaymentResult"/></returns> public virtual IPaymentResult AuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args) { Mandate.ParameterNotNull(invoice, "invoice"); var operationData = new AuthorizeOperationData() { Invoice = invoice, Amount = amount, PaymentMethod = this.PaymentMethod, ProcessorArgumentCollection = args }; AuthorizeCapturing.RaiseEvent(new SaveEventArgs <AuthorizeOperationData>(operationData), this); // persist the invoice if (!invoice.HasIdentity) { GatewayProviderService.Save(invoice); } // authorize and capture the payment var response = PerformAuthorizeCapturePayment(invoice, amount, args); // Check configuration for override on ApproveOrderCreation if (!response.ApproveOrderCreation) { ((PaymentResult)response).ApproveOrderCreation = MerchelloConfiguration.Current.AlwaysApproveOrderCreation; } AuthorizeCaptureAttempted.RaiseEvent(new PaymentAttemptEventArgs <IPaymentResult>(response), this); if (!response.Payment.Success) { return(response); } AssertPaymentApplied(response, response.Invoice); AssertInvoiceStatus(response.Invoice); // give response return(response); }
/// <summary> /// Processes a payment for the <see cref="IInvoice"/> /// </summary> /// <param name="invoice">The invoice to be paid</param> /// <param name="args">Additional arguments required by the payment processor</param> /// <returns>A <see cref="IPaymentResult"/></returns> public virtual IPaymentResult AuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args) { Mandate.ParameterNotNull(invoice, "invoice"); var operationData = new AuthorizeOperationData() { Invoice = invoice, PaymentMethod = this.PaymentMethod, ProcessorArgumentCollection = args }; Authorizing.RaiseEvent(new SaveEventArgs<AuthorizeOperationData>(operationData), this); // persist the invoice if (!invoice.HasIdentity) GatewayProviderService.Save(invoice); // collect the payment authorization var response = PerformAuthorizePayment(invoice, args); //((PaymentResult)response).ApproveOrderCreation = this.EnsureApproveOrderCreation(response, invoice); AuthorizeAttempted.RaiseEvent(new PaymentAttemptEventArgs<IPaymentResult>(response), this); if (!response.Payment.Success) return response; AssertPaymentApplied(response, invoice); // Check configuration for override on ApproveOrderCreation if (!response.ApproveOrderCreation) ((PaymentResult)response).ApproveOrderCreation = MerchelloConfiguration.Current.AlwaysApproveOrderCreation; // give response return response; }