コード例 #1
0
        public async override Task <Order> Run(Order arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull($"{this.Name}: order can not be null.");

            var order = arg;

            if (!order.HasComponent <OnHoldOrderComponent>())
            {
                var invalidOrderStateMessage = $"{this.Name}: Expected order in '{context.GetPolicy<KnownOrderStatusPolicy>().OnHold}' status but order was in '{order.Status}' status";
                context.Abort(context.CommerceContext.AddMessage(
                                  context.GetPolicy <KnownResultCodes>().ValidationError,
                                  "InvalidOrderState",
                                  new object[] { context.GetPolicy <KnownOrderStatusPolicy>().OnHold, order.Status },
                                  invalidOrderStateMessage), context);
            }

            var cart = context.CommerceContext.Entities.OfType <Cart>().FirstOrDefault(c => c.Id.Equals(order.GetComponent <OnHoldOrderComponent>().TemporaryCart.EntityTarget, StringComparison.OrdinalIgnoreCase));

            if (cart == null || !cart.HasComponent <FederatedPaymentComponent>())
            {
                return(arg);
            }

            var payment = cart.GetComponent <FederatedPaymentComponent>();

            if (string.IsNullOrEmpty(payment.PaymentMethodNonce))
            {
                context.Abort(context.CommerceContext.AddMessage(
                                  context.GetPolicy <KnownResultCodes>().Error,
                                  "InvalidOrMissingPropertyValue",
                                  new object[] { "PaymentMethodNonce" },
                                  $"Invalid or missing value for property 'PaymentMethodNonce'."), context);

                return(arg);
            }

            if (!string.IsNullOrEmpty(payment.TransactionId))
            {
                // Federated Payment was not changed
                return(arg);
            }

            var braintreeClientPolicy = context.GetPolicy <BraintreeClientPolicy>();

            if (string.IsNullOrEmpty(braintreeClientPolicy?.Environment) || string.IsNullOrEmpty(braintreeClientPolicy?.MerchantId) ||
                string.IsNullOrEmpty(braintreeClientPolicy?.PublicKey) || string.IsNullOrEmpty(braintreeClientPolicy?.PrivateKey))
            {
                context.CommerceContext.AddMessage(
                    context.GetPolicy <KnownResultCodes>().Error,
                    "InvalidClientPolicy",
                    new object[] { "BraintreeClientPolicy" },
                    $"{this.Name}. Invalid BraintreeClientPolicy");
                return(arg);
            }

            try
            {
                var gateway = new BraintreeGateway(braintreeClientPolicy?.Environment, braintreeClientPolicy?.MerchantId, braintreeClientPolicy?.PublicKey, braintreeClientPolicy?.PrivateKey);

                // void order payment
                if (order.HasComponent <FederatedPaymentComponent>())
                {
                    var orderPayment = order.GetComponent <FederatedPaymentComponent>();

                    // void order payment
                    Result <Transaction> voidResult = gateway.Transaction.Void(orderPayment.TransactionId);
                    if (voidResult.IsSuccess())
                    {
                        context.Logger.LogInformation($"{this.Name} - Void Payment succeeded:{ orderPayment.Id }");
                        orderPayment.TransactionStatus = voidResult.Target.Status.ToString();
                        await this.GenerateSalesActivity(order, orderPayment, context);
                    }
                    else
                    {
                        var errorMessages = voidResult.Errors.DeepAll().Aggregate(string.Empty, (current, error) => current + ("Error: " + (int)error.Code + " - " + error.Message + "\n"));

                        context.Abort(context.CommerceContext.AddMessage(
                                          context.GetPolicy <KnownResultCodes>().Error,
                                          "PaymentVoidFailed",
                                          new object[] { orderPayment.TransactionId },
                                          $"{this.Name}. Payment void failed for transaction { orderPayment.TransactionId }: { errorMessages }"), context);

                        return(arg);
                    }
                }

                var request = new TransactionRequest
                {
                    Amount             = payment.Amount.Amount,
                    PaymentMethodNonce = payment.PaymentMethodNonce,
                    BillingAddress     = ComponentsHelper.TranslatePartyToAddressRequest(payment.BillingParty, context),
                    Options            = new TransactionOptionsRequest
                    {
                        SubmitForSettlement = false
                    }
                };

                Result <Transaction> result = gateway.Transaction.Sale(request);

                if (result.IsSuccess())
                {
                    Transaction transaction = result.Target;
                    payment.TransactionId     = transaction?.Id;
                    payment.TransactionStatus = transaction?.Status?.ToString();
                    CreditCard cc = transaction?.CreditCard;
                    payment.MaskedNumber = cc?.MaskedNumber;
                    payment.ExpiresMonth = Int32.Parse(cc?.ExpirationMonth);
                    payment.ExpiresYear  = Int32.Parse(cc?.ExpirationYear);
                    payment.CardType     = cc?.CardType?.ToString();
                }
                else
                {
                    string errorMessages = result.Errors.DeepAll().Aggregate(string.Empty, (current, error) => current + ("Error: " + (int)error.Code + " - " + error.Message + "\n"));

                    context.Abort(context.CommerceContext.AddMessage(
                                      context.GetPolicy <KnownResultCodes>().Error,
                                      "CreatePaymentFailed",
                                      new object[] { "PaymentMethodNonce" },
                                      $"{this.Name}. Create payment failed :{ errorMessages }"), context);
                }

                return(arg);
            }
            catch (BraintreeException ex)
            {
                context.CommerceContext.AddMessage(
                    context.GetPolicy <KnownResultCodes>().Error,
                    "InvalidClientPolicy",
                    new object[] { "BraintreeClientPolicy" },
                    $"{this.Name}. Invalid BraintreeClientPolicy { ex.Message }");
                return(arg);
            }
        }
コード例 #2
0
ファイル: FixedFcdSilHd.cs プロジェクト: linusaurus/Knoodle-4
        //Bill of Material
        public override void Build()
        {
            Component Component;
            string    Componentleader = this.Parent.UnitID + "." + this.CreateID.ToString();

            var Components = ComponentsHelper.TrackMaker(new FrameLS_OX()
            {
                SubAssemblyWidth = 100.0m, SubAssemblyHieght = 90.0m,
                Parent           = this.Parent
            }, 3, 3, TrackConfiguration.Telescoping);

            foreach (Component p in Components)
            {
                p.ComponentGroupType = "Track-Components";
                m_Components.Add(p);
            }

            #region FrameAlum

            //////////////////////////////////////////////////////////////////////////////

            // AlumFxdFcdSilHd
            for (int i = 0; i < 2; i++)
            {
                Component = new Component(4344, "AlumFxdFcdSilHd", this, 1, m_subAssemblyWidth);
                Component.ComponentGroupType = "FrameAlum-Components";
                Component.ComponentWidth     = Component.Source.Width;
                Component.ComponentThick     = Component.Source.Height;
                Component.ComponentLabel     = "";

                m_Components.Add(Component);
            }

            ////////////////////////////////////////////////////////////////////////////////


            #endregion

            #region StopAlum

            //////////////////////////////////////////////////////////////////////////////

            //AlumGlsStpHz
            for (int i = 0; i < 2; i++)
            {
                Component = new Component(4341, "AlumGlsStpHz", this, 1, m_subAssemblyWidth - stopReduceX2);
                Component.ComponentGroupType = "StopAlum-Components";
                Component.ComponentWidth     = Component.Source.Width;
                Component.ComponentThick     = Component.Source.Height;
                Component.ComponentLabel     = "";

                m_Components.Add(Component);
            }

            ////////////////////////////////////////////////////////////////////////////////

            //GlsSpcrBrz
            for (int i = 0; i < 2; i++)
            {
                Component = new Component(4317, "GlsSpcrBrz", this, 1, m_subAssemblyWidth - stopReduceX2);
                Component.ComponentGroupType = "StopAlum-Components";
                Component.ComponentWidth     = Component.Source.Width;
                Component.ComponentThick     = Component.Source.Height;
                Component.ComponentLabel     = "";

                m_Components.Add(Component);
            }

            ////////////////////////////////////////////////////////////////////////////////

            #endregion

            #region Glass


            //Glass Panel

            Component = new Component(3300);

            Component.FunctionalName     = "Glass";
            Component.ComponentGroupType = "Glass-Components";
            Component.Qnty = 1;
            Component.ContainerAssembly = this;
            Component.ComponentWidth    = m_subAssemblyWidth - (glassReduce * 2.0m);
            Component.ComponentLength   = m_subAssemblyHieght - (glassReduce * 2.0m);
            Component.ComponentThick    = 0.5625m;

            m_Components.Add(Component);



            #endregion

            #region GlazingSeal


            for (int i = 0; i < 1; i++)
            {
                //decimal peri = FrameWorks.Functions.Perimeter(m_subAssemblyHieght - gasketReduce, m_subAssemblyWidth - gasketReduce);

                //Glazing Seals
                Component = new Component(4314, "GlazDartEPDM", this, 1, m_subAssemblyWidth * 2.0m);
                Component.ComponentGroupType = "GlazingSeal-Components";
                Component.ComponentLabel     = "";

                m_Components.Add(Component);
            }


            for (int i = 0; i < 1; i++)
            {
                //decimal peri = FrameWorks.Functions.Perimeter(m_subAssemblyHieght - gasketReduce, m_subAssemblyWidth - gasketReduce);

                //Glazing Seals
                Component = new Component(4399, "GlazWedgEPDM", this, 1, m_subAssemblyWidth * 2.0m);
                Component.ComponentGroupType = "GlazingSeal-Components";
                Component.ComponentLabel     = "";

                m_Components.Add(Component);
            }



            #endregion

            #region AssyBrackets

            /////////////////////////////////////////////////////////////////////////

            //AglBrktAlum

            for (int i = 0; i < 8; i++)
            {
                Component = new Component(3206, "AglBrktAlum", this, 1, aluminumCrnBrk);
                Component.ComponentGroupType = "AssyBrackets";
                Component.ComponentWidth     = Component.Source.Width;
                Component.ComponentThick     = Component.Source.Height;
                Component.ComponentLabel     = "Angle_1.5";

                m_Components.Add(Component);
            }

            //PointSetScrew_1/4_20

            for (int i = 0; i < 32; i++)
            {
                Component = new Component(1545, "PointSetScrew_1/4_20", this, 1, 0.0m);
                Component.ComponentGroupType = "AssyBrackets";
                Component.ComponentWidth     = Component.Source.Width;
                Component.ComponentThick     = Component.Source.Height;
                Component.ComponentLabel     = "1/4_20x.25";

                m_Components.Add(Component);
            }

            /////////////////////////////////////////////////////////////////////////

            #endregion
        }
コード例 #3
0
 private async Task PopulateRegistrationStatus(string errorMessage)
 {
     ViewBag.RegistrationStatus = new SelectList(ComponentsHelper.GetRegistrationStatusList(), "Key", "Value");
     ViewBag.ErrorMessage       = errorMessage;
 }
コード例 #4
0
        public override Task <CartEmailArgument> Run(CartEmailArgument arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull($"{this.Name}: The cart can not be null");

            var cart = arg.Cart;

            if (!cart.HasComponent <FederatedPaymentComponent>())
            {
                return(Task.FromResult(arg));
            }

            var payment = cart.GetComponent <FederatedPaymentComponent>();

            if (string.IsNullOrEmpty(payment.PaymentMethodNonce))
            {
                context.Abort(context.CommerceContext.AddMessage(
                                  context.GetPolicy <KnownResultCodes>().Error,
                                  "InvalidOrMissingPropertyValue",
                                  new object[] { "PaymentMethodNonce" },
                                  $"Invalid or missing value for property 'PaymentMethodNonce'."), context);

                return(Task.FromResult(arg));
            }

            var braintreeClientPolicy = context.GetPolicy <BraintreeClientPolicy>();

            if (string.IsNullOrEmpty(braintreeClientPolicy?.Environment) || string.IsNullOrEmpty(braintreeClientPolicy?.MerchantId) ||
                string.IsNullOrEmpty(braintreeClientPolicy?.PublicKey) || string.IsNullOrEmpty(braintreeClientPolicy?.PrivateKey))
            {
                context.CommerceContext.AddMessage(
                    context.GetPolicy <KnownResultCodes>().Error,
                    "InvalidClientPolicy",
                    new object[] { "BraintreeClientPolicy" },
                    $"{this.Name}. Invalid BraintreeClientPolicy");
                return(Task.FromResult(arg));
            }

            try
            {
                var gateway = new BraintreeGateway(braintreeClientPolicy?.Environment, braintreeClientPolicy?.MerchantId, braintreeClientPolicy?.PublicKey, braintreeClientPolicy?.PrivateKey);

                var request = new TransactionRequest
                {
                    Amount             = payment.Amount.Amount,
                    PaymentMethodNonce = payment.PaymentMethodNonce,
                    BillingAddress     = ComponentsHelper.TranslatePartyToAddressRequest(payment.BillingParty, context),
                    Options            = new TransactionOptionsRequest
                    {
                        SubmitForSettlement = false
                    }
                };

                Result <Transaction> result = gateway.Transaction.Sale(request);

                if (result.IsSuccess())
                {
                    Transaction transaction = result.Target;
                    payment.TransactionId     = transaction?.Id;
                    payment.TransactionStatus = transaction?.Status?.ToString();
                    //payment.PaymentInstrumentType = transaction?.PaymentInstrumentType?.ToString();
                    var cc = transaction?.CreditCard;
                    payment.MaskedNumber = cc?.MaskedNumber;
                    payment.CardType     = cc?.CardType?.ToString();
                    if (cc?.ExpirationMonth != null)
                    {
                        payment.ExpiresMonth = int.Parse(cc.ExpirationMonth);
                    }

                    if (cc?.ExpirationYear != null)
                    {
                        payment.ExpiresYear = int.Parse(cc.ExpirationYear);
                    }
                }
                else
                {
                    string errorMessages = result.Errors.DeepAll().Aggregate(string.Empty, (current, error) => current + ("Error: " + (int)error.Code + " - " + error.Message + "\n"));

                    context.Abort(context.CommerceContext.AddMessage(
                                      context.GetPolicy <KnownResultCodes>().Error,
                                      "CreatePaymentFailed",
                                      new object[] { "PaymentMethodNonce" },
                                      $"{this.Name}. Create payment failed :{ errorMessages }"), context);
                }

                return(Task.FromResult(arg));
            }
            catch (BraintreeException ex)
            {
                context.Abort(context.CommerceContext.AddMessage(
                                  context.GetPolicy <KnownResultCodes>().Error,
                                  "CreatePaymentFailed",
                                  new object[] { "PaymentMethodNonce", ex },
                                  $"{this.Name}. Create payment failed."), context);
                return(Task.FromResult(arg));
            }
        }
コード例 #5
0
        public async Task <OrderFormFederatedPayment> CreateFederatedPayment(SerializableCart cart)
        {
            if (cart == null)
            {
                throw new InvalidOrMissingPropertyValueException("The cart can not be null");
            }
            var payment = _livisMarketContext.OrderFormsFederatedPayment.FirstOrDefault(x => x.CartId.HasValue && x.CartId.Value.Equals(cart.CartId));

            if (payment == null)
            {
                throw new InvalidOrMissingPropertyValueException("The payment can not be null");
            }
            if (string.IsNullOrEmpty(payment.PaymentMethodNonce))
            {
                throw new InvalidOrMissingPropertyValueException("Invalid or missing value for property 'PaymentMethodNonce'.");
            }

            try
            {
                var gateway = new BraintreeGateway(_clientPolicy.Environment, _clientPolicy.MerchantId, _clientPolicy.PublicKey, _clientPolicy.PrivateKey);
                var request = new TransactionRequest
                {
                    Amount             = payment.Amount,
                    PaymentMethodNonce = payment.PaymentMethodNonce,
                    BillingAddress     = ComponentsHelper.TranslatePartyToAddressRequest(payment.BillingParty),
                    Options            = new TransactionOptionsRequest
                    {
                        SubmitForSettlement = false
                    }
                };
                Result <Transaction> result = gateway.Transaction.Sale(request);

                if (result.IsSuccess())
                {
                    Transaction transaction = result.Target;
                    payment.TransactionId     = transaction?.Id;
                    payment.TransactionStatus = transaction?.Status?.ToString();
                    //payment.PaymentInstrumentType = transaction?.PaymentInstrumentType?.ToString();
                    var cc = transaction?.CreditCard;
                    payment.MaskedNumber = cc?.MaskedNumber;
                    payment.CardType     = cc?.CardType?.ToString();
                    if (cc?.ExpirationMonth != null)
                    {
                        payment.ExpiresMonth = int.Parse(cc.ExpirationMonth);
                    }

                    if (cc?.ExpirationYear != null)
                    {
                        payment.ExpiresYear = int.Parse(cc.ExpirationYear);
                    }
                    await _livisMarketContext.SaveChangesAsync();

                    return(payment);
                }
                else
                {
                    string errorMessages = result.Errors.DeepAll().Aggregate(string.Empty, (current, error) => current + ("Error: " + (int)error.Code + " - " + error.Message + "\n"));
                    throw new CreatePaymentFailedException(errorMessages);
                }
            }
            catch (BraintreeException ex)
            {
                throw new CreatePaymentFailedException("Create payment failed. " + ex.Message, ex);
            }
        }
コード例 #6
0
 private void PopulateCountryCodes(string errorMessage)
 {
     ViewBag.CountryList  = new SelectList(ComponentsHelper.GetCountryList(), "Key", "Value");
     ViewBag.ErrorMessage = errorMessage;
 }