public void ExtraHeadersAreSent(CollectionModel collection, 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); collection.HttpHeaders.Add(EXTRA_HEADER_NAME, "some random value"); IResult<ITransactionResult> refundReceipt = judo.Collections.Create(collection).Result; Assert.NotNull(refundReceipt); Assert.IsFalse(refundReceipt.HasError); Assert.NotNull(refundReceipt.Response); Assert.That(refundReceipt.Response.ReceiptId, Is.EqualTo(134567)); }
public void AFailedSimplePreAuthAndValidateCollection() { var paymentWithCard = GetCardPaymentModel("432438862"); var response = JudoPayApi.PreAuths.Create(paymentWithCard).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); var receipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("PreAuth", receipt.Type); var collection = new CollectionModel { Amount = 1, ReceiptId = response.Response.ReceiptId, }; var test = JudoPayApi.Collections.Create(collection).Result; collection.Amount = 30; var validateResponse = JudoPayApi.Collections.Validate(collection).Result; Assert.IsNotNull(validateResponse); Assert.IsTrue(validateResponse.HasError); Assert.True(string.Equals("Sorry, but the amount you're trying to collect is greater than the pre-auth", validateResponse.Error.Message)); Assert.True(46==validateResponse.Error.Code); }
public void CollectionWithSuccess(CollectionModel collections, 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.Collections.Create(collections).Result; Assert.NotNull(paymentReceiptResult); Assert.IsFalse(paymentReceiptResult.HasError); Assert.NotNull(paymentReceiptResult.Response); Assert.That(paymentReceiptResult.Response.ReceiptId, Is.EqualTo(134567)); }
public void GetCollectionsTransactions() { var paymentWithCard = GetCardPaymentModel("432438862"); var response = JudoPayApi.PreAuths.Create(paymentWithCard).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); Assert.AreEqual("Success", response.Response.Result); var collection = new CollectionModel { Amount = 25, ReceiptId = response.Response.ReceiptId, }; response = JudoPayApi.Collections.Create(collection).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); Assert.AreEqual("Success", response.Response.Result); var paymentReceipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(paymentReceipt); var transactions = JudoPayApi.Consumers.GetCollections(paymentReceipt.Consumer.ConsumerToken).Result; Assert.IsNotNull(transactions); Assert.IsFalse(transactions.HasError); Assert.IsNotEmpty(transactions.Response.Results); // ReSharper disable once PossibleNullReferenceException Assert.AreEqual(Configuration.Judoid, transactions.Response.Results.FirstOrDefault().JudoId.ToString(CultureInfo.InvariantCulture)); // ReSharper disable once PossibleNullReferenceException Assert.IsTrue(transactions.Response.Results.Any(t => t.ReceiptId == response.Response.ReceiptId)); }
public void ASimplePreAuthAndCollection() { var paymentWithCard = GetCardPaymentModel(); var response = JudoPayApi.PreAuths.Create(paymentWithCard).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); var receipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("PreAuth", receipt.Type); var collection = new CollectionModel { Amount = 25, ReceiptId = response.Response.ReceiptId, }; response = JudoPayApi.Collections.Create(collection).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); receipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("Collection", receipt.Type); }
public void ASimplePreAuthAndValidateCollection() { var paymentWithCard = GetCardPaymentModel("432438862"); var response = JudoPayApi.PreAuths.Create(paymentWithCard).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); var receipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("PreAuth", receipt.Type); var collection = new CollectionModel { Amount = 25, ReceiptId = response.Response.ReceiptId, }; var validateResponse = JudoPayApi.Collections.Validate(collection).Result; Assert.IsNotNull(validateResponse); Assert.IsFalse(validateResponse.HasError); Assert.AreEqual(JudoApiError.General_Error, validateResponse.Response.ErrorType); }
public void APreAuthTwoCollectionsAndTwoRefunds() { var paymentWithCard = GetCardPaymentModel("432438862"); var preAuthResponse = JudoPayApi.PreAuths.Create(paymentWithCard).Result; Assert.IsNotNull(preAuthResponse); Assert.IsFalse(preAuthResponse.HasError); Assert.AreEqual("Success", preAuthResponse.Response.Result); var collection = new CollectionModel { Amount = 24, ReceiptId = preAuthResponse.Response.ReceiptId, }; var collection1Response = JudoPayApi.Collections.Create(collection).Result; Assert.IsNotNull(collection1Response); Assert.IsFalse(collection1Response.HasError); var receipt = collection1Response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("Collection", receipt.Type); collection = new CollectionModel { Amount = 1, ReceiptId = preAuthResponse.Response.ReceiptId, }; var collection2Response = JudoPayApi.Collections.Create(collection).Result; Assert.IsNotNull(collection2Response); Assert.IsFalse(collection2Response.HasError); receipt = collection2Response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("Collection", receipt.Type); var refund = new RefundModel { Amount = 24, ReceiptId = collection1Response.Response.ReceiptId, }; var response = JudoPayApi.Refunds.Create(refund).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); receipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("Refund", receipt.Type); refund = new RefundModel { Amount = 1, ReceiptId = collection2Response.Response.ReceiptId, }; response = JudoPayApi.Refunds.Create(refund).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); receipt = response.Response as PaymentReceiptModel; Assert.IsNotNull(receipt); Assert.AreEqual("Success", receipt.Result); Assert.AreEqual("Refund", receipt.Type); }
public void ValidateWithoutSuccess(CollectionModel collection, 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); var collectionValidationResult = judo.Collections.Validate(collection).Result; Assert.NotNull(collectionValidationResult); Assert.IsTrue(collectionValidationResult.HasError); Assert.IsNull(collectionValidationResult.Response); Assert.IsNotNull(collectionValidationResult.Error); Assert.AreEqual((int)errorType, collectionValidationResult.Error.Code); }
public Task<IResult<ITransactionResult>> Create(CollectionModel collection) { var validationError = Validate<CollectionModel, ITransactionResult>(CollectionValidator, collection); return validationError ?? PostInternal<CollectionModel, ITransactionResult>(_createAddress, collection); }
public async Task<IResult<ITransactionResult>> Collection(CollectionModel collectionModel) { Task<IResult<ITransactionResult>> task = _judoAPI.Collections.Create(collectionModel); return await task; }
public void GetTransactionAfterPreAuthAndTwoCollections() { var paymentWithCard = GetCardPaymentModel(); var response = JudoPayApi.PreAuths.Create(paymentWithCard).Result; Assert.IsNotNull(response); Assert.IsFalse(response.HasError); Assert.AreEqual("Success", response.Response.Result); var collection = new CollectionModel() { Amount = 5, ReceiptId = response.Response.ReceiptId }; var collectionResult = JudoPayApi.Collections.Create(collection).Result; collectionResult = JudoPayApi.Collections.Create(collection).Result; var transaction = JudoPayApi.Transactions.Get(response.Response.ReceiptId).Result; var payment = transaction.Response as PaymentReceiptModel; Assert.IsNotNull(transaction); Assert.IsFalse(transaction.HasError); Assert.AreEqual("Success", transaction.Response.Result); Assert.AreEqual(response.Response.ReceiptId, transaction.Response.ReceiptId); Assert.AreEqual(10, payment.AmountCollected); }
public Task<IResult<JudoApiErrorModel>> Validate(CollectionModel collection) { var validationError = Validate<CollectionModel, JudoApiErrorModel>(CollectionValidator, collection); return validationError ?? PostInternal<CollectionModel, JudoApiErrorModel>(_validateAddress, collection); }