182 lines
5.3 KiB
C#
182 lines
5.3 KiB
C#
using AyCode.Services.Loggers;
|
|
using System.Net.Http.Json;
|
|
using TIAM.Entities.Transfers;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using TIAMWebApp.Shared.Application.Utility;
|
|
using TIAM.Core.Loggers;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace TIAMWebApp.Shared.Application.Services
|
|
{
|
|
public class SumupService
|
|
{
|
|
private readonly HttpClient _http;
|
|
private readonly ILogger _logger;
|
|
|
|
public SumupService(HttpClient http, IEnumerable<IAcLogWriterClientBase> logWriters)
|
|
{
|
|
_http = http;
|
|
_logger = new LoggerClient<TransferDataService>(logWriters.ToArray());
|
|
}
|
|
|
|
|
|
public async Task<string> CreatePaymentAsync(Transfer transferToPay)
|
|
{
|
|
var url = $"{Setting.ApiBaseUrl}/{APIUrls.CreatePayment}";
|
|
//var url = $"{APIUrls.GetTransferDestinations}";
|
|
_logger.Info(url);
|
|
var response = await _http.PostAsJsonAsync(url, transferToPay);
|
|
|
|
if (response == null)
|
|
return "Not ok";
|
|
|
|
var result = await response.Content.ReadAsStringAsync();
|
|
var paymentLink = result;
|
|
return paymentLink;
|
|
}
|
|
|
|
public async Task<string> GetPaymentAsync(string paymentId)
|
|
{
|
|
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetPaymentById}/"+paymentId;
|
|
//var url = $"{APIUrls.GetTransferDestinations}";
|
|
_logger.Info(url);
|
|
var jsonResponse = await _http.GetStringAsync(url);
|
|
|
|
if (jsonResponse == null || jsonResponse == "error")
|
|
return "error";
|
|
else
|
|
{
|
|
var checkoutResponse = JsonSerializer.Deserialize<GetPaymentResponse>(jsonResponse);
|
|
return checkoutResponse.Status;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public class GetPaymentResponse
|
|
{
|
|
[JsonPropertyName("amount")]
|
|
public double Amount { get; set; }
|
|
|
|
[JsonPropertyName("checkout_reference")]
|
|
public string CheckoutReference { get; set; }
|
|
|
|
[JsonPropertyName("currency")]
|
|
public string Currency { get; set; }
|
|
|
|
[JsonPropertyName("customer_id")]
|
|
public string CustomerId { get; set; }
|
|
|
|
[JsonPropertyName("date")]
|
|
public DateTimeOffset Date { get; set; }
|
|
|
|
[JsonPropertyName("description")]
|
|
public string Description { get; set; }
|
|
|
|
[JsonPropertyName("id")]
|
|
public Guid Id { get; set; }
|
|
|
|
[JsonPropertyName("mandate")]
|
|
public Mandate Mandate { get; set; }
|
|
|
|
[JsonPropertyName("merchant_code")]
|
|
public string MerchantCode { get; set; }
|
|
|
|
[JsonPropertyName("pay_to_email")]
|
|
public string PayToEmail { get; set; }
|
|
|
|
[JsonPropertyName("return_url")]
|
|
public string ReturnUrl { get; set; }
|
|
|
|
[JsonPropertyName("status")]
|
|
public string Status { get; set; }
|
|
|
|
[JsonPropertyName("transactions")]
|
|
public Transaction[] Transactions { get; set; }
|
|
|
|
[JsonPropertyName("valid_until")]
|
|
public DateTime ValidUntil { get; set; }
|
|
|
|
[JsonPropertyName("merchant_name")]
|
|
public string MerchantName { get; set; }
|
|
|
|
[JsonPropertyName("payment_instrument")]
|
|
public PaymentInstrument PaymentInstrument { get; set; }
|
|
|
|
[JsonPropertyName("redirect_url")]
|
|
public string RedirectUrl { get; set; }
|
|
|
|
[JsonPropertyName("transaction_code")]
|
|
public string TransactionCode { get; set; }
|
|
|
|
[JsonPropertyName("transaction_id")]
|
|
public Guid TransactionId { get; set; }
|
|
}
|
|
|
|
public partial class Mandate
|
|
{
|
|
[JsonPropertyName("merchant_code")]
|
|
public string MerchantCode { get; set; }
|
|
|
|
[JsonPropertyName("status")]
|
|
public string Status { get; set; }
|
|
|
|
[JsonPropertyName("type")]
|
|
public string Type { get; set; }
|
|
}
|
|
|
|
public partial class PaymentInstrument
|
|
{
|
|
[JsonPropertyName("token")]
|
|
public Guid Token { get; set; }
|
|
}
|
|
|
|
public partial class Transaction
|
|
{
|
|
[JsonPropertyName("amount")]
|
|
public double Amount { get; set; }
|
|
|
|
[JsonPropertyName("currency")]
|
|
public string Currency { get; set; }
|
|
|
|
[JsonPropertyName("id")]
|
|
public Guid Id { get; set; }
|
|
|
|
[JsonPropertyName("installments_count")]
|
|
public string InstallmentsCount { get; set; }
|
|
|
|
[JsonPropertyName("payment_type")]
|
|
public string PaymentType { get; set; }
|
|
|
|
[JsonPropertyName("status")]
|
|
public string Status { get; set; }
|
|
|
|
[JsonPropertyName("timestamp")]
|
|
public DateTimeOffset Timestamp { get; set; }
|
|
|
|
[JsonPropertyName("transaction_code")]
|
|
public string TransactionCode { get; set; }
|
|
|
|
[JsonPropertyName("auth_code")]
|
|
public string AuthCode { get; set; }
|
|
|
|
[JsonPropertyName("entry_mode")]
|
|
public string EntryMode { get; set; }
|
|
|
|
[JsonPropertyName("internal_id")]
|
|
public long InternalId { get; set; }
|
|
|
|
[JsonPropertyName("merchant_code")]
|
|
public string MerchantCode { get; set; }
|
|
|
|
[JsonPropertyName("tip_amount")]
|
|
public long TipAmount { get; set; }
|
|
|
|
[JsonPropertyName("vat_amount")]
|
|
public long VatAmount { get; set; }
|
|
}
|
|
|
|
}
|