Пример #1
0
        public PaymentInitializeResult Initialize(PaymentMethod currentPayment, string orderNumber, string returnUrl, string orderRef)
        {
            if (currentPayment.RequireAddressUpdate)
            {
                Log.InfoFormat(
                    "Retrieving consumer legal address for payment with ID:{0} belonging to order with ID: {1}",
                    currentPayment.Payment.Id, currentPayment.OrderGroupId);
                CustomerDetails customerDetails = CreateModel(currentPayment);
                if (customerDetails == null)
                {
                    throw new Exception("Payment class must be ExtendedPayExPayment when using this payment method");
                }

                var result = _paymentManager.GetAddressByPaymentMethod(currentPayment.PaymentMethodCode,
                                                                       customerDetails.SocialSecurityNumber, customerDetails.PostNumber, customerDetails.CountryCode,
                                                                       customerDetails.IpAddress);
                if (!result.Status.Success)
                {
                    return new PaymentInitializeResult {
                               ErrorMessage = result.Status.Description
                    }
                }
                ;

                var convertToConsumerAddress = ConvertToConsumerAddress(result);
                _paymentActions.UpdateConsumerInformation(currentPayment, convertToConsumerAddress);

                var extendedPayment = currentPayment.Payment as ExtendedPayExPayment;
                _updateAddressHandler.UpdateAddress(currentPayment.Cart, extendedPayment);

                Log.InfoFormat(
                    "Successfully retrieved consumer legal address for payment with ID:{0} belonging to order with ID: {1}",
                    currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }
            else
            {
                Log.InfoFormat(
                    "Payment method is configured to not use consumer legal address for payment with ID:{0} belonging to order with ID: {1}",
                    currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            return(_paymentInitializer.Initialize(currentPayment, orderNumber, returnUrl, orderRef));
        }