public void RefundWithError(RefundModel refund, 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.Refunds.Create(refund).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 PayWithError(PaymentModel payment, 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 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.IsTrue(paymentReceiptResult.HasError); Assert.IsNull(paymentReceiptResult.Response); Assert.IsNotNull(paymentReceiptResult.Error); Assert.AreEqual((int)errorType, paymentReceiptResult.Error.Code); }
public void CompleteThreeDsWithSuccess(long receiptId, ThreeDResultModel threeDResult, 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://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.ThreeDs.Complete3DSecure(receiptId, threeDResult).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.ReceiptId, Is.EqualTo(134567)); Assert.That(paymentReceiptResult.Response.ThreeDSecure.Result, Is.EqualTo("done")); }
public void ExtraHeadersAreSent(CardPaymentModel 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); payment.HttpHeaders.Add(EXTRA_HEADER_NAME, "some random value"); IResult<ITransactionResult> paymentReceiptResult = judo.Payments.Create(payment).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.ReceiptId, Is.EqualTo(134567)); }
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 PaymentService(JudoPayApi judoAPI, Judo judo) { _judoAPI = judoAPI; _judo = judo; clientService = DependencyService.Get<IClientService>(); CycleSession(); }
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 GetThreeDsAuthorizationsFail(string md, 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://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); var paymentReceiptResult = judo.ThreeDs.GetThreeDAuthorization(md).Result; Assert.NotNull(paymentReceiptResult); Assert.IsTrue(paymentReceiptResult.HasError); }
public void RegisterCardWithSuccess(CardPaymentModel registerCard, 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 paymentReceiptResult = judo.RegisterCards.Create(registerCard).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 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://something.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 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 void CreatePayment() { 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" } } }; const string EXTRA_HEADER_NAME = "ExtraHeader"; request.HttpHeaders.Add(EXTRA_HEADER_NAME, "ExtraHeaderValue"); 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.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); var paymentReceiptResult = judo.WebPayments.Payments.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); }
protected IntegrationTestsBase() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; JudoPayApi = JudoPaymentsFactory.Create(Configuration.JudoEnvironment, Configuration.Token, Configuration.Secret); JudoPayApiElevated = JudoPaymentsFactory.Create(Configuration.JudoEnvironment, Configuration.ElevatedPrivilegesToken, Configuration.ElevatedPrivilegesSecret); }
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://something.com")); var judo = new JudoPayApi(DotNetLoggerFactory.Create, client); const long receiptId = 1245; var paymentReceiptResult = judo.Transactions.Get(receiptId).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.ReceiptId, Is.EqualTo(134567)); }
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); }