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 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); }
void PopulateSessionModel(PaymentModel sessionModel, PaymentModel paymentModel) { sessionModel.JudoId = (string.IsNullOrWhiteSpace(paymentModel.JudoId) ? _judo.JudoId : paymentModel.JudoId); sessionModel.YourConsumerReference = (string.IsNullOrWhiteSpace(paymentModel.YourConsumerReference) ? ("Consumer:" + _judo.JudoId) : paymentModel.YourConsumerReference); sessionModel.Amount = paymentModel.Amount; sessionModel.ClientDetails = clientService.GetClientDetails(); }