예제 #1
0
        public void Add_PassingNullObj_ReturnsException()
        {
            // Arrange
            Api.Models.Order order = null;

            // Act
            Action act = () => { _service.Add(order); };

            // Assert
            Assert.Throws <ArgumentNullException>(act);
        }
        public void Add_PassingNullObj_ReturnsBadRequestWithException()
        {
            //Arrange
            Api.Models.Order input = null;

            // Act
            var result     = _controller.Add(input);
            var badRequest = result as BadRequestObjectResult;

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
            Assert.IsType <ArgumentNullException>(badRequest.Value);
        }
예제 #3
0
        public void Add_WhenCalled_ReturnsObjWithId()
        {
            // Arrange
            var order = new Api.Models.Order()
            {
                Id = 0, Price = 11.11M, CreatedDate = DateTime.Now
            };

            // Act
            var obj = _service.Add(order);

            // Assert
            Assert.IsType <Api.Models.Order>(obj);
            Assert.True(obj.Id > 0);
        }
        public void Add_WhenCalled_ReturnsObjWithId()
        {
            //Arrange
            var input = new Api.Models.Order()
            {
                Price = 11.11M, CreatedDate = DateTime.Now
            };

            // Act
            var result   = _controller.Add(input);
            var okResult = (OkObjectResult)result;

            // Assert
            Assert.IsType <OkObjectResult>(result);
            Assert.IsType <Api.Models.Order>(okResult.Value);
            Assert.True(((Api.Models.Order)okResult.Value).Id > 0);
        }
예제 #5
0
        public override PaymentHtmlForm GenerateHtmlForm(Api.Models.Order order, string teaCommerceContinueUrl, string teaCommerceCancelUrl, string teaCommerceCallBackUrl, string teaCommerceCommunicationUrl, IDictionary <string, string> settings)
        {
            try
            {
                settings.MustNotBeNull("settings");
                settings.MustContainKey("PartnerId", "settings");
                settings.MustContainKey("ProfileKey", "settings");
                settings.MustContainKey("SecretKey", "settings");
                settings.MustContainKey("ReturnUrl", "settings");
                settings.MustContainKey("mollieiDealBanksPropertyAlias", "settings");
                settings.MustContainKey("OrderDescriptionField", "settings");

                string bankId = order.Properties[settings["mollieiDealBanksPropertyAlias"]];
                string amount = order.TotalPrice.Value.WithVatFormattedWithoutSymbol.Replace(".", "");

                //var hash = GenerateHMACMD5Hash(settings["SecretKey"], string.Format("{0}{1}{2}", settings["PartnerId"], settings["ProfileKey"], order.CartNumber));
                var hash = new HMACSHA256(Encoding.UTF8.GetBytes(settings["SecretKey"])).ComputeHash(Encoding.UTF8.GetBytes(string.Format("{0}{1}{2}", settings["PartnerId"], settings["ProfileKey"], order.CartNumber))).ToBase64();

                var    qs                    = (settings["ReportUrl"].Contains('?')) ? "&" : "?";
                string reporturl             = string.Format("{0}{1}cartNumber={2}&hash={3}", settings["ReportUrl"], qs, order.CartNumber, hash);
                string orderDescriptionField = settings["OrderDescriptionField"];
                string description           = string.Format("{0} {1}", orderDescriptionField, order.CartNumber);
                qs = (settings["ReturnUrl"].Contains('?')) ? "&" : "?";
                string returnurl   = string.Format("{0}{1}orderId={2}", settings["ReturnUrl"], qs, order.Id);
                string profile_key = settings["ProfileKey"];
                string partner_id  = settings["PartnerId"];

                Dictionary <string, string> transactionSettings = getTransactionURL(settings, order);
                Dictionary <string, string> inputFields         = new Dictionary <string, string>();
                inputFields.Add("paymentUrl", transactionSettings["transactionUrl"]);
                // The next line is here because Mollie does not accept POST requests, only GET requests
                PaymentHtmlForm htmlForm = new PaymentHtmlForm
                {
                    Action      = "/pages/redirecttopayment.aspx",
                    InputFields = inputFields
                };
                return(htmlForm);
            }
            catch (Exception ex)
            {
                LoggingService.Instance.Error <MollieiDeal>("GenerateHtmlForm exception", ex);
                throw ex;
            }
        }
예제 #6
0
        /// <summary>
        /// Processes the callback.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="request">The request.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public override CallbackInfo ProcessCallback(Api.Models.Order order, System.Web.HttpRequest request, IDictionary <string, string> settings)
        {
            CallbackInfo callbackInfo = null;

            try
            {
                order.MustNotBeNull("order");
                request.MustNotBeNull("request");
                settings.MustNotBeNull("settings");
                settings.MustContainKey("PartnerId", "settings");
                settings.MustContainKey("RoundingMode", "settings");

                // Call the validation URL to check this order
                IdealCheck idealCheck = new IdealCheck(settings["PartnerId"], settings["TestMode"] == "1", request["transaction_id"]);

                decimal orderAmount = order.TotalPrice.Value.WithVat;
                if (idealCheck.Payed)
                {
                    decimal mollieAmount = idealCheck.Amount;

                    // Check if amount that mollie received is equal to the orders amount
                    if (Math.Round(mollieAmount, 0) == Math.Round(orderAmount, Convert.ToInt32(settings["RoundingMode"])))
                    {
                        callbackInfo = new CallbackInfo(orderAmount, request["transaction_id"], PaymentState.Captured);
                        LoggingService.Instance.Info <MollieiDeal>(string.Format("Mollie: Saved and finalized orderId {0}", order.Id));
                    }
                    else
                    {
                        callbackInfo = new CallbackInfo(orderAmount, request["transaction_id"], PaymentState.Error);
                        LoggingService.Instance.Info <MollieiDeal>(string.Format("Mollie: Controle: MollieAmount:{0} OrderAmount: {1} do not match!", mollieAmount, orderAmount));
                    }
                }
                else
                {
                    LoggingService.Instance.Info <MollieiDeal>(string.Format("Mollie: Controle: iDeal status not payed, for cartId {0}!", order.Id));
                }
            }
            catch (Exception exp)
            {
                LoggingService.Instance.Error <MollieiDeal>("ProcessCallback exception", exp);
            }

            return(callbackInfo);
        }
예제 #7
0
        /// <summary>
        /// Gets the transaction URL.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="order">The order.</param>
        /// <returns></returns>
        public Dictionary <string, string> getTransactionURL(IDictionary <string, string> settings, Api.Models.Order order)
        {
            Dictionary <string, string> resultList = new Dictionary <string, string>();

            settings.MustContainKey("mollieiDealBanksPropertyAlias", "settings");
            settings.MustContainKey("OrderDescriptionField", "settings");
            string  bankId = order.Properties[settings["mollieiDealBanksPropertyAlias"]];
            decimal amount = order.TotalPrice.Value.WithVat;

            //var hash = GenerateHMACMD5Hash(settings["SecretKey"], string.Format("{0}{1}{2}", settings["PartnerId"], settings["ProfileKey"], order.CartNumber));
            var hash = new HMACSHA256(Encoding.UTF8.GetBytes(settings["SecretKey"])).ComputeHash(Encoding.UTF8.GetBytes(string.Format("{0}{1}{2}", settings["PartnerId"], settings["ProfileKey"], order.CartNumber))).ToBase64();

            var    qs                    = (settings["ReportUrl"].Contains('?')) ? "&" : "?";
            string reporturl             = string.Format("{0}{1}cartNumber={2}&hash={3}", settings["ReportUrl"], qs, order.CartNumber, hash);
            string orderDescriptionField = settings["OrderDescriptionField"];
            string description           = string.Format("{0} {1}", orderDescriptionField, order.CartNumber);

            qs = (settings["ReturnUrl"].Contains('?')) ? "&" : "?";
            string returnurl   = string.Format("{0}{1}orderId={2}", settings["ReturnUrl"], qs, order.Id);
            string profile_key = settings["ProfileKey"];
            string partner_id  = settings["PartnerId"];
            string mollieUrl   = settings["MollieUrl"];

            bool testmode = false;

            if (settings["TestMode"] == "1")
            {
                testmode = true;
            }

            IdealFetch idealFetch = new IdealFetch
                                    (
                partner_id     //replace this by your Mollie partnerid
                , testmode     //testmode
                , description
                , reporturl
                , returnurl
                , bankId
                , amount
                                    );

            resultList.Add("transactionId", idealFetch.TransactionId);
            resultList.Add("transactionUrl", idealFetch.Url);

            return(resultList);
        }