Esempio n. 1
0
        /// <summary>
        /// The perform void payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="payment">
        /// The payment.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformVoidPayment(IInvoice invoice, IPayment payment, ProcessorArgumentCollection args)
        {
            string transactionString;

            if (args.TryGetValue(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction, out transactionString))
            {
                var transaction = JsonConvert.DeserializeObject <Transaction>(transactionString);
                var result      = this._braintreeApiService.Transaction.Refund(transaction.Id);

                if (!result.IsSuccess())
                {
                    return(new PaymentResult(Attempt <IPayment> .Fail(payment), invoice, false));
                }

                foreach (var applied in payment.AppliedPayments())
                {
                    applied.TransactionType = AppliedPaymentType.Void;
                    applied.Amount          = 0;
                    applied.Description    += " - **Void**";
                    this.GatewayProviderService.Save(applied);
                }

                payment.Voided = true;
                this.GatewayProviderService.Save(payment);

                return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, false));
            }

            return(new PaymentResult(Attempt <IPayment> .Fail(payment), invoice, false));
        }
Esempio n. 2
0
        /// <summary>
        /// Safely gets a value.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <param name="argumentName">
        /// The argument name.
        /// </param>
        /// <param name="elseValue">
        /// The else value.
        /// </param>
        /// <returns>
        /// Tries to get an argument value with an optional default
        /// </returns>
        /// <remarks>
        /// This was in the original plugin.
        /// </remarks>
        private static string GetArgumentValue(ProcessorArgumentCollection args, string argumentName, string elseValue = null)
        {
            string value;

            if (args != null && args.TryGetValue(argumentName, out value))
            {
                return(value);
            }
            return(elseValue);
        }
Esempio n. 3
0
        /// <summary>
        /// The perform capture payment.
        /// </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)
        {
            payment.Collected  = true;
            payment.Authorized = true;

            string transaction;

            if (args.TryGetValue(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction, out transaction))
            {
                payment.ExtendedData.SetValue(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction, transaction);
            }

            this.GatewayProviderService.Save(payment);

            this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree subscription payment", amount);

            return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, this.CalculateTotalOwed(invoice).CompareTo(amount) <= 0));
        }
Esempio n. 4
0
        /// <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 payment = this.GatewayProviderService.CreatePayment(PaymentMethodType.Cash, amount, this.PaymentMethod.Key);

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

            string transaction;

            if (args.TryGetValue(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction, out transaction))
            {
                payment.ExtendedData.SetValue(Constants.Braintree.ExtendedDataKeys.BraintreeTransaction, transaction);
            }

            this.GatewayProviderService.Save(payment);

            this.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree subscription payment", amount);

            return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, this.CalculateTotalOwed(invoice).CompareTo(amount) <= 0));
        }
        /// <summary>
        /// The perform void payment.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="payment">
        /// The payment.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformVoidPayment(IInvoice invoice, IPayment payment, ProcessorArgumentCollection args)
        {
            string transactionString;
            if (args.TryGetValue(Constants.ExtendedDataKeys.BraintreeTransaction, out transactionString))
            {
                var transaction = JsonConvert.DeserializeObject<Transaction>(transactionString);
                var result = _braintreeApiService.Transaction.Refund(transaction.Id);

                if (!result.IsSuccess()) return new PaymentResult(Attempt<IPayment>.Fail(payment), invoice, false);  

                foreach (var applied in payment.AppliedPayments())
                {
                    applied.TransactionType = AppliedPaymentType.Void;
                    applied.Amount = 0;
                    applied.Description += " - **Void**";
                    GatewayProviderService.Save(applied);
                }

                payment.Voided = true;
                GatewayProviderService.Save(payment);

                return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, false);
            }
            
            return new PaymentResult(Attempt<IPayment>.Fail(payment), invoice, false);
        }
        /// <summary>
        /// The perform capture payment.
        /// </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)
        {
            payment.Collected = true;
            payment.Authorized = true;

            string transaction;
            if (args.TryGetValue(Constants.ExtendedDataKeys.BraintreeTransaction, out transaction))
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.BraintreeTransaction, transaction);
            }

            GatewayProviderService.Save(payment);

            GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree subscription payment", amount);

            return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0);
        }
        /// <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 payment = GatewayProviderService.CreatePayment(PaymentMethodType.Cash, amount, PaymentMethod.Key);
            payment.CustomerKey = invoice.CustomerKey;
            payment.PaymentMethodName = PaymentMethod.Name + " " + PaymentMethod.PaymentCode;
            payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
            payment.Collected = true;
            payment.Authorized = true;

            string transaction;
            if (args.TryGetValue(Constants.ExtendedDataKeys.BraintreeTransaction, out transaction))
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.BraintreeTransaction, transaction);
            }

            GatewayProviderService.Save(payment);

            GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree subscription payment", amount);

            return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0);
        }
 /// <summary>
 /// Safely gets a value.
 /// </summary>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <param name="argumentName">
 /// The argument name.
 /// </param>
 /// <param name="elseValue">
 /// The else value.
 /// </param>
 /// <returns>
 /// Tries to get an argument value with an optional default
 /// </returns>
 /// <remarks>
 /// This was in the original plugin.
 /// </remarks>
 private static string GetArgumentValue(ProcessorArgumentCollection args, string argumentName, string elseValue = null)
 {
     string value;
     if (args != null && args.TryGetValue(argumentName, out value)) return value;
     return elseValue;
 }