Exemplo n.º 1
0
        private static void LoadBillingDetails(Dictionary <string, string> inputFields, OrderReadOnly order, OpayoSettings settings, VendrContext context)
        {
            string tempStore;

            settings.OrderPropertyBillingLastName.MustNotBeNullOrWhiteSpace(nameof(settings.OrderPropertyBillingLastName));
            tempStore = order.Properties[settings.OrderPropertyBillingLastName];
            if (string.IsNullOrWhiteSpace(tempStore))
            {
                throw new ArgumentNullException(nameof(settings.OrderPropertyBillingLastName), "Billing last name must be provided");
            }
            inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.Surname, tempStore.Truncate(20));

            settings.OrderPropertyBillingFirstName.MustNotBeNullOrWhiteSpace(nameof(settings.OrderPropertyBillingFirstName));
            tempStore = order.Properties[settings.OrderPropertyBillingFirstName];
            if (string.IsNullOrWhiteSpace(tempStore))
            {
                throw new ArgumentNullException(nameof(settings.OrderPropertyBillingFirstName), "Billing forenames must be provided");
            }
            inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.Firstnames, tempStore.Truncate(20));

            settings.OrderPropertyBillingAddress1.MustNotBeNullOrWhiteSpace(nameof(settings.OrderPropertyBillingAddress1));
            tempStore = order.Properties[settings.OrderPropertyBillingAddress1];
            if (string.IsNullOrWhiteSpace(tempStore))
            {
                throw new ArgumentNullException(nameof(settings.OrderPropertyBillingAddress1), "Billing address 1 must be provided");
            }
            inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.Address1, tempStore.Truncate(100));

            if (string.IsNullOrWhiteSpace(settings.OrderPropertyBillingAddress2) == false)
            {
                tempStore = order.Properties[settings.OrderPropertyBillingAddress2];
                if (string.IsNullOrWhiteSpace(tempStore) == false)
                {
                    inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.Address2, tempStore.Truncate(100));
                }
            }

            settings.OrderPropertyBillingCity.MustNotBeNullOrWhiteSpace(nameof(settings.OrderPropertyBillingCity));
            tempStore = order.Properties[settings.OrderPropertyBillingCity];
            if (string.IsNullOrWhiteSpace(tempStore))
            {
                throw new ArgumentNullException(nameof(settings.OrderPropertyBillingCity), "Billing city must be provided");
            }
            inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.City, tempStore.Truncate(40));

            if (string.IsNullOrWhiteSpace(settings.OrderPropertyBillingPostcode) == false)
            {
                tempStore = order.Properties[settings.OrderPropertyBillingPostcode];
                if (string.IsNullOrWhiteSpace(tempStore) == false)
                {
                    inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.PostCode, tempStore.Truncate(10));
                }
            }

            var billingCountry = order.PaymentInfo.CountryId.HasValue
                ? context.Services.CountryService.GetCountry(order.PaymentInfo.CountryId.Value)
                : null;

            if (billingCountry == null)
            {
                throw new ArgumentNullException("billingCountry", "Billing country must be provided");
            }
            inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.Country, billingCountry.Code);

            if (billingCountry.Code == "US")
            {
                tempStore = order.Properties[settings.OrderPropertyBillingCounty];
                if (string.IsNullOrWhiteSpace(tempStore))
                {
                    throw new ArgumentNullException(nameof(settings.OrderPropertyBillingCounty), "Billing State must be provided for the US");
                }
                inputFields.Add(OpayoConstants.TransactionRequestFields.Billing.State, tempStore);
            }
        }
Exemplo n.º 2
0
        private static void LoadOrderValues(Dictionary <string, string> inputFields, OrderReadOnly order, OpayoSettings settings, VendrContext context)
        {
            inputFields.Add(OpayoConstants.TransactionRequestFields.VendorTxCode, order.OrderNumber);

            var currency     = context.Services.CurrencyService.GetCurrency(order.CurrencyId);
            var currencyCode = currency.Code.ToUpperInvariant();

            // Ensure currency has valid ISO 4217 code
            if (!Iso4217.CurrencyCodes.ContainsKey(currencyCode))
            {
                throw new Exception("Currency must be a valid ISO 4217 currency code: " + currency.Name);
            }

            inputFields.Add(OpayoConstants.TransactionRequestFields.Currency, currencyCode);
            inputFields.Add(OpayoConstants.TransactionRequestFields.Amount, order.TotalPrice.Value.WithTax.ToString("0.00", CultureInfo.InvariantCulture));

            var description = $"Vendr order - {order.TotalQuantity} items";

            if (string.IsNullOrWhiteSpace(settings.OrderPropertyDescription) == false)
            {
                var tempStore = order.Properties[settings.OrderPropertyDescription];
                if (string.IsNullOrWhiteSpace(tempStore?.Value) == false)
                {
                    description = tempStore.Value.Truncate(100);
                }
            }
            inputFields.Add(OpayoConstants.TransactionRequestFields.Description, description);


            LoadBillingDetails(inputFields, order, settings, context);
            LoadShippingDetails(inputFields, order, settings, context);

            if (settings.DisplayOrderLines)
            {
                LoadOrderLines(inputFields, order, settings);
            }
        }
Exemplo n.º 3
0
        private static void LoadOrderLines(Dictionary <string, string> inputFields, OrderReadOnly order, OpayoSettings settings)
        {
            var orderLines = new List <string>();

            foreach (var item in order.OrderLines)
            {
                var itemDescription = GetItemDescriptionByOrderPropertyDescriptionAlias(item, settings.OrderLinePropertyDescription);
                orderLines.Add($"{itemDescription}:{item.Quantity}:{item.UnitPrice.Value.WithoutTax:0.00}:{item.UnitPrice.Value.Tax:0.00}:{item.UnitPrice.Value.WithTax:0.00}:{item.TotalPrice.Value.WithTax:0.00}");
            }

            orderLines.Insert(0, orderLines.Count.ToString());

            inputFields.Add(OpayoConstants.TransactionRequestFields.Basket, string.Join(":", orderLines));
        }
Exemplo n.º 4
0
 private static void LoadBasicSettings(Dictionary <string, string> inputFields, OpayoSettings settings, string callbackUrl)
 {
     settings.VendorName.MustNotBeNullOrWhiteSpace(nameof(settings.VendorName));
     inputFields.Add(OpayoConstants.TransactionRequestFields.VpsProtocol, OpayoSettings.Defaults.VPSProtocol);
     inputFields.Add(OpayoConstants.TransactionRequestFields.TransactionType, (string.IsNullOrWhiteSpace(settings.TxType) ? OpayoSettings.Defaults.TxType : settings.TxType).ToUpper());
     inputFields.Add(OpayoConstants.TransactionRequestFields.Vendor, settings.VendorName);
     inputFields.Add(OpayoConstants.TransactionRequestFields.NotificationURL, callbackUrl);
 }