Esempio n. 1
0
        public void Update_AcceptsNestedBillingAddressId()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            AddressRequest addressRequest = new AddressRequest
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            Address address = gateway.Address.Create(customer.Id, addressRequest).Target;

            var updateRequest = new CustomerRequest
            {
                CreditCard = new CreditCardRequest
                {
                    Number           = "4111111111111111",
                    ExpirationDate   = "10/10",
                    BillingAddressId = address.Id
                }
            };

            Customer updatedCustomer = gateway.Customer.Update(customer.Id, updateRequest).Target;
            Address  billingAddress  = updatedCustomer.CreditCards[0].BillingAddress;

            Assert.AreEqual(address.Id, billingAddress.Id);
            Assert.AreEqual("John", billingAddress.FirstName);
            Assert.AreEqual("Doe", billingAddress.LastName);
        }
Esempio n. 2
0
        public bool Run(string address)
        {
            Request = new AddressRequest();
            Request.param.Address = address;

            return(Run(Request));
        }
Esempio n. 3
0
        private static void GetFullMinicipalInfoByAddressTest(AddressRequest address = null)
        {
            var service = new GovernmentService();

            if (address == null)
            {
                RequestAddress(out address);
            }

            //Get Municipal Info
            var muni = service.GetMunicipalByAddress(address);

            if (muni == null)
            {
                service.DisplayText("Municipal Not Found");
            }
            service.DisplayText($"Municipal: {muni.MunicipalName}");

            service.DisplayText("Officials");
            //Get Officials
            var officials = service.GetOfficialsByMunicipalNumber(muni.MunicipalNumber).OrderBy(o => o.FullName).ToList();

            officials.ForEach(o => { Console.WriteLine($"{o.Position}: {o.FullName}"); });


            Console.ReadLine();
        }
        public void Find_FindsAddress()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressRequest = new AddressRequest
            {
                FirstName = "Michael",
                LastName = "Angelo",
                Company = "Angelo Co.",
                StreetAddress = "1 E Main St",
                ExtendedAddress = "Apt 3",
                Locality = "Chicago",
                Region = "IL",
                PostalCode = "60622",
                CountryName = "United States of America"
            };

            Address createdAddress = gateway.Address.Create(customer.Id, addressRequest).Target;
            Address address = gateway.Address.Find(customer.Id, createdAddress.Id);

            Assert.AreEqual("Michael", address.FirstName);
            Assert.AreEqual("Angelo", address.LastName);
            Assert.AreEqual("Angelo Co.", address.Company);
            Assert.AreEqual("1 E Main St", address.StreetAddress);
            Assert.AreEqual("Apt 3", address.ExtendedAddress);
            Assert.AreEqual("Chicago", address.Locality);
            Assert.AreEqual("IL", address.Region);
            Assert.AreEqual("60622", address.PostalCode);
            Assert.AreEqual("United States of America", address.CountryName);
        }
Esempio n. 5
0
        public async Task UpdateUserAddressAsync(int userId, int addressId, AddressRequest addressRequest)
        {
            if (addressRequest == null)
            {
                throw new ArgumentNullException(nameof(addressRequest));
            }

            var userDal = await _repository.GetUserByIdAsync(userId);

            if (userDal.Addresses.All(a => a.Id != addressId))
            {
                throw new ResourceNotFoundException();
            }

            if (userDal.Addresses.Any(a => a.Description == addressRequest.Description))
            {
                throw new ResourceHasConflictException("description");
            }

            var addressDal = Mapper.Map <AddressDal>(addressRequest);

            addressDal.Id   = addressId;
            addressDal.User = userDal;

            await _repository.UpdateAddressAsync(addressId, addressDal);
        }
Esempio n. 6
0
        /// <summary>
        /// This test case is used to create multiple addresses and report time
        /// </summary>
        /// <param name="count">holds the number of addreses to insert</param>
        static void testCaseAddMultipleAddreses(int count)
        {
            AddressMaintenance am = new AddressMaintenance();

            for (int i = 0; i < count; i++)
            {
                AddressRequest a = new AddressRequest();
                a.AddressLine1      = "Address Line 1 " + i.ToString();
                a.AddressLine2      = "Address Line 2 " + i.ToString();
                a.City              = "City " + i.ToString();
                a.Company           = "Company " + i.ToString();
                a.Name              = "Name " + i.ToString();
                a.ZipCode           = "98001 " + i.ToString();
                a.StateAbbreviation = "WA";
                AddressResponse resp = am.addAddress(a);
                if (resp.Status != "Success")
                {
                    Console.WriteLine("Exceptions:");
                    foreach (string e in resp.exceptions)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        } // end testCaseAddMultipleAddresses
Esempio n. 7
0
        /// <summary>
        /// This test case tests attempting to add an improperly formed address
        /// </summary>
        static void testCaseAddAddressNegative()
        {
            AddressMaintenance am = new AddressMaintenance();

            try
            {
                AddressRequest request = new AddressRequest();
                request.StateAbbreviation = "WA";
                request.Name         = "";
                request.City         = "";
                request.AddressLine1 = "";
                request.AddressLine2 = "Address LIne 56";
                request.Company      = "";
                request.ZipCode      = "";

                AddressResponse response = am.addAddress(request);
                if (response.Status != "Success")
                {
                    Console.WriteLine("Exceptions:");
                    foreach (string e in response.exceptions)
                    {
                        Console.WriteLine(e);
                    }
                }
                else
                {
                    Console.WriteLine("Address id = " + response.id.ToString());
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
Esempio n. 8
0
        public async Task AddAccountAddress(string accountMasterExtId, TestAccountAddress address = null)
        {
            string externalIdentifier = address == null ? accountMasterExtId : address.ExternalIdentifier;

            //clear account address if exist
            //await RemoveAddress(externalIdentifier);

            address = address ?? new TestAccountAddress
            {
                Apartment           = "12",
                City                = "denver",
                CompanyName         = "dfs",
                Country             = "US",
                ExternalIdentifier  = accountMasterExtId,
                Postal              = "80019",
                StateProvinceRegion = "CO",
                Street              = "Walnut Street"
            };

            AddressRequest addressRequest = new AddressRequest
            {
                AddressLine  = address.Street,
                AddressLine2 = address.Apartment,
                City         = address.City,
                Country      = address.Country,
                Identifier   = externalIdentifier,
                Name         = address.CompanyName,
                Postal       = address.Postal,
                State        = address.StateProvinceRegion
            };
            await _client.Addresses.Create(accountMasterExtId, addressRequest);
        }
Esempio n. 9
0
        public IActionResult PutAddress(Guid clientId, [FromBody] AddressRequest request)
        {
            var exists = addresses.Any(a => a.ClientId == clientId);

            if (exists)
            {
                var requestError = IsRequestValid(request);

                if (requestError == null)
                {
                    var address = addresses.Find(a => a.ClientId.Equals(request.ClientId));
                    address.AddressLine1 = request.AddressLine1;
                    address.AddressLine2 = request.AddressLine2;
                    address.Postcode     = request.Postcode;
                    return(Ok(address));
                }
                else
                {
                    return(requestError);
                }
            }
            else
            {
                return(NotFound());
            }
        }
        public HttpResponseMessage Add([FromBody] AddressRequest bxAddress)
        {
            var viewModel = new CreateAddressViewModel();

            try
            {
                int addressId = _AddressService.Add(bxAddress);
                if (addressId > 0)
                {
                    viewModel.BusinessStatus = 1;
                    viewModel.AddressId      = addressId;
                }
                else
                {
                    viewModel.BusinessStatus = -10002;
                    viewModel.StatusMessage  = "创建地址失败";
                }
            }
            catch (Exception ex)
            {
                viewModel.BusinessStatus = -10002;
                viewModel.StatusMessage  = "创建地址失败";
            }
            return(viewModel.ResponseToJson());
        }
Esempio n. 11
0
        /// <summary>
        /// Generates new addresses, meaning addresses which were not spend from, according to the connected node.
        /// </summary>
        /// <param name="addressRequest"></param>
        /// <returns></returns>
        public GetNewAddressResponse GenerateNewAddresses(AddressRequest addressRequest)
        {
            var stopwatch = Stopwatch.StartNew();

            List <string> addresses;

            if (addressRequest.Amount == 0)
            {
                string unusedAddress = GetFirstUnusedAddress(
                    addressRequest.Seed, addressRequest.SecurityLevel,
                    addressRequest.Index, addressRequest.Checksum);

                addresses = new List <string>
                {
                    unusedAddress
                };
            }
            else
            {
                addresses = GetAddresses(
                    addressRequest.Seed, addressRequest.SecurityLevel,
                    addressRequest.Index, addressRequest.Checksum,
                    addressRequest.Amount, addressRequest.AddSpendAddresses);
            }

            stopwatch.Stop();
            return(new GetNewAddressResponse
            {
                Addresses = addresses,
                Duration = stopwatch.ElapsedMilliseconds
            });
        }
        public async Task <IActionResult> UpdateAddress(int id, AddressRequest request)
        {
            var mapped   = request.MapToAddress(_mapper);
            var response = await _service.UpdateAddress(id, mapped);

            return(StatusCode(response.Code, response));
        }
        public async Task FindAsync_FindsAddress()
        {
            Result<Customer> customerResult = await gateway.Customer.CreateAsync(new CustomerRequest());
            Customer customer = customerResult.Target;

            var addressRequest = new AddressRequest
            {
                FirstName = "Michael",
                LastName = "Angelo",
                Company = "Angelo Co.",
                StreetAddress = "1 E Main St",
                ExtendedAddress = "Apt 3",
                Locality = "Chicago",
                Region = "IL",
                PostalCode = "60622",
                CountryName = "United States of America"
            };

            Result<Address> addressResult = await gateway.Address.CreateAsync(customer.Id, addressRequest);
            Address createdAddress = addressResult.Target;
            Address address = await gateway.Address.FindAsync(customer.Id, createdAddress.Id);

            Assert.AreEqual("Michael", address.FirstName);
            Assert.AreEqual("Angelo", address.LastName);
            Assert.AreEqual("Angelo Co.", address.Company);
            Assert.AreEqual("1 E Main St", address.StreetAddress);
            Assert.AreEqual("Apt 3", address.ExtendedAddress);
            Assert.AreEqual("Chicago", address.Locality);
            Assert.AreEqual("IL", address.Region);
            Assert.AreEqual("60622", address.PostalCode);
            Assert.AreEqual("United States of America", address.CountryName);
        }
 public ActionResult AddAddress(AddressRequest request)
 {
     return(this.Execute(
                () => this.accountService.AddAddress(
                    this.visitorContext.ContactId,
                    this.mapper.Map <AddressRequest, Address>(request))));
 }
Esempio n. 15
0
 public Address(AddressRequest request)
 {
     Street = request.Street;
     Number = request.Number;
     City   = request.City;
     State  = request.State;
 }
Esempio n. 16
0
        public IActionResult Add([FromBody] AddressRequest addressRequest)
        {
            Address newAddress = _mapper.Map <Address>(addressRequest);

            _address.Register(newAddress);
            return(CreatedAtAction(nameof(Get), new { id = newAddress.Id }, newAddress));
        }
Esempio n. 17
0
 public void InitializeTest()
 {
     using (var client = TestHelper.ClientGet())
     {
         // ContactType seems to be mandatory for a create action of the CiviCRM
         // contact api.
         var result = client.ContactSave(TestHelper.ApiKey, TestHelper.SiteKey,
                                         new ContactRequest {
             ContactType = ContactType.Individual, FirstName = "Joe", LastName = "Schmoe"
         });
         _myContactId = result.Values.First().Id;
         // TODO: chain this address creation.
         var addressRequest = new AddressRequest
         {
             ContactId      = _myContactId,
             StreetAddress  = "Kipdorp 30",
             PostalCode     = "2000",
             City           = "Antwerpen",
             CountryId      = 1020, // Belgium
             LocationTypeId = 1,
             Name           = MyAddressName
         };
         // If this fails, please turn off map and geocode services.
         // (Adminis, System Settings, Maps)
         var addressResult = client.AddressSave(TestHelper.ApiKey, TestHelper.SiteKey, addressRequest);
         var address       = addressResult.Values.First();
         _myAddressId = address.Id;
     }
 }
Esempio n. 18
0
        //TODO
        //when not found the response is a string
        //[TestMethod]
        //public async Task DELETE_Address_NotFound()

        public override async Task TestScenarioSetUp(AddressTestData testData)
        {
            AccountMasterRequest accountMasterRequest = new AccountMasterRequest
            {
                Identifier         = testData.AccountMasterExtId,
                Name               = "temporal request helper",
                CreateAccount      = false,
                IsWebEnabled       = true,
                CreatedBy          = "temporal request",
                TermsConfiguration = new AccountMasterTermConfiguration
                {
                    HasPaymentTerms  = true,
                    TermsDescription = "Net 15 days"
                }
            };
            AddressRequest addressRequest = new AddressRequest
            {
                Identifier   = testData.ExternalIdentifier,
                Name         = "temporal address",
                AddressLine  = "elm street",
                AddressLine2 = "1",
                City         = "denver",
                Country      = "US",
                State        = "Colorado",
                Postal       = "1234567890"
            };

            await Client.AccountMasters.Create(accountMasterRequest);

            await Client.Addresses.Create(testData.AccountMasterExtId, addressRequest);
        }
Esempio n. 19
0
        public void AddAddress()
        {
            using (var client = TestHelper.ClientGet())
            {
                var newAddress = new AddressRequest
                {
                    ContactId      = _myContactId,
                    StreetAddress  = "Hoefslagstraatje 2",
                    PostalCode     = "9000",
                    City           = "Gent",
                    CountryId      = 1020, // Belgium
                    LocationTypeId = 1,
                };

                var result = client.AddressSave(TestHelper.ApiKey, TestHelper.SiteKey, newAddress);
                Assert.AreEqual(0, result.IsError);
                Assert.AreEqual(1, result.Count);

                var resultAddress = result.Values.First();

                Assert.AreEqual(newAddress.ContactId, resultAddress.ContactId);
                Assert.AreEqual(newAddress.StreetAddress, resultAddress.StreetAddress);
                Assert.AreEqual(newAddress.PostalCode, resultAddress.PostalCode);
                Assert.AreEqual(1020, resultAddress.CountryId);
                Assert.AreEqual(newAddress.LocationTypeId, resultAddress.LocationTypeId);
            }
        }
Esempio n. 20
0
        public async Task PUT_Address_Success()
        {
            AddressTestData testData = new AddressTestData
            {
                ExternalIdentifier = "putAddress01",
                AccountMasterExtId = "putAddressAccountMaster01"
            };

            await TestScenarioSetUp(testData);

            AddressRequest addressRequest = new AddressRequest
            {
                AddressLine  = "address updated",
                AddressLine2 = "1212",
                City         = "denver",
                Country      = "US",
                Name         = "name updated",
                Postal       = "0987654321",
                State        = "co"
            };

            AddressResponse response = await Client.Addresses.Update(testData.ExternalIdentifier, addressRequest);

            //validations
            Assert.IsNotNull(response, "Response object should not be null");

            //specific validations
            Assert.AreEqual(addressRequest.AddressLine, response.AddressLine);
            Assert.AreEqual(addressRequest.Name, response.Name);

            //test scenario clean up
            await TestScenarioCleanUp(testData);
        }
Esempio n. 21
0
        /// <summary>
        /// The Validate.
        /// </summary>
        /// <param name="addressRequest"></param>
        /// <returns>The <see cref="ErrorInfo"/>.</returns>
        public static ErrorInfo Validate(AddressRequest addressRequest)
        {
            var e = new ErrorInfo();

            if (string.IsNullOrWhiteSpace(addressRequest.AddressLine1))
            {
                e.ErrorCode    = ErrorTypes.InvalidFullName;
                e.ErrorMessage = "Address 1 cannot be empty.";
                return(e);
            }

            if (string.IsNullOrWhiteSpace(addressRequest.City))
            {
                e.ErrorCode    = ErrorTypes.InvalidFullName;
                e.ErrorMessage = "City cannot be empty.";
                return(e);
            }

            if (string.IsNullOrWhiteSpace(addressRequest.State))
            {
                e.ErrorCode    = ErrorTypes.InvalidFullName;
                e.ErrorMessage = "State cannot be empty.";
                return(e);
            }

            return(e);
        }
        public void Create_AcceptsBillingAddressId()
        {
            Customer       customer       = gateway.Customer.Create(new CustomerRequest()).Target;
            AddressRequest addressRequest = new AddressRequest
            {
                FirstName          = "John",
                CountryName        = "Chad",
                CountryCodeAlpha2  = "TD",
                CountryCodeAlpha3  = "TCD",
                CountryCodeNumeric = "148"
            };

            Address address = gateway.Address.Create(customer.Id, addressRequest).Target;

            var creditCardRequest = new CreditCardRequest
            {
                CustomerId       = customer.Id,
                Number           = "5105105105105100",
                ExpirationDate   = "05/12",
                CVV              = "123",
                CardholderName   = "Michael Angelo",
                BillingAddressId = address.Id
            };

            CreditCard creditCard = gateway.CreditCard.Create(creditCardRequest).Target;

            Address billingAddress = creditCard.BillingAddress;

            Assert.AreEqual(address.Id, billingAddress.Id);
            Assert.AreEqual("Chad", billingAddress.CountryName);
            Assert.AreEqual("TD", billingAddress.CountryCodeAlpha2);
            Assert.AreEqual("TCD", billingAddress.CountryCodeAlpha3);
            Assert.AreEqual("148", billingAddress.CountryCodeNumeric);
        }
Esempio n. 23
0
        public void Delete_DeletesTheAddress()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressRequest = new AddressRequest
            {
                StreetAddress   = "1 E Main St",
                ExtendedAddress = "Apt 3",
            };

            Address createdAddress = gateway.Address.Create(customer.Id, addressRequest).Target;

            Assert.AreEqual(createdAddress.Id, gateway.Address.Find(customer.Id, createdAddress.Id).Id);

            Result <Address> result = gateway.Address.Delete(customer.Id, createdAddress.Id);

            Assert.IsTrue(result.IsSuccess());
            try
            {
                gateway.Address.Find(customer.Id, createdAddress.Id);
                Assert.Fail("Expected NotFoundException.");
            }
            catch (NotFoundException)
            {
                // expected
            }
        }
Esempio n. 24
0
        public void Find_FindsAddress()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressRequest = new AddressRequest
            {
                FirstName       = "Michael",
                LastName        = "Angelo",
                Company         = "Angelo Co.",
                StreetAddress   = "1 E Main St",
                ExtendedAddress = "Apt 3",
                Locality        = "Chicago",
                Region          = "IL",
                PostalCode      = "60622",
                CountryName     = "United States of America"
            };

            Address createdAddress = gateway.Address.Create(customer.Id, addressRequest).Target;
            Address address        = gateway.Address.Find(customer.Id, createdAddress.Id);

            Assert.AreEqual("Michael", address.FirstName);
            Assert.AreEqual("Angelo", address.LastName);
            Assert.AreEqual("Angelo Co.", address.Company);
            Assert.AreEqual("1 E Main St", address.StreetAddress);
            Assert.AreEqual("Apt 3", address.ExtendedAddress);
            Assert.AreEqual("Chicago", address.Locality);
            Assert.AreEqual("IL", address.Region);
            Assert.AreEqual("60622", address.PostalCode);
            Assert.AreEqual("United States of America", address.CountryName);
        }
Esempio n. 25
0
        public async Task <HttpResponse> Create(AddressRequest request)
        {
            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(request));

            HttpResponse response = await Post(stringPayload);

            return(response.TryParseEntity <AddressResponse>());
        }
Esempio n. 26
0
        public async Task <HttpResponse> Update(AddressRequest request)
        {
            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(request));

            HttpResponse response = await Put(request.ExternalIdentifier, stringPayload);

            return(response.TryParseEntity <AddressResponse>());
        }
Esempio n. 27
0
 public List <string> ValidateOrderAddress(AddressRequest address)
 {
     address.Errors = ValidateStreet(address);
     address.Errors = ValidateHouseNumber(address);
     address.Errors = ValidatePostCode(address);
     address.Errors = ValidateCity(address);
     return(address.Errors);
 }
 public EmployeeRequest(NameRequest name, DocumentRequest document, EmailRequest email,
                        AddressRequest address, EmployeePositionRequest employeePosition)
 {
     Name             = name;
     Document         = document;
     Email            = email;
     Address          = address;
     EmployeePosition = employeePosition;
 }
Esempio n. 29
0
        public async Task <Addresses> GetAsync(AddressRequest request)
        {
            Requires.ArgumentNotNull(request, nameof(request));

            var user = await _userClient.GetAsync().ConfigureAwait(_halClient);

            return(await _halClient.GetAsync <Addresses>(user.AddressesLink,
                                                         request).ConfigureAwait(_halClient));
        }
 public CompanyRequest(DocumentRequest document, EmailRequest email,
                       AddressRequest address, string companyName, string fantasyName)
 {
     Email       = email;
     Address     = address;
     Document    = document;
     FantasyName = fantasyName;
     CompanyName = companyName;
 }
        public void GetLocBlockWithEvents()
        {
            // Make sure that your API user has permissions
            // 'access CiviEvent', 'view event info',
            // and 'edit all events'.

            var myAddressRequest = new AddressRequest
            {
                LocationTypeId = 1,
                StreetAddress  = "Kipdorp 30",
                PostalCode     = "2000",
                City           = "Antwerpen"
            };

            var myEventRequest = new EventRequest
            {
                Title       = "My mighty unit test event",
                Description = "It will be fun.",
                StartDate   = new Filter <DateTime?>(new DateTime(2015, 07, 01)),
                EndDate     = new Filter <DateTime?>(new DateTime(2015, 07, 10)),
                EventTypeId = MyEventTypeId,
            };

            using (var client = TestHelper.ClientGet())
            {
                // Save the event by chaining everything to the loc block.
                var saveResult = client.LocBlockSave(TestHelper.ApiKey, TestHelper.SiteKey, new LocBlockRequest
                {
                    Address          = myAddressRequest,
                    EventSaveRequest = new[] { myEventRequest }
                });
                Assert.IsNotNull(saveResult.Id);

                int myLocBlockId = saveResult.Id.Value;
                int?myAddressId  = saveResult.Values.First().AddressId;
                Assert.IsNotNull(myAddressId);

                var locBlockGetRequest = new LocBlockRequest
                {
                    Id = myLocBlockId,
                    EventGetRequest = new EventRequest
                    {
                        LocBlockIdValueExpression = "$value.id",
                    }
                };
                var getResult = client.LocBlockGetSingle(TestHelper.ApiKey, TestHelper.SiteKey, locBlockGetRequest);

                client.EventDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(getResult.EventResult.Values.First().Id));
                client.LocBlockDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(myLocBlockId));
                client.AddressDelete(TestHelper.ApiKey, TestHelper.SiteKey, new DeleteRequest(myAddressId.Value));

                Assert.AreEqual(myLocBlockId, getResult.Id);
                Assert.AreEqual(1, getResult.EventResult.Count);
                var retrievedEvent = getResult.EventResult.Values.First();
                Assert.AreEqual(myEventRequest.Title, retrievedEvent.Title);
            }
        }
        public void Create_CreatesAddressForGivenCustomerId()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressRequest = new AddressRequest
            {
                FirstName = "Michael",
                LastName = "Angelo",
                Company = "Angelo Co.",
                StreetAddress = "1 E Main St",
                ExtendedAddress = "Apt 3",
                Locality = "Chicago",
                Region = "IL",
                PostalCode = "60622",
                CountryCodeAlpha2 = "US",
                CountryCodeAlpha3 = "USA",
                CountryCodeNumeric = "840",
                CountryName = "United States of America"
            };

            Address address = gateway.Address.Create(customer.Id, addressRequest).Target;

            Assert.AreEqual("Michael", address.FirstName);
            Assert.AreEqual("Angelo", address.LastName);
            Assert.AreEqual("Angelo Co.", address.Company);
            Assert.AreEqual("1 E Main St", address.StreetAddress);
            Assert.AreEqual("Apt 3", address.ExtendedAddress);
            Assert.AreEqual("Chicago", address.Locality);
            Assert.AreEqual("IL", address.Region);
            Assert.AreEqual("60622", address.PostalCode);
            Assert.AreEqual("US", address.CountryCodeAlpha2);
            Assert.AreEqual("USA", address.CountryCodeAlpha3);
            Assert.AreEqual("840", address.CountryCodeNumeric);
            Assert.AreEqual("United States of America", address.CountryName);
            Assert.IsNotNull(address.CreatedAt);
            Assert.IsNotNull(address.UpdatedAt);
        }
Esempio n. 33
0
        public void Update_AcceptsNestedBillingAddressId()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            AddressRequest addressRequest = new AddressRequest
            {
                FirstName = "John",
                LastName = "Doe"
            };

            Address address = gateway.Address.Create(customer.Id, addressRequest).Target;

            var updateRequest = new CustomerRequest
            {
                CreditCard = new CreditCardRequest
                {
                    Number = "4111111111111111",
                    ExpirationDate = "10/10",
                    BillingAddressId = address.Id
                }
            };

            Customer updatedCustomer = gateway.Customer.Update(customer.Id, updateRequest).Target;
            Address billingAddress = updatedCustomer.CreditCards[0].BillingAddress;
            Assert.AreEqual(address.Id, billingAddress.Id);
            Assert.AreEqual("John", billingAddress.FirstName);
            Assert.AreEqual("Doe", billingAddress.LastName);
        }
Esempio n. 34
0
        public ActionResult PaymentInfo(PaymentInfoModel model, string cancel)
        {
            if (cancel != null)
            {
                return (RedirectToAction("Index", "Home"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        //Credit Card
                        CreditCardRequest creditCard = new CreditCardRequest()
                        {
                            Cvv = model.CreditCard.Cvv,
                            ExpirationDate = model.CreditCard.ExpirationDate,
                            FirstNameOnCard = model.CreditCard.FirstNameOnCard,
                            LastNameOnCard = model.CreditCard.LastNameOnCard,
                            Number = model.CreditCard.Number
                        };

                        //Billing Address
                        AddressRequest billingAddress = new AddressRequest()
                        {

                            Address1 = model.BillingAddress.BillingAddress1,
                            City = model.BillingAddress.BillingCity,
                            Country = model.BillingAddress.BillingCountry,
                            FirstName = model.BillingAddress.BillingFirstName,
                            LastName = model.BillingAddress.BillingLastName,
                            StateProvince = model.BillingAddress.BillingProvince,
                            ZipPostalCode = model.BillingAddress.BillingZipPostalCode
                        };

                        ProfileCommon profile = ProfileCommon.GetUserProfile(User.Identity.Name);

                        // add or update the Credit card
                        if (model.CreditCard.Id <= 0)
                        {
                            var customer = _dynabicBillingGateway.Customer.GetCustomerByReferenceId(Config.MySiteSubdomain, profile.CustomerReferenceId);
                            _dynabicBillingGateway.Customer.AddCreditCard(customer.Id.ToString(), creditCard);
                        }
                        else
                        {
                            _dynabicBillingGateway.Customer.UpdateCreditCardByCustomerReferenceId(Config.MySiteSubdomain,
                                profile.CustomerReferenceId,
                                model.CreditCard.Id.ToString(),
                                creditCard);
                        }

                        // add or update the Billing Address
                        if (model.BillingAddress.BillingAddressId <= 0)
                        {
                            var customer = _dynabicBillingGateway.Customer.GetCustomerByReferenceId(Config.MySiteSubdomain, profile.CustomerReferenceId);
                            _dynabicBillingGateway.Customer.AddBillingAddress(customer.Id.ToString(), billingAddress);
                        }
                        else
                        {
                            _dynabicBillingGateway.Customer.UpdateBillingAddressByCustomerReferenceId(Config.MySiteSubdomain,
                                profile.CustomerReferenceId,
                                model.BillingAddress.BillingAddressId.ToString(),
                                billingAddress);
                        }

                        //set the Success message
                        TempData["PageMessage"] = new PageMessageModel
                        {
                            Type = PageMessageModel.MessageType.Success,
                            Message = "Your Payment details have been updated successfully."
                        };

                        return RedirectToAction("PaymentInfo", "Account");
                    }
                    catch
                    {
                        //provide an error message in case something went wrong
                        model.PageMessage = new PageMessageModel
                        {
                            Type = PageMessageModel.MessageType.Error,
                            Message = "Something went wrong. Please try again later."
                        };
                    }

                }
            }
            if (model.PageMessage == null)
                model.PageMessage = new PageMessageModel();
            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 35
0
        public ActionResult Register(RegisterModel model)
        {
            string message = "";

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);

                //if the registration process was successful,
                //add the newly registered user to your Customers and subscribe him to the Selected Plan
                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                    try
                    {
                        //get your Site data through Billing Gateway
                        var mySite = _dynabicBillingGateway.Sites.GetSiteBySubdomain(Config.MySiteSubdomain);

                        //get the selected plan
                        var selectedPlan = _dynabicBillingGateway.Products.GetProductById(model.Plans.SelectedPlan.ToString());

                        //generate a random Customer Reference Id
                        //CustomerReferenceId does not permit the usage of any other special characters except "-" and
                        //it isn't allowed to begin or end with this character nor it can be consecutive
                        Random r = new Random();
                        long value = (long)((r.NextDouble() * 2.0 - 1.0) * long.MaxValue);
                        string newCustomerReferenceId = string.Format("{0}-{1}", mySite.Id, Math.Abs(value));

                        //create a new CustomerRequest
                        CustomerRequest newCustomer = new CustomerRequest()
                        {
                            //this fields are required
                            FirstName = model.UserName,
                            LastName = model.UserName,
                            Email = model.Email,
                            ReferenceId = newCustomerReferenceId
                        };

                        //create a new Subscription Request
                        SubscriptionRequest newSubscription = new SubscriptionRequest()
                        {
                            Customer = newCustomer,
                            ProductId = selectedPlan.Id,
                            ProductPricingPlanId = selectedPlan.PricingPlans[0].Id,
                        };

                        //if the Credit Card is required at Signup 
                        //create a new Credit Card Request and add it to your Subscription
                        //isCreditCardAtSignupRequired may be "No", "Yes", "YesOptional"
                        if (selectedPlan.isCreditCardAtSignupRequired != BoolOptional.No)
                        {
                            CreditCardRequest newCreditCard = new CreditCardRequest()
                            {
                                Cvv = model.CreditCard.Cvv,
                                ExpirationDate = model.CreditCard.ExpirationDate,
                                FirstNameOnCard = model.CreditCard.FirstNameOnCard,
                                LastNameOnCard = model.CreditCard.LastNameOnCard,
                                Number = model.CreditCard.Number
                            };

                            newSubscription.CreditCard = newCreditCard;
                        }
                        //if the Billing Address is required at Signup 
                        //create a new Billing Address Request and add it to your Subscription
                        //isBillingAddressAtSignupRequired may be "No", "Yes", "YesOptional"
                        if (selectedPlan.isBillingAddressAtSignupRequired != BoolOptional.No)
                        {
                            AddressRequest billingAddress = new AddressRequest()
                            {
                                Address1 = model.BillingAddress.BillingAddress1,
                                City = model.BillingAddress.BillingCity,
                                Country = model.BillingAddress.BillingCountry,
                                StateProvince = model.BillingAddress.BillingProvince,
                                ZipPostalCode = model.BillingAddress.BillingZipPostalCode,
                                FirstName = model.BillingAddress.BillingFirstName,
                                LastName = model.BillingAddress.BillingLastName
                            };
                            newSubscription.BillingAddress = billingAddress;
                        }

                        //subscribe the newly created Customer to selected Plan
                        _dynabicBillingGateway.Subscription.AddSubscription(mySite.Subdomain, newSubscription);

                        //create a User Profile and save some data that we may need later
                        ProfileCommon profile = ProfileCommon.GetUserProfile(model.UserName);
                        profile.CurrentPlanId = model.Plans.SelectedPlan;
                        profile.CustomerReferenceId = newCustomerReferenceId;

                        //redirect to Home page 
                        return RedirectToAction("Index", "Home");
                    }
                    catch (Exception)
                    {
                        message = "Something went wrong. Please try again later.";
                    }
                }
                else
                {
                    message = ErrorCodeToString(createStatus);
                }
            }
            //provide an error message in case something went wrong
            model.PageMessage = new PageMessageModel
            {
                Type = PageMessageModel.MessageType.Error,
                Message = message
            };

            model.Plans.MyPlans = model.Plans.GetAllPlans(_dynabicBillingGateway);
            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public void Update_ReturnsAnErrorResult_ForInconsistenCountry()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressCreateRequest = new AddressRequest
            {
                FirstName = "Dave",
                LastName = "Inchy",
                Company = "Leon Ardo Co.",
                StreetAddress = "1 E State St",
                ExtendedAddress = "Apt 4",
                Locality = "Boston",
                Region = "MA",
                PostalCode = "11111",
                CountryName = "Canada",
                CountryCodeAlpha2 = "CA",
                CountryCodeAlpha3 = "CAN",
                CountryCodeNumeric = "124"
            };

            Address originalAddress = gateway.Address.Create(customer.Id, addressCreateRequest).Target;

            var addressUpdateRequest = new AddressRequest
            {
                FirstName = "Michael",
                LastName = "Angelo",
                Company = "Angelo Co.",
                StreetAddress = "1 E Main St",
                ExtendedAddress = "Apt 3",
                Locality = "Chicago",
                Region = "IL",
                PostalCode = "60622",
                CountryName = "United States of America",
                CountryCodeAlpha3 = "MEX"
            };

            Result<Address> result = gateway.Address.Update(customer.Id, originalAddress.Id, addressUpdateRequest);

            Assert.AreEqual(
                ValidationErrorCode.ADDRESS_INCONSISTENT_COUNTRY,
                result.Errors.ForObject("Address").OnField("Base")[0].Code
            );
        }
Esempio n. 37
0
 /// <summary>
 /// Updates an existing BillingAddress for a Customer
 /// </summary>
 /// <param name="siteSubdomain"> Subdomain of the Site where the Customer is registered </param>
 /// <param name="customerReferenceId"> The Customer's ReferenceID </param>
 /// <param name="billingAddressId"> The Id of the BillingAddress </param>
 /// <param name="updatedBillingAddress"> An AddressRequest object containing the updated BillingAddress record </param>
 /// <param name="format"> The format used for the data transfer (XML or JSON) </param>
 /// <returns> An AddressResponse object corresponding to the newly-updated BillingAddress </returns>
 public AddressResponse UpdateBillingAddressByCustomerReferenceId(string siteSubdomain, string customerReferenceId, string billingAddressId, AddressRequest updatedBillingAddress, string format = "xml")
 {
     return _service.Put<AddressRequest, AddressResponse>(string.Format("{0}/{1}/reference-id/{2}/billing-address/{3}.{4}", _gatewayURL, siteSubdomain, customerReferenceId, billingAddressId, format), updatedBillingAddress);
 }
Esempio n. 38
0
 /// <summary>
 /// Updates an existing BillingAddress for a Customer
 /// </summary>
 /// <param name="customerId"> The Id of the Customer </param>
 /// <param name="billingAddressId"> The Id of the BillingAddress </param>
 /// <param name="updatedBillingAddress"> The updated BillingAddress </param>
 /// <param name="format"> The format of the Response </param>
 /// <returns> An AddressResponse object corresponding to the newly-updated BillingAddress </returns>
 public AddressResponse UpdateBillingAddress(string customerId, string billingAddressId, AddressRequest updatedBillingAddress, string format = ContentFormat.XML)
 {
     return _service.Put<AddressRequest, AddressResponse>(string.Format("{0}/{1}/billing-address/{2}.{3}", _gatewayURL, customerId, billingAddressId, format), updatedBillingAddress);
 }
Esempio n. 39
0
 /// <summary>
 /// Adds a new BillingAddress for a Customer
 /// </summary>
 /// <param name="customerId"> The Id of the Customer </param>
 /// <param name="newBillingAddress"> The new BillingAddress </param>
 /// <param name="format"> The format of the Response </param>
 /// <returns> An AddressResponse object corresponding to the newly-inserted BillingAddress </returns>
 public AddressResponse AddBillingAddress(string customerId, AddressRequest newBillingAddress, string format = ContentFormat.XML)
 {
     return _service.Post<AddressRequest, AddressResponse>(string.Format("{0}/{1}/billing-address.{2}", _gatewayURL, customerId, format), newBillingAddress);
 }
        public void Delete_DeletesTheAddress()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressRequest = new AddressRequest
            {
                StreetAddress = "1 E Main St",
                ExtendedAddress = "Apt 3",
            };

            Address createdAddress = gateway.Address.Create(customer.Id, addressRequest).Target;
            Assert.AreEqual(createdAddress.Id, gateway.Address.Find(customer.Id, createdAddress.Id).Id);

            try {
                Result<Address> result = gateway.Address.Delete(customer.Id, createdAddress.Id);
                Assert.IsTrue(result.IsSuccess());
            } catch (NotFoundException) {
                Assert.Fail("Unable to delete the created address");
            }

            Assert.Throws<NotFoundException> (() => gateway.Address.Find(customer.Id, createdAddress.Id));
        }
        public void Create_ReturnsAnErrorResult()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
            AddressRequest request = new AddressRequest() { CountryName = "United States of Hammer" };

            Result<Address> createResult = gateway.Address.Create(customer.Id, request);
            Assert.IsFalse(createResult.IsSuccess());
            Dictionary<string, string> parameters = createResult.Parameters;
            Assert.AreEqual("integration_merchant_id", parameters["merchant_id"]);
            Assert.AreEqual(customer.Id, parameters["customer_id"]);
            Assert.AreEqual("United States of Hammer", parameters["address[country_name]"]);
        }
        public void Create_AcceptsBillingAddressId()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
            AddressRequest addressRequest = new AddressRequest
            {
                FirstName = "John",
                CountryName = "Chad",
                CountryCodeAlpha2 = "TD",
                CountryCodeAlpha3 = "TCD",
                CountryCodeNumeric = "148"
            };

            Address address = gateway.Address.Create(customer.Id, addressRequest).Target;

            var creditCardRequest = new CreditCardRequest
            {
                CustomerId = customer.Id,
                Number = "5105105105105100",
                ExpirationDate = "05/12",
                CVV = "123",
                CardholderName = "Michael Angelo",
                BillingAddressId = address.Id
            };

            CreditCard creditCard = gateway.CreditCard.Create(creditCardRequest).Target;

            Address billingAddress = creditCard.BillingAddress;
            Assert.AreEqual(address.Id, billingAddress.Id);
            Assert.AreEqual("Chad", billingAddress.CountryName);
            Assert.AreEqual("TD", billingAddress.CountryCodeAlpha2);
            Assert.AreEqual("TCD", billingAddress.CountryCodeAlpha3);
            Assert.AreEqual("148", billingAddress.CountryCodeNumeric);
        }
        public void Update_UpdatesAddressForGivenCustomerIdAndAddressId()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;

            var addressCreateRequest = new AddressRequest
            {
                FirstName = "Dave",
                LastName = "Inchy",
                Company = "Leon Ardo Co.",
                StreetAddress = "1 E State St",
                ExtendedAddress = "Apt 4",
                Locality = "Boston",
                Region = "MA",
                PostalCode = "11111",
                CountryName = "Canada",
                CountryCodeAlpha2 = "CA",
                CountryCodeAlpha3 = "CAN",
                CountryCodeNumeric = "124"
            };

            Address originalAddress = gateway.Address.Create(customer.Id, addressCreateRequest).Target;

            var addressUpdateRequest = new AddressRequest
            {
                FirstName = "Michael",
                LastName = "Angelo",
                Company = "Angelo Co.",
                StreetAddress = "1 E Main St",
                ExtendedAddress = "Apt 3",
                Locality = "Chicago",
                Region = "IL",
                PostalCode = "60622",
                CountryName = "United States of America",
                CountryCodeAlpha2 = "US",
                CountryCodeAlpha3 = "USA",
                CountryCodeNumeric = "840"
            };

            Address address = gateway.Address.Update(customer.Id, originalAddress.Id, addressUpdateRequest).Target;

            Assert.AreEqual("Michael", address.FirstName);
            Assert.AreEqual("Angelo", address.LastName);
            Assert.AreEqual("Angelo Co.", address.Company);
            Assert.AreEqual("1 E Main St", address.StreetAddress);
            Assert.AreEqual("Apt 3", address.ExtendedAddress);
            Assert.AreEqual("Chicago", address.Locality);
            Assert.AreEqual("IL", address.Region);
            Assert.AreEqual("60622", address.PostalCode);
            Assert.AreEqual("United States of America", address.CountryName);
            Assert.AreEqual("US", address.CountryCodeAlpha2);
            Assert.AreEqual("USA", address.CountryCodeAlpha3);
            Assert.AreEqual("840", address.CountryCodeNumeric);
        }
        public void Create_ReturnsAnErrorResult_ForInconsistentCountry()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
            AddressRequest request = new AddressRequest()
            {
                CountryName = "United States of America",
                CountryCodeAlpha2 = "BZ"
            };

            Result<Address> createResult = gateway.Address.Create(customer.Id, request);
            Assert.IsFalse(createResult.IsSuccess());
            Assert.AreEqual(
                ValidationErrorCode.ADDRESS_INCONSISTENT_COUNTRY,
                createResult.Errors.ForObject("Address").OnField("Base")[0].Code
            );
        }
        public void Create_ReturnsAnErrorResult_ForIncorrectNumeric()
        {
            Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
            AddressRequest request = new AddressRequest()
            {
                CountryCodeNumeric = "000"
            };

            Result<Address> createResult = gateway.Address.Create(customer.Id, request);
            Assert.IsFalse(createResult.IsSuccess());
            Assert.AreEqual(
                ValidationErrorCode.ADDRESS_COUNTRY_CODE_NUMERIC_IS_NOT_ACCEPTED,
                createResult.Errors.ForObject("Address").OnField("CountryCodeNumeric")[0].Code
            );
        }