// TODO: Exception handling public CreatePaymentResponse CreatePayment(CreatePaymentRequestBody createRequestBody) { IRestRequest request = CreateRequest("/payments/", Method.POST, createRequestBody); var response = _client.Execute(request); var responseContent = response.Content; 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 <CreatePaymentResponse>(response, out var responseData)) { return(responseData); } throw new Exception($"Signature mismatch"); }
private CreatePaymentRequestBody CreatePaymentRequest(IEnumerable <Item> items) { var total = CalculateTotal(items); var orderId = Guid.NewGuid().ToString(); var reference = Guid.NewGuid().ToString(); var stamp = Guid.NewGuid(); // TODO: Validation before really sending request CreatePaymentRequestBody paymentRequest = new CreatePaymentRequestBody() { OrderId = orderId, Stamp = stamp, Reference = reference, Amount = total, Currency = "EUR", Language = "EN", Customer = new Customer() { Email = "*****@*****.**", FirstName = "Tri", LastName = "Helen", Phone = "0401234123", VatId = string.Empty }, Items = items .Select(x => { x.Merchant = accountId; x.Reference = reference; x.Stamp = stamp; x.ProductCode = Guid.NewGuid().ToString(); // TODO: Item repository x.DeliveryDate = DateTimeOffset.Now.AddDays(10).ToCheckoutDateFormat(); return(x); }).ToArray(), DeliveryAddress = new Address() { City = "Helsinki", Country = "FI", StreetAddress = "Something else 2", PostalCode = "01300", County = string.Empty }, // What is call back , what is redirect // TODO: Url/callback cannot be an IP address :( CallbackUrls = new CallbackUrl() { Success = "https://something.com/api/checkout/success", Cancel = "https://something.com/api/checkout/cancel" }, RedirectUrls = new CallbackUrl() { Success = "https://something.com/checkout-success", Cancel = "https://something.com/checkout-cancel" }, InvoicingAddress = new Address() { City = "Helsinki", Country = "FI", StreetAddress = "Something 2", PostalCode = "01300", County = string.Empty }, }; return(paymentRequest); }
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"); }