public RefundResponse CreateRefund(Guid transactionId, MerchantRefundRequestBody refundRequest)
        {
            // todo: Create transaction request
            if (transactionId == null || transactionId == Guid.Empty)
            {
                throw new Exception("Invalid transactionId provided");
            }

            var extraHeader = new Dictionary <string, string>()
            {
                { CheckoutRequestHeaders.TransactionId, transactionId.ToString() }
            };

            IRestRequest request = CreateRequest(RequestTemplateUrls.RefundPayment, Method.POST, refundRequest, extraHeader)
                                   .AddParameter("transactionId", transactionId, ParameterType.UrlSegment);
            // End of create transaction request

            var response        = _client.Execute(request);
            var responseContent = response.Content;

            // If not 201 , then throw something
            if (!response.IsSuccessful)
            {
                var errorResponse = SerializationUtils.DeserializeResponse <CheckoutError>(responseContent);
                throw new Exception($" {errorResponse.Message} - {RequestIdHeader}:{response.Headers.SingleOrDefault(x => x.Name.Equals(RequestIdHeader))?.Value}");
            }

            if (TryGetValidatedResponse <RefundResponse>(response, out var responseData))
            {
                return(responseData);
            }
            throw new Exception($"{nameof(CreateRefund)} : Response not validated due to signature mismatch");
        }
Exemple #2
0
        public void CanCreatePayment()
        {
            var clientUnderTest = new CheckoutFinlandClient(testAccount, testSecretKey);

            var orderId   = Guid.NewGuid().ToString();
            var reference = Guid.NewGuid().ToString();
            var stamp     = Guid.NewGuid();

            var itemList = new List <Item>()
            {
                new Item()
                {
                    Units = 1, UnitPrice = 100, VatPercentage = 24, ProductCode = Guid.NewGuid().ToString(), DeliveryDate = DateTimeOffset.Now.AddDays(10).ToCheckoutDateFormat(),

                    //OrderId = orderId,
                    Stamp = stamp, Reference = reference, Merchant = testAccount, Description = "tEST", Category = "Test"
                }
            };

            CreatePaymentRequestBody requestBody = new CreatePaymentRequestBody()
            {
                OrderId   = orderId,
                Stamp     = stamp,
                Reference = reference,
                Amount    = 100,
                Currency  = Currencies.Euro,
                Language  = Languages.English,
                Customer  = new Customer()
                {
                    Email     = "*****@*****.**",
                    FirstName = "Tri",
                    LastName  = "Helen",
                    Phone     = "0401234123",
                    VatId     = string.Empty
                },
                Items           = itemList.ToArray(),
                DeliveryAddress = new Address()
                {
                    City          = "Helsinki",
                    Country       = "FI",
                    StreetAddress = "Atomi 2",
                    PostalCode    = "01300",
                    County        = string.Empty
                },
                // Should there be any transaction ID associated here ?
                CallbackUrls = new CallbackUrl()
                {
                    Success = "https://something.com/success/",
                    Cancel  = "https://something.com/cancel/"
                },
                RedirectUrls = new CallbackUrl()
                {
                    Success = "https://something.com/success/",
                    Cancel  = "https://something.com/cancel/"
                },
                InvoicingAddress = new Address()
                {
                    City          = "Helsinki",
                    Country       = "FI",
                    StreetAddress = "Atomi 2",
                    PostalCode    = "01300",
                    County        = string.Empty
                },
            };

            // TODO : stringId as param
            var paymentResponse = clientUnderTest.CreatePayment(requestBody);

            paymentResponse.Should().NotBeNull();
            paymentResponse.Href.Should().NotBeNullOrEmpty();
            paymentResponse.TransactionId.Should().NotBeEmpty();
            paymentResponse.Providers.Length.Should().BeGreaterThan(0);

            var paymentInformation = clientUnderTest.GetTransactionInformation(paymentResponse.TransactionId);

            paymentInformation.Should().NotBeNull();
            paymentInformation.Id.Should().NotBeEmpty();

            var refundRequest = new MerchantRefundRequestBody()
            {
                Amount       = 100,
                CallbackUrls = new CallbackUrl()
                {
                    Success = "https://something.com/success/",
                    Cancel  = "https://something.com/cancel/"
                },
                Items = new List <Item>()
            };

            // TODO: Pay the damn transaction

            //var refund = clientUnderTest.CreateRefund(paymentResponse.TransactionId, refundRequest);
            //refund.TransactionId.Should().Be(paymentResponse.TransactionId);
            //refund.Status.Should().Be("0");
        }