public void ValidateWithSuccess(CollectionModel collection, string responseData, JudoApiError errorType) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var collectionValidationResult = judo.Collections.Validate(collection).Result; Assert.NotNull(collectionValidationResult); Assert.IsFalse(collectionValidationResult.HasError); Assert.NotNull(collectionValidationResult.Response); Assert.AreEqual(errorType, collectionValidationResult.Response.ErrorType); }
public void RegisterCardWithError(CardPaymentModel registerCard, string responseData, JudoApiError errorType) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); IResult <ITransactionResult> paymentReceiptResult = null; // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull paymentReceiptResult = judo.RegisterCards.Create(registerCard).Result; // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull Assert.NotNull(paymentReceiptResult); Assert.IsTrue(paymentReceiptResult.HasError); Assert.IsNull(paymentReceiptResult.Response); Assert.IsNotNull(paymentReceiptResult.Error); Assert.AreEqual((int)errorType, paymentReceiptResult.Error.Code); }
public void GetThreeDsAuthorizationsWithSuccess(string md, string responseData) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentRequiresThreeD = judo.ThreeDs.GetThreeDAuthorization(md).Result; Assert.NotNull(paymentRequiresThreeD); Assert.IsFalse(paymentRequiresThreeD.HasError); Assert.NotNull(paymentRequiresThreeD.Response); Assert.AreEqual(paymentRequiresThreeD.Response.ReceiptId, "134567"); }
public void CollectionWithError(CollectionModel collections, string responseData, JudoApiError error) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.Collections.Create(collections).Result; Assert.NotNull(paymentReceiptResult); Assert.IsTrue(paymentReceiptResult.HasError); Assert.IsNull(paymentReceiptResult.Response); Assert.IsNotNull(paymentReceiptResult.Error); Assert.AreEqual((int)error, paymentReceiptResult.Error.Code); }
public void CompleteThreeDsFail(string receiptId, ThreeDResultModel threeDResult, string responseData) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.ThreeDs.Complete3DSecure(receiptId, threeDResult).Result; Assert.NotNull(paymentReceiptResult); Assert.IsTrue(paymentReceiptResult.HasError); }
public void ExtraHeadersAreSent(RefundModel refundModel, string responseData, string receiptId) { const string EXTRA_HEADER_NAME = "X-Extra-Request-Header"; var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Is <HttpRequestMessage>(r => r.Headers.Contains(EXTRA_HEADER_NAME))) .Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); refundModel.HttpHeaders.Add(EXTRA_HEADER_NAME, "some random value"); IResult <ITransactionResult> refundReceipt = judo.Refunds.Create(refundModel).Result; Assert.NotNull(refundReceipt); Assert.IsFalse(refundReceipt.HasError); Assert.NotNull(refundReceipt.Response); Assert.That(refundReceipt.Response.ReceiptId, Is.EqualTo(134567)); }
public void RefundWithSuccess(RefundModel refund, string responseData, string receiptId) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.Refunds.Create(refund).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.ReceiptId, Is.EqualTo(134567)); }
public void GetMerchantsResultsForSearchCriterias(KeyValuePair <string, string>[] queryExpected, MarketMerchantsTestSource.FunctionHolder getCall) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ resultCount : 1, pageSize : 1, offest : 0, sort : 'timeAscending', results : [ { partnerReference : 'abs234', merchantLegalName : 'merchant', accessGranted : '2012-07-19T14:30:00+09:30', lastTransaction : '2012-07-19T14:30:00+09:30', scopes : 'test scope', locations : [ { partnerReference : 'cbd230', tradingName : 'mertrade', judoId : '1235465' } ] } ] }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var results = getCall.Func(judo.Market.Merchants); Assert.IsNotNull(results); Assert.IsFalse(results.HasError); Assert.AreEqual(1, results.Response.ResultCount); Assert.AreEqual(1, results.Response.Results.Count()); // ReSharper disable PossibleNullReferenceException Assert.AreEqual(1, results.Response.Results.FirstOrDefault().Locations.Count()); Assert.AreEqual("1235465", results.Response.Results.FirstOrDefault().Locations.FirstOrDefault().JudoId); // ReSharper restore PossibleNullReferenceException }
public void GetByReciptIdRequiresReceiptId(string receiptId) { var httpClient = Substitute.For <IHttpClient>(); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var exception = Assert.Throws <ArgumentNullException>(() => judo.WebPayments.Transactions.GetByReceipt(receiptId)); Assert.That(exception.Message, Contains.Substring("receiptId")); }
public void GetTransationsForReceipt() { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ receiptId : '134567', type : 'Create', judoId : '12456', originalAmount : 20, amount : 20, netAmount : 20, cardDetails : { cardLastfour : '1345', endDate : '1214', cardToken : 'ASb345AE', cardType : 'VISA' }, currency : 'GBP', consumer : { consumerToken : 'B245SEB', yourConsumerReference : 'Consumer1' } }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); const string receiptId = "1245"; var paymentReceiptResult = judo.Transactions.Get(receiptId).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.AreEqual(paymentReceiptResult.Response.ReceiptId, "134567"); }
public void ExtraHeadersAreSent(PaymentModel payment, string responseData, string receiptId) { const string EXTRA_HEADER_NAME = "X-Extra-Request-Header"; var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Is <HttpRequestMessage>(r => r.Headers.Contains(EXTRA_HEADER_NAME))) .Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); IResult <ITransactionResult> paymentReceiptResult = null; payment.HttpHeaders.Add(EXTRA_HEADER_NAME, "some random value"); // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull if (payment is CardPaymentModel) { paymentReceiptResult = judo.Payments.Create((CardPaymentModel)payment).Result; } else if (payment is TokenPaymentModel) { paymentReceiptResult = judo.Payments.Create((TokenPaymentModel)payment).Result; } // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.ReceiptId, Is.EqualTo(134567)); }
public void PayWithFailedValidation(PaymentModel payment, string responseData, string receiptId) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); IResult <ITransactionResult> paymentReceiptResult = null; // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull if (payment is CardPaymentModel) { paymentReceiptResult = judo.Payments.Create((CardPaymentModel)payment).Result; } else if (payment is TokenPaymentModel) { paymentReceiptResult = judo.Payments.Create((TokenPaymentModel)payment).Result; } // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull Assert.NotNull(paymentReceiptResult); Assert.True(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Error); Assert.AreEqual(1, paymentReceiptResult.Error.ModelErrors.Count); // ReSharper disable once PossibleNullReferenceException Assert.AreEqual("JudoId", paymentReceiptResult.Error.ModelErrors.FirstOrDefault().FieldName); }
public void ValidateWithSuccess(PaymentModel payment, string responseData, JudoApiError errorType) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(responseData) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); IResult <JudoApiErrorModel> paymentValidateResult = null; // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull if (payment is CardPaymentModel) { paymentValidateResult = judo.Payments.Validate((CardPaymentModel)payment).Result; } else if (payment is TokenPaymentModel) { paymentValidateResult = judo.Payments.Validate((TokenPaymentModel)payment).Result; } // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull Assert.NotNull(paymentValidateResult); Assert.IsFalse(paymentValidateResult.HasError); Assert.NotNull(paymentValidateResult.Response); Assert.AreEqual(errorType, paymentValidateResult.Response.ErrorType); }
public void GetTransactionsByReceiptId() { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ amount : 10, cardAddress : { cardHolderName : 'Test User', line1 : 'Test Street', line2 : 'Test Street', line3 : 'Test Street', town : 'London', postCode : 'W31 4HS', country : 'England' }, clientIpAddress : '128.0.0.1', clientUserAgent : 'Chrome', companyName : 'Test', currency : 'GBP', expiryDate : '2012-07-19T14:30:00+09:30', judoId : '1254634', partnerRecId : '243532', partnerServiceFee : 10, paymentCancelUrl : 'http://test.com', paymentSuccessUrl : 'http://test.com', reference : '42421', status : 'Open', transactionType : 'SALE', yourConsumerReference : '4235325', yourPaymentReference : '42355', receipt: { receiptId : '134567', type : 'Create', judoId : '12456', originalAmount : 20, amount : 20, netAmount : 20, cardDetails : { cardLastfour : '1345', endDate : '1214', cardToken : 'ASb345AE', cardType : 'VISA' }, currency : 'GBP', consumer : { consumerToken : 'B245SEB', yourConsumerReference : 'Consumer1' } } }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); const string RECEIPT_ID = "1245"; var paymentReceiptResult = judo.WebPayments.Transactions.GetByReceipt(RECEIPT_ID).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.Status, Is.EqualTo(WebPaymentStatus.Open)); Assert.That(paymentReceiptResult.Response.Receipt.ReceiptId, Is.EqualTo(134567)); }
public ApplePayService(JudoPayApi judoAPI) { _judoAPI = judoAPI; _clientService = new ClientService(); }
public void GetMerchantsForSearchCriterias(KeyValuePair <string, string>[] queryExpected, MarketMerchantsTestSource.FunctionHolder getCall) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ resultCount : 1, pageSize : 1, offest : 0, sort : 'timeAscending', results : [ { partnerReference : 'abs234', merchantLegalName : 'merchant', accessGranted : '2012-07-19T14:30:00+09:30', lastTransaction : '2012-07-19T14:30:00+09:30', scopes : 'test scope', locations : [ { partnerReference : 'cbd230', tradingName : 'mertrade', judoId : '1235465' } ] } ] }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://judo.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); getCall.Func(judo.Market.Merchants); httpClient.Received().SendAsync(Arg.Any <HttpRequestMessage>()); var calls = httpClient.ReceivedCalls(); // ReSharper disable once PossibleNullReferenceException var request = calls.FirstOrDefault(call => call.GetMethodInfo().Name == "SendAsync"). GetArguments().FirstOrDefault() as HttpRequestMessage; Assert.IsNotNull(request); var numberOfMatchingParameters = request.RequestUri.Query .Remove(0, 1) .Split('&').Select(kv => { var keyValue = kv.Split('='); return(new KeyValuePair <string, string>(keyValue[0], keyValue[1])); }).Intersect(queryExpected).Count(); Assert.AreEqual(queryExpected.Count(), numberOfMatchingParameters); }
public void UpdatePreAuth() { var httpClient = Substitute.For <IHttpClient>(); var request = new WebPaymentRequestModel { Amount = 10, CardAddress = new WebPaymentCardAddress { CardHolderName = "Test User", Line1 = "Test Street", Line2 = "Test Street", Line3 = "Test Street", Town = "London", PostCode = "W31 4HS", Country = "England" }, ClientIpAddress = "127.0.0.1", CompanyName = "Test", Currency = "GBP", ExpiryDate = DateTimeOffset.Now, JudoId = "1254634", PartnerServiceFee = 10, PaymentCancelUrl = "http://test.com", PaymentSuccessUrl = "http://test.com", Reference = "42421", Status = WebPaymentStatus.Open, TransactionType = TransactionType.PAYMENT, YourConsumerReference = "4235325", Receipt = new PaymentReceiptModel { ReceiptId = 134567, Type = "Create", JudoId = 12456, OriginalAmount = 20, Amount = 20, NetAmount = 20, CardDetails = new CardDetails { CardLastfour = "1345", EndDate = "1214", CardToken = "ASb345AE", CardType = CardType.VISA }, Currency = "GBP", Consumer = new Consumer { ConsumerToken = "B245SEB", YourConsumerReference = "Consumer1" } } }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ amount : 10, cardAddress : { cardHolderName : 'Test User', line1 : 'Test Street', line2 : 'Test Street', line3 : 'Test Street', town : 'London', postCode : 'W31 4HS', country : 'England' }, clientIpAddress : '128.0.0.1', clientUserAgent : 'Chrome', companyName : 'Test', currency : 'GBP', expiryDate : '2012-07-19T14:30:00+09:30', judoId : '1254634', partnerRecId : '243532', partnerServiceFee : 10, paymentCancelUrl : 'http://test.com', paymentSuccessUrl : 'http://test.com', reference : '1342423', status : 'Open', transactionType : 'SALE', yourConsumerReference : '4235325', yourPaymentReference : '42355', receipt: { receiptId : '134567', type : 'Create', judoId : '12456', originalAmount : 20, amount : 20, netAmount : 20, cardDetails : { cardLastfour : '1345', endDate : '1214', cardToken : 'ASb345AE', cardType : 'VISA' }, currency : 'GBP', consumer : { consumerToken : 'B245SEB', yourConsumerReference : 'Consumer1' } }, response: { postUrl : 'http://test.com', reference : '1342423' } }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.WebPayments.PreAuths.Update(request).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.AreEqual("1342423", paymentReceiptResult.Response.Reference); Assert.AreEqual("1342423", paymentReceiptResult.Response.Response.Reference); Assert.NotNull(paymentReceiptResult.Response.Response.PostUrl); }
protected IntegrationTestsBase() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; JudoPayApi = JudoPaymentsFactory.Create(Configuration.JudoEnvironment, Configuration.Token, Configuration.Secret); JudoPayApiElevated = JudoPaymentsFactory.Create(Configuration.JudoEnvironment, Configuration.ElevatedPrivilegesToken, Configuration.ElevatedPrivilegesSecret); }
public void GetTransactionsForSearchCriterias(KeyValuePair <string, string>[] queryExpected, ConsumerTransactionsTestSource.FunctionHolder getCall) { var httpClient = Substitute.For <IHttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ receiptId : '134567', type : 'Create', judoId : '12456', originalAmount : 20, amount : 20, netAmount : 20, cardDetails : { cardLastfour : '1345', endDate : '1214', cardToken : 'ASb345AE', cardType : 'VISA' }, currency : 'GBP', consumer : { consumerToken : 'B245SEB', yourConsumerReference : 'Consumer1' } }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); getCall.Func(judo.Consumers); httpClient.Received().SendAsync(Arg.Any <HttpRequestMessage>()); var calls = httpClient.ReceivedCalls(); // ReSharper disable once PossibleNullReferenceException var request = calls.FirstOrDefault(call => call.GetMethodInfo().Name == "SendAsync"). GetArguments().FirstOrDefault() as HttpRequestMessage; Assert.IsNotNull(request); var numberOfMatchingParameters = request.RequestUri.Query .Remove(0, 1) .Split('&').Select(kv => { var keyValue = kv.Split('='); return(new KeyValuePair <string, string>(keyValue[0], keyValue[1])); }).Intersect(queryExpected).Count(); Assert.AreEqual(queryExpected.Count(), numberOfMatchingParameters); Assert.AreEqual("payments", request.RequestUri.AbsolutePath.Split('/').Last()); }
public void CreatePreAuth() { var httpClient = Substitute.For <IHttpClient>(); var request = new WebPaymentRequestModel { Amount = 10, CardAddress = new WebPaymentCardAddress { CardHolderName = "Test User", Line1 = "Test Street", Line2 = "Test Street", Line3 = "Test Street", Town = "London", PostCode = "W31 4HS", Country = "England" }, ClientIpAddress = "127.0.0.1", CompanyName = "Test", Currency = "GBP", ExpiryDate = DateTimeOffset.Now, JudoId = "1254634", PartnerServiceFee = 10, PaymentCancelUrl = "http://test.com", PaymentSuccessUrl = "http://test.com", Reference = "42421", Status = WebPaymentStatus.Open, TransactionType = TransactionType.PAYMENT, YourConsumerReference = "4235325", Receipt = new PaymentReceiptModel { ReceiptId = 134567, Type = "Create", JudoId = 12456, OriginalAmount = 20, Amount = 20, NetAmount = 20, CardDetails = new CardDetails { CardLastfour = "1345", EndDate = "1214", CardToken = "ASb345AE", CardType = CardType.VISA }, Currency = "GBP", Consumer = new Consumer { ConsumerToken = "B245SEB", YourConsumerReference = "Consumer1" } } }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ postUrl : 'http://test.com', reference : '1342423' }") }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var responseTask = new TaskCompletionSource <HttpResponseMessage>(); responseTask.SetResult(response); httpClient.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(responseTask.Task); var client = new Client(new Connection(httpClient, DotNetLoggerFactory.Create, "http://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.WebPayments.PreAuths.Create(request).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.AreEqual("1342423", paymentReceiptResult.Response.Reference); Assert.NotNull(paymentReceiptResult.Response.PostUrl); }
public PaymentService(JudoPayApi judoAPI) { _judoAPI = judoAPI; }