public void ThrowsWhenGivenInvalidEnvironment() { var config = new LatitudePayClientConfiguration() { ApiKey = "MockKey", ApiSecret = "MockSecret", Environment = (LatitudePayEnvironment)100, HttpClient = new System.Net.Http.HttpClient(new MockLatitudePayHttpHandler()) }; using (var x = new LatitudePayClient(config)) { }; }
public void Config_ThrowsOnMinimumRetriesSetWhenLocked() { var config = new LatitudePayClientConfiguration() { ApiKey = "Test", ApiSecret = "Test" }; config.MinimumRetries = 3; Assert.AreEqual(3, config.MinimumRetries); using (var client = new LatitudePayClient(config)) { Assert.ThrowsException <InvalidOperationException>(() => config.MinimumRetries = 4); } }
public void Config_ThrowsOnProductVendorSetWhenLocked() { var config = new LatitudePayClientConfiguration() { ApiKey = "Test", ApiSecret = "Test" }; config.ProductVendor = "Test Vendor"; Assert.AreEqual("Test Vendor", config.ProductVendor); using (var client = new LatitudePayClient(config)) { Assert.ThrowsException <InvalidOperationException>(() => config.ProductVendor = "Alternate Test Vendor"); } }
public void Config_ThrowsOnProductVersionSetWhenLocked() { var config = new LatitudePayClientConfiguration() { ApiKey = "Test", ApiSecret = "Test" }; config.ProductVersion = "1.0"; Assert.AreEqual("1.0", config.ProductVersion); using (var client = new LatitudePayClient(config)) { Assert.ThrowsException <InvalidOperationException>(() => config.ProductVersion = "1.1"); } }
public void Config_ThrowsOnRetryDelaySecondsSetWhenLocked() { var config = new LatitudePayClientConfiguration() { ApiKey = "Test", ApiSecret = "Test" }; config.RetryDelaySeconds = 10; Assert.AreEqual(10, config.RetryDelaySeconds); using (var client = new LatitudePayClient(config)) { Assert.ThrowsException <InvalidOperationException>(() => config.RetryDelaySeconds = 20); } }
public void Config_ThrowsOnHttpClientSetWhenLocked() { var config = new LatitudePayClientConfiguration() { ApiKey = "Test", ApiSecret = "Test" }; var hc = new System.Net.Http.HttpClient(); config.HttpClient = hc; Assert.AreEqual(hc, config.HttpClient); using (var client = new LatitudePayClient(config)) { Assert.ThrowsException <InvalidOperationException>(() => config.HttpClient = new System.Net.Http.HttpClient()); } }
public async Task ThrowsUnauthorisedException_ForAuthorisationFailure() { var config = new LatitudePayClientConfiguration() { ApiKey = "InvalidKey", ApiSecret = "InvalidSecret", Environment = LatitudePayEnvironment.Uat }; using (var client = new LatitudePayClient(config)) { var request = new LatitudePayCreatePosPurchaseRequest() { Reference = System.Guid.NewGuid().ToString(), BillingAddress = new LatitudePayAddress() { AddressLine1 = "124 Fifth Avenue", Suburb = "Auckland", CityTown = "Auckland", State = "Auckland", Postcode = "1010", CountryCode = "NZ" }, ShippingAddress = new LatitudePayAddress() { AddressLine1 = "124 Fifth Avenue", Suburb = "Auckland", CityTown = "Auckland", State = "Auckland", Postcode = "1010", CountryCode = "NZ" }, Customer = new LatitudePayCustomer() { Address = new LatitudePayAddress() { AddressLine1 = "124 Fifth Avenue", Suburb = "Auckland", CityTown = "Auckland", State = "Auckland", Postcode = "1010", CountryCode = "NZ" }, FirstName = "John", Surname = "Doe", MobileNumber = Environment.GetEnvironmentVariable("LatitudePay_TestMobileNumber") }, Products = new List <LatitudePayProduct>() { new LatitudePayProduct() { Name = "Tennis Ball Multipack", Price = new LatitudePayMoney(30, "NZD"), Sku = "abc123", Quantity = 1, TaxIncluded = true } }, ShippingLines = new List <LatitiudePayShippingLine>() { new LatitiudePayShippingLine() { Carrier = "NZ Post", Price = new LatitudePayMoney(5.5M, "NZD") } }, TaxAmount = new LatitudePayMoney(5.325M, "NZD"), TotalAmount = new LatitudePayMoney(35.5M, "NZD"), ReturnUrls = new LatitudePayReturnUrls() { SuccessUrl = new Uri("http://genoapay.com/success"), FailUrl = new Uri("http://genoapay.com/fail"), CallbackUrl = new Uri("http://genoapay.com/fail-safe-callback") } }; request.IdempotencyKey = request.Reference; var purchaseResponse = await client.CreatePosPurchaseAsync(request); Assert.IsNotNull(purchaseResponse); Assert.IsFalse(String.IsNullOrWhiteSpace(purchaseResponse.Token)); Assert.IsNotNull(purchaseResponse.StatusUrl); //Wait until payment enters final status var statusRequest = new LatitudePayPurchaseStatusRequest() { PaymentPlanToken = purchaseResponse.Token }; var finalStatus = false; LatitudePayPurchaseStatusResponse paymentStatus = null; while (!finalStatus) { await Task.Delay(5000).ConfigureAwait(false); paymentStatus = await client.GetPurchaseStatusAsync(statusRequest).ConfigureAwait(false); finalStatus = !String.Equals(paymentStatus.Status, LatitudePayConstants.StatusPending, StringComparison.OrdinalIgnoreCase); } Assert.AreEqual(LatitudePayConstants.StatusApproved, paymentStatus.Status); Assert.IsFalse(String.IsNullOrEmpty(paymentStatus.Token)); Assert.IsFalse(String.IsNullOrEmpty(paymentStatus.Message)); } }