/// <summary>
        /// The perform authorize payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
        {
            var authorizeAmount = invoice.Total;

            if (args.ContainsKey("authorizePaymentAmount"))
            {
                authorizeAmount = Convert.ToDecimal(args["authorizePaymentAmount"]);
            }

            var merchantAccountId = string.Empty;

            if (args.ContainsKey("merchantAccountId"))
            {
                merchantAccountId = args["merchantAccountId"];
            }

            // The Provider settings
            if (this.BraintreeApiService.BraintreeProviderSettings.DefaultTransactionOption == TransactionOption.SubmitForSettlement)
            {
                return(this.PerformAuthorizeCapturePayment(invoice, authorizeAmount, args));
            }

            var paymentMethodToken = args.GetPaymentMethodToken();

            if (string.IsNullOrEmpty(paymentMethodToken))
            {
                var error = new InvalidOperationException("No payment method token was found in the ProcessorArgumentCollection");
                LogHelper.Debug <BraintreeStandardTransactionPaymentGatewayMethod>(error.Message);
                return(new PaymentResult(Attempt <IPayment> .Fail(error), invoice, false));
            }

            var attempt = this.ProcessPayment(invoice, TransactionOption.Authorize, authorizeAmount, paymentMethodToken, "", merchantAccountId);

            var payment = attempt.Payment.Result;

            this.GatewayProviderService.Save(payment);

            if (!attempt.Payment.Success)
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, attempt.Payment.Exception.Message, 0);
            }
            else
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, this.PaymentLineAuthorizeDescription, 0);
            }

            return(attempt);
        }
Esempio n. 2
0
        /// <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. (Maybe a username, password or some API Key)</param>
        /// <returns>The <see cref="IPaymentResult"/></returns>
        protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
        {
            var authorizeAmount = invoice.Total;

            if (args.ContainsKey("authorizePaymentAmount"))
            {
                authorizeAmount = Convert.ToDecimal(args["authorizePaymentAmount"]);
            }

            var payment = GatewayProviderService.CreatePayment(PaymentMethodType.Cash, authorizeAmount, PaymentMethod.Key);

            payment.CustomerKey       = invoice.CustomerKey;
            payment.PaymentMethodName = PaymentMethod.Name;
            payment.ReferenceNumber   = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
            payment.Collected         = false;
            payment.Authorized        = true;

            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));
        }
Esempio n. 3
0
        /// <summary>
        /// Performs the actual work of authorizing and capturing a payment.  
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="amount">
        /// The amount.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        /// <remarks>
        /// This is a transaction with SubmitForSettlement = true
        /// </remarks>
        protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args)
        {
            var paymentMethodNonce = args.GetPaymentMethodNonce();

            if (string.IsNullOrEmpty(paymentMethodNonce))
            {
                var error = new InvalidOperationException("No payment method nonce was found in the ProcessorArgumentCollection");
                LogHelper.Debug<BraintreeStandardTransactionPaymentGatewayMethod>(error.Message);
                return new PaymentResult(Attempt<IPayment>.Fail(error), invoice, false);
            }

            // TODO this is a total last minute hack
            var email = string.Empty;
            if (args.ContainsKey("customerEmail")) email = args["customerEmail"];

            var attempt = this.ProcessPayment(invoice, TransactionOption.SubmitForSettlement, invoice.Total, paymentMethodNonce, email);

            var payment = attempt.Payment.Result;

            this.GatewayProviderService.Save(payment);

            if (!attempt.Payment.Success)
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, attempt.Payment.Exception.Message, 0);
            }
            else
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree PayPal one time transaction - authorized and captured", amount);
            }

            return attempt;
        }
Esempio n. 4
0
        /// <summary>
        /// The set purchase order number.
        /// </summary>
        /// <param name="args">
        /// The <see cref="ProcessorArgumentCollection"/>
        /// </param>
        /// <param name="purchaseOrderNumber">
        /// The Purchase Order Number.
        /// </param>
        public static void SetPurchaseOrderNumber(this ProcessorArgumentCollection args, string purchaseOrderNumber)
        {
            if (args.ContainsKey(PurchaseOrderKey))
            {
                args[PurchaseOrderKey] = purchaseOrderNumber;
                return;
            }

            args.Add(PurchaseOrderKey, purchaseOrderNumber);
        }
Esempio n. 5
0
        /// <summary>
        /// Performs the actual work of authorizing and capturing a payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="amount">
        /// The amount.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        /// <remarks>
        /// This is a transaction with SubmitForSettlement = true
        /// </remarks>
        protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args)
        {
            var paymentMethodNonce = args.GetPaymentMethodNonce();

            if (string.IsNullOrEmpty(paymentMethodNonce))
            {
                var error = new InvalidOperationException("No payment method nonce was found in the ProcessorArgumentCollection");
                LogHelper.Debug <BraintreeStandardTransactionPaymentGatewayMethod>(error.Message);
                return(new PaymentResult(Attempt <IPayment> .Fail(error), invoice, false));
            }

            // TODO this is a total last minute hack
            var email = string.Empty;

            if (args.ContainsKey("customerEmail"))
            {
                email = args["customerEmail"];
            }

            var merchantAccountId = string.Empty;

            if (args.ContainsKey("merchantAccountId"))
            {
                merchantAccountId = args["merchantAccountId"];
            }

            var attempt = this.ProcessPayment(invoice, TransactionOption.SubmitForSettlement, amount, paymentMethodNonce, email, merchantAccountId);

            var payment = attempt.Payment.Result;

            this.GatewayProviderService.Save(payment);

            if (!attempt.Payment.Success)
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, attempt.Payment.Exception.Message, 0);
            }
            else
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree PayPal one time transaction - authorized and captured", amount);
            }

            return(attempt);
        }
Esempio n. 6
0
        /// <summary>
        /// Does the actual work of authorizing the payment
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
        {
            var authorizeAmount = invoice.Total;

            if (args.ContainsKey("authorizePaymentAmount"))
            {
                authorizeAmount = Convert.ToDecimal(args["authorizePaymentAmount"]);
            }

            var merchantAccountId = string.Empty;

            if (args.ContainsKey("merchantAccountId"))
            {
                merchantAccountId = args["merchantAccountId"];
            }

            var paymentMethodNonce = args.GetPaymentMethodNonce();

            if (string.IsNullOrEmpty(paymentMethodNonce))
            {
                var error = new InvalidOperationException("No payment method nonce was found in the ProcessorArgumentCollection");
                LogHelper.Debug <BraintreeStandardTransactionPaymentGatewayMethod>(error.Message);
                return(new PaymentResult(Attempt <IPayment> .Fail(error), invoice, false));
            }

            var attempt = this.ProcessPayment(invoice, TransactionOption.Authorize, authorizeAmount, paymentMethodNonce, "", merchantAccountId);

            var payment = attempt.Payment.Result;

            this.GatewayProviderService.Save(payment);

            if (!attempt.Payment.Success)
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, attempt.Payment.Exception.Message, 0);
            }
            else
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "To show record of Braintree Authorization", 0);
            }

            return(attempt);
        }
        /// <summary>
        /// Get Stripe customer name
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static string GetCustomerName(this ProcessorArgumentCollection args)
        {
            if (args.ContainsKey(Constants.Stripe.ProcessorArguments.CustomerName))
            {
                return(args[Constants.Stripe.ProcessorArguments.CustomerName]);
            }

            LogHelper.Debug(typeof(MappingExtensions), "Payment Method Customer Name not found in process argument collection");

            return(string.Empty);
        }
Esempio n. 8
0
        /// <summary>
        /// The get payment method token.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GetPaymentMethodToken(this ProcessorArgumentCollection args)
        {
            if (args.ContainsKey(Constants.Braintree.ProcessorArguments.PaymentMethodToken))
            {
                return(args[Constants.Braintree.ProcessorArguments.PaymentMethodToken]);
            }

            LogHelper.Debug(typeof(MappingExtensions), "Payment Method Token not found in process argument collection");

            return(string.Empty);
        }
        /// <summary>
        /// Performs the AuthorizePayment operation.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="args">
        /// The <see cref="ProcessorArgumentCollection"/>.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        /// <remarks>
        /// For the ExpressCheckout there is not technically an "Authorize" but we use this to start the checkout process and to
        /// mark intent to pay before redirecting the customer to PayPal.  e.g.  This method is called after the customer has
        /// clicked the Pay button, we then save the invoice and "Authorize" a payment setting the invoice status to Unpaid before redirecting.
        /// IN this way, we have both an Invoice and a Payment (denoting the redirect).  When the customer completes the purchase on PayPal sites
        /// the payment will be used to perform a capture and the invoice status will be changed to Paid.  In the event the customer cancels,
        /// the invoice will either be voided or deleted depending on the configured setting.
        /// Events are included in the controller handling the response to allow developers to override success and cancel redirect URLs.
        /// </remarks>
        protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
        {
            var authorizeAmount = invoice.Total;

            if (args.ContainsKey("authorizePaymentAmount"))
            {
                authorizeAmount = Convert.ToDecimal(args["authorizePaymentAmount"]);
            }

            var payment = GatewayProviderService.CreatePayment(PaymentMethodType.Redirect, authorizeAmount, PaymentMethod.Key);

            payment.CustomerKey       = invoice.CustomerKey;
            payment.PaymentMethodName = PaymentMethod.Name;
            payment.ReferenceNumber   = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
            payment.Collected         = false;
            payment.Authorized        = false; // this is technically not the authorization.  We'll mark this in a later step.

            // Have to save here to generate the payment key
            GatewayProviderService.Save(payment);

            // Now we want to get things setup for the ExpressCheckout
            var record = this._paypalApiService.ExpressCheckout.SetExpressCheckout(invoice, payment);

            payment.SavePayPalTransactionRecord(record);

            // Have to save here to persist the record so it can be used in later processing.
            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 via PayPal Express Checkout", PaymentMethod.Name), 0);


            // if the ACK was success return a success IPaymentResult
            if (record.Success)
            {
                return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, false, record.SetExpressCheckout.RedirectUrl));
            }

            // In the case of a failure, package up the exception so we can bubble it up.
            var ex = new PayPalApiException("PayPal Checkout Express initial response ACK was not Success");

            if (record.SetExpressCheckout.ErrorTypes.Any())
            {
                ex.ErrorTypes = record.SetExpressCheckout.ErrorTypes;
            }

            return(new PaymentResult(Attempt <IPayment> .Fail(payment, ex), invoice, false));
        }
        /// <summary>
        /// The perform authorize capture payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="amount">
        /// The amount.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args)
        {
            var paymentMethodToken = args.GetPaymentMethodToken();

            if (string.IsNullOrEmpty(paymentMethodToken))
            {
                var error = new InvalidOperationException("No payment method token was found in the ProcessorArgumentCollection");
                LogHelper.Debug <BraintreeStandardTransactionPaymentGatewayMethod>(error.Message);
                return(new PaymentResult(Attempt <IPayment> .Fail(error), invoice, false));
            }

            var merchantAccountId = string.Empty;

            if (args.ContainsKey("merchantAccountId"))
            {
                merchantAccountId = args["merchantAccountId"];
            }

            var attempt = this.ProcessPayment(invoice, TransactionOption.SubmitForSettlement, amount, paymentMethodToken, "", merchantAccountId);

            var payment = attempt.Payment.Result;

            this.GatewayProviderService.Save(payment);

            if (!attempt.Payment.Success)
            {
                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, attempt.Payment.Exception.Message, 0);
            }
            else
            {
                var customerKey = invoice.CustomerKey.GetValueOrDefault();
                var last4       = string.Empty;
                if (!Guid.Empty.Equals(customerKey))
                {
                    var customer = this.BraintreeApiService.Customer.GetBraintreeCustomer(customerKey);
                    if (customer.CreditCards.Any())
                    {
                        var cc = customer.CreditCards.FirstOrDefault(x => x.Token == paymentMethodToken);
                        if (cc != null)
                        {
                            last4 += " - " + cc.CardType + " " + cc.LastFour;
                        }
                    }
                }

                this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, this.PaymentLineAuthorizeCaptureDescription + " " + last4, payment.Amount);
            }

            return(attempt);
        }
Esempio n. 11
0
 private static string ArgValue(this ProcessorArgumentCollection args, string key)
 {
     return(args.ContainsKey(key) ? args[key] : string.Empty);
 }