public string Create(long accountNumber, PaymentInformation payment, string encryptionKey)
        {
            var stringToHash = string.Concat(accountNumber, payment.PurchaseOperation, payment.Price, payment.PriceArgList, payment.Currency, payment.Vat, payment.OrderId, payment.ProductNumber,
                                payment.Description, payment.ClientIpAddress, payment.ClientIdentifier, payment.AdditionalValues, payment.ReturnUrl, payment.View,
                                payment.AgreementRef, payment.CancelUrl, payment.ClientLanguage, encryptionKey);

            return CreateHash(stringToHash);
        }
        public static PayExAddress OrderAddress(Cart cart, PaymentInformation payment, InitializeResult result)
        {
            PayExAddress payexAddress = new PayExAddress(result.OrderRef.ToString());

            if (cart == null || cart.OrderForms == null || cart.OrderForms.Count == 0)
                return payexAddress;

            OrderForm orderForm = cart.OrderForms[0];

            OrderAddress billingAddress = cart.OrderAddresses.ToArray().FirstOrDefault(x => x.Name == orderForm.BillingAddressId);
            if (billingAddress != null)
                payexAddress.BillingAddress.Populate(billingAddress);

            if (orderForm.Shipments != null && orderForm.Shipments.Count > 0 && orderForm.Shipments[0] != null)
            {
                OrderAddress shippingAddress = cart.OrderAddresses.ToArray().FirstOrDefault(x => x.Name == orderForm.Shipments[0].ShippingAddressId);
                if (shippingAddress != null)
                    payexAddress.ShippingAddress.Populate(shippingAddress);
            }

            return payexAddress;
        }
        public InitializeResult Initialize(Cart cart, PaymentInformation payment, bool ignoreOrderLines = false, bool ignoreCustomerAddress = false)
        {
            Log.InfoFormat("Calling Initialize for cart with ID:{0}. PaymentInformation:{1}", cart.Id, payment);

            string hash = _hasher.Create(_payExSettings.AccountNumber, payment, _payExSettings.EncryptionKey);
            string xmlResult = _orderFacade.Initialize(_payExSettings.AccountNumber, payment, hash);

            InitializeResult result = _resultParser.Deserialize<InitializeResult>(xmlResult);
            if (!result.Status.Success)
            {
                Log.ErrorFormat("Error when calling Initialize for cart with ID:{0}. Result:{1}", cart.Id, xmlResult);
                return result;
            }

            Log.InfoFormat("Successfully called Initialize for cart with ID:{0}. Result:{1}", cart.Id, xmlResult);

            if (!ignoreOrderLines && _payExSettings.IncludeOrderLines)
                AddOrderLineItems(cart, payment, result);

            if (!ignoreCustomerAddress && _payExSettings.IncludeCustomerAddress)
                AddOrderAddress(cart, payment, result);

            return result;
        }
 public string Initialize(long accountNumber, PaymentInformation payment, string hash)
 {
     return Client.Initialize8(accountNumber, payment.PurchaseOperation, payment.Price, payment.PriceArgList, payment.Currency, payment.Vat, payment.OrderId,
                               payment.ProductNumber, payment.Description, payment.ClientIpAddress, payment.ClientIdentifier, payment.AdditionalValues,
                               string.Empty, payment.ReturnUrl, payment.View, payment.AgreementRef, payment.CancelUrl, payment.ClientLanguage, hash);
 }
        private void AddOrderLineItems(Cart cart, PaymentInformation payment, InitializeResult initializeResult)
        {
            Log.InfoFormat("Calling AddOrderLineItems for cart with ID:{0}. PaymentInformation:{1}. InitializeResult:{2}", cart.Id, payment, initializeResult);

            List<OrderLine> orderlines = CartHelper.OrderLines(cart, payment, initializeResult);
            foreach (OrderLine orderline in orderlines)
            {
                string hash = _hasher.Create(_payExSettings.AccountNumber, orderline, _payExSettings.EncryptionKey);
                string result = _orderFacade.AddOrderLine(_payExSettings.AccountNumber, orderline, hash);

                Log.InfoFormat("Added OrderLineItem for cart with ID:{0}. OrderLine:{1}. Result:{2}",
                    cart.Id, orderline, result);
            }
        }
        private void AddOrderAddress(Cart cart, PaymentInformation payment, InitializeResult initializeResult)
        {
            Log.InfoFormat("Calling AddOrderAddress for cart with ID:{0}. PaymentInformation:{1}. InitializeResult:{2}", cart.Id, payment, initializeResult);

            PayExAddress address = CartHelper.OrderAddress(cart, payment, initializeResult);
            string hash = _hasher.Create(_payExSettings.AccountNumber, address, _payExSettings.EncryptionKey);
            string xmlResult = _orderFacade.AddOrderAddress(_payExSettings.AccountNumber, address, hash);

            Log.InfoFormat("Finished calling AddOrderAddress for cart with ID:{0}. PaymentInformation:{1}. InitializeResult:{2}. Result:{3}",
                cart.Id, payment, initializeResult, xmlResult);
        }
        public static List<OrderLine> OrderLines(Cart cart, PaymentInformation payment, InitializeResult result)
        {
            List<OrderLine> orderLines = new List<OrderLine>();
            if (cart == null || cart.OrderForms == null || cart.OrderForms.Count == 0)
                return orderLines;

            OrderForm orderForm = cart.OrderForms[0];
            if (orderForm == null || orderForm.LineItems == null || orderForm.LineItems.Count == 0)
                return orderLines;

            foreach (LineItem lineItem in orderForm.LineItems)
            {
                orderLines.Add(new OrderLine(result.OrderRef.ToString(), lineItem.CatalogEntryId, lineItem.DisplayName, (int)lineItem.Quantity,
                    lineItem.ExtendedPrice.RoundToInt(), GetVatAmount(lineItem), GetVatPercentage(lineItem)));
            }

            decimal shippingVatPercentage = GetShippingVatPercentage();
            foreach (Shipment shipment in orderForm.Shipments)
            {
                decimal shippingVatAmount = cart.ShippingTotal * (shippingVatPercentage / 100);
                orderLines.Add(new OrderLine(result.OrderRef.ToString(), string.Empty, GetShippingMethodName(shipment), 1,
                    cart.ShippingTotal.RoundToInt(), shippingVatAmount, shippingVatPercentage));
            }
            return orderLines;
        }
Esempio n. 8
0
        private void AddOrderLineItems(Cart cart, PaymentInformation payment, InitializeResult initializeResult)
        {
            Log.Info($"Calling AddOrderLineItems for cart with ID:{cart.Id}. PaymentInformation:{payment}. InitializeResult:{initializeResult}");

            var orderlines = CartHelper.OrderLines(cart, payment, initializeResult);
            foreach (var orderline in orderlines)
            {
                var hash = _hasher.Create(_payExSettings.AccountNumber, orderline, _payExSettings.EncryptionKey);
                var result = _orderFacade.AddOrderLine(_payExSettings.AccountNumber, orderline, hash);

                Log.Info($"Added OrderLineItem for cart with ID:{cart.Id}. OrderLine:{orderline}. Result:{result}");
            }
        }
Esempio n. 9
0
        private void AddOrderAddress(Cart cart, PaymentInformation payment, InitializeResult initializeResult)
        {
            Log.Info($"Calling AddOrderAddress for cart with ID:{cart.Id}. PaymentInformation:{payment}. InitializeResult:{initializeResult}");

            var address = CartHelper.OrderAddress(cart, payment, initializeResult);
            var hash = _hasher.Create(_payExSettings.AccountNumber, address, _payExSettings.EncryptionKey);
            var xmlResult = _orderFacade.AddOrderAddress(_payExSettings.AccountNumber, address, hash);

            Log.Info($"Finished calling AddOrderAddress for cart with ID:{cart.Id}. PaymentInformation:{payment}. InitializeResult:{initializeResult}. Result:{xmlResult}");
        }