public void HashIsComputedCorrectly1()
        {
            var request = new TransactionRequest();
            request.Add("ORDERID", "VALUE1");
            request.Add("DATE", "VALUE2");
            var client = GetClient();
            client.SetHash(request);

            Assert.AreEqual("b7c312f5d79aebc472d91b7395ba855b00bcfee5e15b13a01af85a9f64737a89", request["HASH"]);
        }
        public void HashIsComputedCorrectly0_EvenWithExistingHash()
        {
            var request = new TransactionRequest();
            request.Add("KEY1", "VALUE1");
            request.Add("HASH", "HASH");
            var client = GetClient();
            client.SetHash(request);

            Assert.AreEqual("05b2372310c2897729f9c185517a25168e6891f2c7749329255f494e1483f181", request["HASH"]);
        }
        public void HashIsComputedCorrectly0_DoesNotHashNonUpperKeys()
        {
            var request = new TransactionRequest();
            request.Add("KEY1", "VALUE1");
            request.Add("yop", "VALUE2");
            var client = GetClient();
            client.SetHash(request);

            Assert.AreEqual("05b2372310c2897729f9c185517a25168e6891f2c7749329255f494e1483f181", request["HASH"]);
        }
        public void HashIsComputedCorrectly1_Verify()
        {
            var hash    = "b7c312f5d79aebc472d91b7395ba855b00bcfee5e15b13a01af85a9f64737a89";
            var request = new TransactionRequest();

            request.Add("ORDERID", "VALUE1");
            request.Add("DATE", "VALUE2");
            var client = GetClient();
            var result = client.VerifyParameters(request, GetClientConfiguration().ApiKey, hash);

            Assert.IsTrue(result);
        }
        public void HashIsComputedCorrectly0_DoesNotHashNonUpperKeys()
        {
            var request = new TransactionRequest();

            request.Add("KEY1", "VALUE1");
            request.Add("yop", "VALUE2");
            var client = GetClient();

            client.SetHash(request);

            Assert.AreEqual("05b2372310c2897729f9c185517a25168e6891f2c7749329255f494e1483f181", request["HASH"]);
        }
        public void HashIsComputedCorrectly1()
        {
            var request = new TransactionRequest();

            request.Add("ORDERID", "VALUE1");
            request.Add("DATE", "VALUE2");
            var client = GetClient();

            client.SetHash(request);

            Assert.AreEqual("b7c312f5d79aebc472d91b7395ba855b00bcfee5e15b13a01af85a9f64737a89", request["HASH"]);
        }
        public void HashIsComputedCorrectly0_EvenWithExistingHash()
        {
            var request = new TransactionRequest();

            request.Add("KEY1", "VALUE1");
            request.Add("HASH", "HASH");
            var client = GetClient();

            client.SetHash(request);

            Assert.AreEqual("05b2372310c2897729f9c185517a25168e6891f2c7749329255f494e1483f181", request["HASH"]);
        }
Beispiel #8
0
        /// <summary>
        /// Sets the pay with form. Call CreateAuthorizationParameters first.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="allow3dSecure">if set to <c>true</c> [allow3d secure].</param>
        /// <param name="hideClientEmail">if set to <c>true</c> [hide client email].</param>
        /// <exception cref="System.ArgumentNullException">collection</exception>
        public void SetPayWithForm(
            TransactionRequest collection,
            bool allow3dSecure   = true,
            bool hideClientEmail = false)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            collection.Add(Names.Params.Use3DSecure, allow3dSecure ? Names.Params.Yes : Names.Params.No);
            collection.Add(Names.Params.HideClientEmail, hideClientEmail ? Names.Params.Yes : Names.Params.No);
        }
        /// <summary>
        /// Creates the authorization/payment parameters. You have to call SetPayWithForm or SetPayWithAlias after.
        /// </summary>
        /// <param name="uniqueOrderId">The unique order unique identifier (you have to create it).</param>
        /// <param name="userId">The user unique identifier.</param>
        /// <param name="userEmail">The user email.</param>
        /// <param name="description">The description of the payment.</param>
        /// <param name="amountInEuro">The amount information euro (not in cents).</param>
        /// <param name="createAlias">if set to <c>true</c> [create alias] (to do oneclick later).</param>
        /// <param name="displayCreateAlias">if set to <c>true</c> the payment form will ask whether to save the card information.</param>
        /// <param name="authorizationInsteadOfPayment">if set to <c>true</c> [authorization instead of payment]. Call Capture to complete the transaction.</param>
        /// <param name="language">The language.</param>
        /// <returns></returns>
        public TransactionRequest CreateAuthorizationParameters(
            string uniqueOrderId,
            string userId,
            string userEmail,
            string description,
            decimal amountInEuro,
            bool createAlias = false,
            bool displayCreateAlias = false,
            bool authorizationInsteadOfPayment = false,
            Be2BillLanguage language = Be2BillLanguage.EN)
        {
            // http://developer.be2bill.com/platform

            var collection = new TransactionRequest();

            if (authorizationInsteadOfPayment)
            {
                collection.Add(Names.Params.OperationType, Names.Params.OperationTypeAuthorization);
            }
            else
            {
                collection.Add(Names.Params.OperationType, Names.Params.OperationTypePayment);
            }

            collection.Add(Names.Params.Description, description);
            collection.Add(Names.Params.OrderId, uniqueOrderId); // be2bill seems to accept only 1 tentative per ORDERID
            collection.Add(Names.Params.Amount, Math.Round(amountInEuro * 100).ToString());
            collection.Add(Names.Params.Version, Names.ApiVersion);
            collection.Add(Names.Params.ClientIdent, userId);
            collection.Add(Names.Params.Language, language.ToString());

            if (createAlias)
            {
                collection.Add(Names.Params.CreateAlias, Names.Params.Yes); // allow one-click for later transactions (force)
            }

            if (displayCreateAlias)
            {
                collection.Add(Names.Params.DisplayCreateAlias, Names.Params.Yes); // allow one-click for later transactions (ask user)
            }

            collection.Add(Names.Params.Identifier, configuration.ApiIdentifier);

            if (userEmail != null)
            {
                collection.Add(Names.Params.ClientEmail, userEmail);
            }

            return collection;
        }
        public void HashIsComputedCorrectly0_Verify()
        {
            var hash = "05b2372310c2897729f9c185517a25168e6891f2c7749329255f494e1483f181";
            var request = new TransactionRequest();
            request.Add("KEY1", "VALUE1");
            var client = GetClient();
            var result = client.VerifyParameters(request, GetClientConfiguration().ApiKey, hash);

            Assert.IsTrue(result);
        }
        public void HashIsComputedCorrectly0_Verify()
        {
            var hash    = "05b2372310c2897729f9c185517a25168e6891f2c7749329255f494e1483f181";
            var request = new TransactionRequest();

            request.Add("KEY1", "VALUE1");
            var client = GetClient();
            var result = client.VerifyParameters(request, GetClientConfiguration().ApiKey, hash);

            Assert.IsTrue(result);
        }
Beispiel #12
0
        /// <summary>
        /// Sets the pay with alias. Call CreateAuthorizationParameters first.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="alias">The alias.</param>
        /// <param name="userAddress">The user address.</param>
        /// <param name="userAgent">The user agent.</param>
        /// <exception cref="System.ArgumentNullException">collection</exception>
        /// <exception cref="System.ArgumentException">
        /// The value cannot be empty;alias
        /// or
        /// The value cannot be empty;userAddress
        /// or
        /// The value cannot be empty;userAgent
        /// </exception>
        public void SetPayWithAlias(TransactionRequest collection, string alias, string userAddress, string userAgent)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            if (string.IsNullOrEmpty(alias))
            {
                throw new ArgumentException("The value cannot be empty", "alias");
            }
            if (string.IsNullOrEmpty(userAddress))
            {
                throw new ArgumentException("The value cannot be empty", "userAddress");
            }
            if (string.IsNullOrEmpty(userAgent))
            {
                throw new ArgumentException("The value cannot be empty", "userAgent");
            }

            collection.Add(Names.Params.Alias, alias);
            collection.Add(Names.Params.AliasMode, Names.Params.AliasModeOneClick);
            collection.Add(Names.Params.ClientIP, userAddress);
            collection.Add(Names.Params.ClientUserAgent, userAgent);

            // some keys are not allowed when paying with alias
            string[] removeKeys = new string[]
            {
                Names.Params.Language,
                Names.Params.Use3DSecure,
                Names.Params.HideClientEmail,
            };
            foreach (var key in removeKeys)
            {
                if (collection.ContainsKey(key))
                {
                    collection.Remove(key);
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Creates the authorization/payment parameters. You have to call SetPayWithForm or SetPayWithAlias after.
        /// </summary>
        /// <param name="uniqueOrderId">The unique order unique identifier (you have to create it).</param>
        /// <param name="userId">The user unique identifier.</param>
        /// <param name="userEmail">The user email.</param>
        /// <param name="description">The description of the payment.</param>
        /// <param name="amountInEuro">The amount information euro (not in cents).</param>
        /// <param name="createAlias">if set to <c>true</c> [create alias] (to do oneclick later).</param>
        /// <param name="displayCreateAlias">if set to <c>true</c> the payment form will ask whether to save the card information.</param>
        /// <param name="authorizationInsteadOfPayment">if set to <c>true</c> [authorization instead of payment]. Call Capture to complete the transaction.</param>
        /// <param name="language">The language.</param>
        /// <returns></returns>
        public TransactionRequest CreateAuthorizationParameters(
            string uniqueOrderId,
            string userId,
            string userEmail,
            string description,
            decimal amountInEuro,
            bool createAlias                   = false,
            bool displayCreateAlias            = false,
            bool authorizationInsteadOfPayment = false,
            Be2BillLanguage language           = Be2BillLanguage.EN)
        {
            // http://developer.be2bill.com/platform

            var collection = new TransactionRequest();

            if (authorizationInsteadOfPayment)
            {
                collection.Add(Names.Params.OperationType, Names.Params.OperationTypeAuthorization);
            }
            else
            {
                collection.Add(Names.Params.OperationType, Names.Params.OperationTypePayment);
            }

            collection.Add(Names.Params.Description, description);
            collection.Add(Names.Params.OrderId, uniqueOrderId); // be2bill seems to accept only 1 tentative per ORDERID
            collection.Add(Names.Params.Amount, Math.Round(amountInEuro * 100).ToString());
            collection.Add(Names.Params.Version, Names.ApiVersion);
            collection.Add(Names.Params.ClientIdent, userId);
            collection.Add(Names.Params.Language, language.ToString());

            if (createAlias)
            {
                collection.Add(Names.Params.CreateAlias, Names.Params.Yes); // allow one-click for later transactions (force)
            }

            if (displayCreateAlias)
            {
                collection.Add(Names.Params.DisplayCreateAlias, Names.Params.Yes); // allow one-click for later transactions (ask user)
            }

            collection.Add(Names.Params.Identifier, configuration.ApiIdentifier);

            if (userEmail != null)
            {
                collection.Add(Names.Params.ClientEmail, userEmail);
            }

            return(collection);
        }
        public void HashIsComputedCorrectly1_Verify()
        {
            var hash = "b7c312f5d79aebc472d91b7395ba855b00bcfee5e15b13a01af85a9f64737a89";
            var request = new TransactionRequest();
            request.Add("ORDERID", "VALUE1");
            request.Add("DATE", "VALUE2");
            var client = GetClient();
            var result = client.VerifyParameters(request, GetClientConfiguration().ApiKey, hash);

            Assert.IsTrue(result);
        }
        /// <summary>
        /// Sets the pay with form. Call CreateAuthorizationParameters first.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="allow3dSecure">if set to <c>true</c> [allow3d secure].</param>
        /// <param name="hideClientEmail">if set to <c>true</c> [hide client email].</param>
        /// <exception cref="System.ArgumentNullException">collection</exception>
        public void SetPayWithForm(
            TransactionRequest collection,
            bool allow3dSecure = true,
            bool hideClientEmail = false)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");

            collection.Add(Names.Params.Use3DSecure, allow3dSecure ? Names.Params.Yes : Names.Params.No);
            collection.Add(Names.Params.HideClientEmail, hideClientEmail ? Names.Params.Yes : Names.Params.No);
        }
        /// <summary>
        /// Sets the pay with alias. Call CreateAuthorizationParameters first.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="alias">The alias.</param>
        /// <param name="userAddress">The user address.</param>
        /// <param name="userAgent">The user agent.</param>
        /// <exception cref="System.ArgumentNullException">collection</exception>
        /// <exception cref="System.ArgumentException">
        /// The value cannot be empty;alias
        /// or
        /// The value cannot be empty;userAddress
        /// or
        /// The value cannot be empty;userAgent
        /// </exception>
        public void SetPayWithAlias(TransactionRequest collection, string alias, string userAddress, string userAgent)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");
            if (string.IsNullOrEmpty(alias))
                throw new ArgumentException("The value cannot be empty", "alias");
            if (string.IsNullOrEmpty(userAddress))
                throw new ArgumentException("The value cannot be empty", "userAddress");
            if (string.IsNullOrEmpty(userAgent))
                throw new ArgumentException("The value cannot be empty", "userAgent");

            collection.Add(Names.Params.Alias, alias);
            collection.Add(Names.Params.AliasMode, Names.Params.AliasModeOneClick);
            collection.Add(Names.Params.ClientIP, userAddress);
            collection.Add(Names.Params.ClientUserAgent, userAgent);

            // some keys are not allowed when paying with alias
            string[] removeKeys = new string[]
            {
                Names.Params.Language,
                Names.Params.Use3DSecure,
                Names.Params.HideClientEmail,
            };
            foreach (var key in removeKeys)
            {
                if (collection.ContainsKey(key))
                    collection.Remove(key);
            }
        }