Beispiel #1
0
        /// <summary>
        /// Captures a payment for the <see cref="IInvoice"/>
        /// </summary>
        /// <param name="invoice">The invoice to be paid</param>
        /// <param name="payment">The payment to capture</param>
        /// <param name="amount">The amount of the payment to be captured</param>
        /// <param name="args">Additional arguments required by the payment processor</param>
        /// <returns>A <see cref="IPaymentResult"/></returns>
        public virtual IPaymentResult CapturePayment(IInvoice invoice, IPayment payment, decimal amount, ProcessorArgumentCollection args)
        {
            Mandate.ParameterNotNull(invoice, "invoice");

            var operationData = new PaymentOperationData()
            {
                Invoice       = invoice,
                Payment       = payment,
                Amount        = amount,
                PaymentMethod = this.PaymentMethod,
                ProcessorArgumentCollection = args
            };

            Capturing.RaiseEvent(new SaveEventArgs <PaymentOperationData>(operationData), this);

            // persist the invoice
            if (!invoice.HasIdentity)
            {
                GatewayProviderService.Save(invoice);
            }

            var response = PerformCapturePayment(invoice, payment, amount, args);

            //((PaymentResult)response).ApproveOrderCreation = this.EnsureApproveOrderCreation(response, invoice);

            // Special case where the order has already been created due to configuration override.
            if (invoice.Orders.Any() && response.ApproveOrderCreation)
            {
                ((PaymentResult)response).ApproveOrderCreation = false;
            }

            CaptureAttempted.RaiseEvent(new PaymentAttemptEventArgs <IPaymentResult>(response), this);

            if (!response.Payment.Success)
            {
                return(response);
            }

            AssertPaymentApplied(response, response.Invoice);

            AssertInvoiceStatus(response.Invoice);


            // give response
            return(response);
        }
Beispiel #2
0
        /// <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 PaymentOperationData()
            {
                Invoice = invoice,
                Amount  = amount,
                ProcessorArgumentCollection = args
            };

            Capturing.RaiseEvent(new SaveEventArgs <PaymentOperationData>(operationData), this);

            // persist the invoice
            if (!invoice.HasIdentity)
            {
                GatewayProviderService.Save(invoice);
            }

            // authorize and capture the payment
            var response = PerformAuthorizeCapturePayment(invoice, amount, args);

            //((PaymentResult)response).ApproveOrderCreation = this.EnsureApproveOrderCreation(response, invoice);

            AuthorizeCaptureAttempted.RaiseEvent(new PaymentAttemptEventArgs <IPaymentResult>(response), this);

            if (!response.Payment.Success)
            {
                return(response);
            }

            AssertPaymentApplied(response, invoice);

            AssertInvoiceStatus(invoice);

            // Check configuration for override on ApproveOrderCreation
            if (!response.ApproveOrderCreation)
            {
                ((PaymentResult)response).ApproveOrderCreation = MerchelloConfiguration.Current.AlwaysApproveOrderCreation;
            }

            // give response
            return(response);
        }