Пример #1
0
        /// <summary>
        /// Prepare Qualpay customer model
        /// </summary>
        /// <param name="customerModel">Customer model</param>
        /// <param name="customer">Customer</param>
        /// <returns>Qualpay customer model</returns>
        public QualpayCustomerModel PrepareQualpayCustomerModel(CustomerModel customerModel, Customer customer)
        {
            if (customerModel == null)
            {
                throw new ArgumentNullException(nameof(customerModel));
            }

            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            //try to get a customer from the Vault
            var vaultCustomer = _qualpayManager.GetCustomer(customer.Id);

            //prepare model
            var model = new QualpayCustomerModel
            {
                Id                = customerModel.Id,
                CustomerExists    = vaultCustomer != null,
                QualpayCustomerId = vaultCustomer?.CustomerId,
                HideBlock         = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, QualpayDefaults.HideBlockAttribute)
            };

            //prepare nested search models
            model.CustomerCardSearchModel.CustomerId = customer.Id;
            model.CustomerCardSearchModel.SetGridPageSize();

            return(model);
        }
        public IActionResult CreateQualpayCustomer(int customerId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            //try to get a customer with the specified id
            var customer = _customerService.GetCustomerById(customerId)
                           ?? throw new ArgumentException("No customer found with the specified id", nameof(customerId));

            //check whether customer is already exists in the Vault and try to create new one if does not exist
            var vaultCustomer = _qualpayManager.GetCustomer(customer.Id) ?? _qualpayManager.CreateCustomer(customer)
                                ?? throw new QNetException("Qualpay Customer Vault error: Failed to create customer. Error details in the log");

            return(Json(new { Result = true }));
        }