/// <summary>
        /// Initialize a payment request from an <see cref="OrderGroup"/> instance. Adds order number, amount, timestamp, buyer information etc.
        /// </summary>
        /// <param name="payment">The <see cref="VerifonePaymentRequest"/> instance to initialize</param>
        /// <param name="orderGroup"><see cref="OrderGroup"/></param>
        public virtual void InitializePaymentRequest(VerifonePaymentRequest payment, OrderGroup orderGroup)
        {
            OrderAddress orderAddress = orderGroup.OrderAddresses.First();

            payment.OrderTimestamp        = orderGroup.Created.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
            payment.MerchantAgreementCode = this.GetMerchantAgreementCode(payment);
            payment.PaymentLocale         = this.GetPaymentLocale(ContentLanguage.PreferredCulture);
            payment.OrderNumber           = orderGroup.OrderGroupId.ToString(CultureInfo.InvariantCulture.NumberFormat);

            payment.OrderCurrencyCode = this.IsProduction(payment)
                ? Iso4217Lookup.LookupByCode(CurrentMarket.DefaultCurrency.CurrencyCode).Number.ToString()
                : "978";

            payment.OrderGrossAmount     = orderGroup.Total.ToVerifoneAmountString();
            payment.OrderNetAmount       = (orderGroup.Total - orderGroup.TaxTotal).ToVerifoneAmountString();
            payment.OrderVatAmount       = orderGroup.TaxTotal.ToVerifoneAmountString();
            payment.BuyerFirstName       = orderAddress.FirstName;
            payment.BuyerLastName        = orderAddress.LastName;
            payment.OrderVatPercentage   = "0";
            payment.PaymentMethodCode    = "";
            payment.SavedPaymentMethodId = "";
            payment.StyleCode            = "";
            payment.RecurringPayment     = "0";
            payment.DeferredPayment      = "0";
            payment.SavePaymentMethod    = "0";
            payment.SkipConfirmationPage = "0";

            string phoneNumber = orderAddress.DaytimePhoneNumber ?? orderAddress.EveningPhoneNumber;

            if (string.IsNullOrWhiteSpace(phoneNumber) == false)
            {
                payment.BuyerPhoneNumber = phoneNumber;
            }

            payment.BuyerEmailAddress      = orderAddress.Email;
            payment.DeliveryAddressLineOne = orderAddress.Line1;

            if (string.IsNullOrWhiteSpace(orderAddress.Line2) == false)
            {
                payment.DeliveryAddressLineTwo = orderAddress.Line2;
            }

            payment.DeliveryAddressPostalCode  = orderAddress.PostalCode;
            payment.DeliveryAddressCity        = orderAddress.City;
            payment.DeliveryAddressCountryCode = "246";

            ApplyPaymentMethodConfiguration(payment);
        }
Пример #2
0
        private static void ConfigureDataMapping()
        {
            Mapper.Initialize(cfg => {
                cfg.CreateMap <Payment, PaymentModel>()
                .ForMember(des => des.CurrencyCode,
                           opt => opt.MapFrom(src => Iso4217Lookup.LookupByNumber(Convert.ToInt32(src.CurrencyCode)).Code));
                cfg.CreateMap <PaymentModel, Payment>()
                .ForMember(des => des.CurrencyCode,
                           opt => opt.MapFrom(src => Iso4217Lookup.LookupByCode(src.CurrencyCode).Number.ToString()));
                cfg.CreateMap <Payment, ResponseModel>()
                .ForMember(des => des.Status, opt => opt.MapFrom(src => (src.Status == "Approved" ? "A" : src.Status == "Rejected" ? "R" : "D")))
                .ForMember(des => des.Payment,
                           opt => opt.MapFrom(src => src.Amount + " " + Iso4217Lookup.LookupByNumber(Convert.ToInt32(src.CurrencyCode)).Code));

                cfg.CreateMap <List <Payment>, List <PaymentModel> >();
                cfg.CreateMap <List <PaymentModel>, List <Payment> >();
                cfg.CreateMap <List <Payment>, List <ResponseModel> >();
                cfg.CreateMap <List <ResponseModel>, List <Payment> >();
            });
        }
Пример #3
0
        /// <summary>
        /// Initialize a payment request from an <see cref="OrderGroup"/> instance. Adds order number, amount, timestamp, buyer information etc.
        /// </summary>
        /// <param name="payment">The <see cref="VerifonePaymentRequest"/> instance to initialize</param>
        /// <param name="orderGroup"><see cref="OrderGroup"/></param>
        public virtual void InitializePaymentRequest(VerifonePaymentRequest payment, IOrderGroup orderGroup)
        {
            IOrderAddress billingAddress  = FindBillingAddress(payment, orderGroup);
            IOrderAddress shipmentAddress = FindShippingAddress(payment, orderGroup);

            payment.OrderTimestamp        = orderGroup.Created.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
            payment.MerchantAgreementCode = GetMerchantAgreementCode(payment);
            payment.PaymentLocale         = GetPaymentLocale(ContentLanguage.PreferredCulture);
            payment.OrderNumber           = orderGroup.OrderLink.OrderGroupId.ToString(CultureInfo.InvariantCulture.NumberFormat);

            payment.OrderCurrencyCode = IsProduction(payment)
                ? Iso4217Lookup.LookupByCode(CurrentMarket.DefaultCurrency.CurrencyCode).Number.ToString()
                : "978";

            var totals = OrderGroupCalculator.GetOrderGroupTotals(orderGroup);

            payment.OrderGrossAmount = totals.Total.ToVerifoneAmountString();

            var netAmount = orderGroup.PricesIncludeTax ? totals.Total : totals.Total - totals.TaxTotal;

            payment.OrderNetAmount = netAmount.ToVerifoneAmountString();
            payment.OrderVatAmount = totals.TaxTotal.ToVerifoneAmountString();

            payment.BuyerFirstName       = billingAddress?.FirstName;
            payment.BuyerLastName        = billingAddress?.LastName;
            payment.OrderVatPercentage   = "0";
            payment.PaymentMethodCode    = "";
            payment.SavedPaymentMethodId = "";
            payment.StyleCode            = "";
            payment.RecurringPayment     = "0";
            payment.DeferredPayment      = "0";
            payment.SavePaymentMethod    = "0";
            payment.SkipConfirmationPage = "0";

            string phoneNumber = billingAddress?.DaytimePhoneNumber ?? billingAddress?.EveningPhoneNumber;

            if (string.IsNullOrWhiteSpace(phoneNumber) == false)
            {
                payment.BuyerPhoneNumber = phoneNumber;
            }

            payment.BuyerEmailAddress = billingAddress?.Email ?? orderGroup.Name ?? string.Empty;

            if (payment.BuyerEmailAddress.IndexOf('@') < 0)
            {
                payment.BuyerEmailAddress = null;
            }

            payment.DeliveryAddressLineOne = shipmentAddress?.Line1;

            if (shipmentAddress != null && string.IsNullOrWhiteSpace(shipmentAddress.Line2) == false)
            {
                payment.DeliveryAddressLineTwo = shipmentAddress.Line2;
            }

            payment.DeliveryAddressPostalCode  = shipmentAddress?.PostalCode;
            payment.DeliveryAddressCity        = shipmentAddress?.City;
            payment.DeliveryAddressCountryCode = "246";

            ApplyPaymentMethodConfiguration(payment);
        }