Exemple #1
0
        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);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        public void ASimplePaymentAndRefund()
        {
            var paymentWithCard = GetCardPaymentModel();
            var response = JudoPayApi.Payments.Create(paymentWithCard).Result;

            Assert.IsNotNull(response);
            Assert.IsFalse(response.HasError);
            Assert.AreEqual("Success", response.Response.Result);

            var refund = new RefundModel
            {
                Amount = 25,
                ReceiptId = response.Response.ReceiptId,

            };

            response = JudoPayApi.Refunds.Create(refund).Result;

            Assert.IsNotNull(response);
            Assert.IsFalse(response.HasError);

            var receipt = response.Response as PaymentReceiptModel;

            Assert.IsNotNull(receipt);

            Assert.AreEqual("Success", receipt.Result);
            Assert.AreEqual("Refund", receipt.Type);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void ARefundValidate()
        {
            var paymentWithCard = GetCardPaymentModel("432438862");

            var response = JudoPayApi.Payments.Create(paymentWithCard).Result;

            Assert.IsNotNull(response);
            Assert.IsFalse(response.HasError);
            Assert.AreEqual("Success", response.Response.Result);

            var refund = new RefundModel
            {
                Amount = 25,
                ReceiptId = response.Response.ReceiptId,

            };

            var validateResponse = JudoPayApi.Refunds.Validate(refund).Result;

            Assert.IsNotNull(validateResponse);
            Assert.IsFalse(validateResponse.HasError);
            Assert.AreEqual(JudoApiError.General_Error, validateResponse.Response.ErrorType);
        }
Exemple #6
0
        public Task<IResult<JudoApiErrorModel>> Validate(RefundModel refund)
        {
            var validationError = Validate<RefundModel, JudoApiErrorModel>(RefundValidator, refund);

            return validationError ?? PostInternal<RefundModel, JudoApiErrorModel>(_validateRefundAddress, refund);
        }
Exemple #7
0
        public void GetRefundsTransactions()
        {
            var paymentWithCard = GetCardPaymentModel("432438862");

            var paymentResponse = JudoPayApi.Payments.Create(paymentWithCard).Result;

            Assert.IsNotNull(paymentResponse);
            Assert.IsFalse(paymentResponse.HasError);
            Assert.AreEqual("Success", paymentResponse.Response.Result);

            var refund = new RefundModel
            {
                Amount = 25,
                ReceiptId = paymentResponse.Response.ReceiptId,

            };

            var response = JudoPayApi.Refunds.Create(refund).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.GetRefunds(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));
        }
Exemple #8
0
 public Task<IResult<ITransactionResult>> Create(RefundModel refund)
 {
     var validationError = Validate<RefundModel, ITransactionResult>(RefundValidator, refund);
     return validationError ?? PostInternal<RefundModel, ITransactionResult>(_createRefundsAddress, refund);
 }
		public async Task<IResult<ITransactionResult>> Refund(RefundModel refundModel)
		{
			Task<IResult<ITransactionResult>> task = _judoAPI.Refunds.Create(refundModel);
			return await task;
		}