using System.Text.Json.Serialization; namespace HBank.Sdk; /// A payment (or a refund, Type == "refund"), as returns it. public sealed record Payment { [JsonPropertyName("id")] public string Id { get; init; } = ""; [JsonPropertyName("type")] public string Type { get; init; } = "payment"; [JsonPropertyName("amount")] public decimal Amount { get; init; } [JsonPropertyName("currency")] public string Currency { get; init; } = ""; /// pending, completed or aborted. [JsonPropertyName("status")] public string Status { get; init; } = ""; [JsonPropertyName("description")] public string? Description { get; init; } /// Set once the payment is completed. [JsonPropertyName("reference")] public string? Reference { get; init; } [JsonPropertyName("payment_code")] public string? PaymentCode { get; init; } [JsonPropertyName("refunded")] public decimal Refunded { get; init; } [JsonPropertyName("refundable")] public decimal Refundable { get; init; } [JsonPropertyName("refund_of")] public string? RefundOf { get; init; } [JsonPropertyName("subscription_id")] public string? SubscriptionId { get; init; } /// Every subscription this payment belongs to: the one it charged, or all those a checkout of several started. [JsonPropertyName("subscription_ids")] public IReadOnlyList SubscriptionIds { get; init; } = []; [JsonIgnore] public bool Completed => Status == "completed"; } /// A QR code for a pending payment: put in a QR code, or show the SVG at . public sealed record PaymentCode( [property: JsonPropertyName("code")] string Code, [property: JsonPropertyName("url")] string Url, [property: JsonPropertyName("qr_svg")] string QrSvg); public sealed record Refund { [JsonPropertyName("id")] public string Id { get; init; } = ""; [JsonPropertyName("amount")] public decimal Amount { get; init; } [JsonPropertyName("currency")] public string Currency { get; init; } = ""; [JsonPropertyName("reference")] public string Reference { get; init; } = ""; [JsonPropertyName("reason")] public string? Reason { get; init; } } /// The refund, and the refunded payment with updated Refunded / Refundable. public sealed record RefundResult( [property: JsonPropertyName("refund")] Refund Refund, [property: JsonPropertyName("transaction")] Payment Payment); public sealed record SubscriptionCustomer([property: JsonPropertyName("name")] string Name); public sealed record Subscription { [JsonPropertyName("id")] public string Id { get; init; } = ""; /// offered, active or canceled. [JsonPropertyName("status")] public string Status { get; init; } = ""; /// Within a period that's been paid for: give access while this is true. [JsonPropertyName("active_period")] public bool ActivePeriod { get; init; } [JsonPropertyName("amount")] public decimal Amount { get; init; } [JsonPropertyName("currency")] public string Currency { get; init; } = ""; /// day, week, month or year. [JsonPropertyName("interval")] public string Interval { get; init; } = ""; [JsonPropertyName("interval_count")] public int IntervalCount { get; init; } = 1; [JsonPropertyName("description")] public string? Description { get; init; } /// Send this to the customer. [JsonPropertyName("url")] public string Url { get; init; } = ""; [JsonPropertyName("qr_svg")] public string QrSvg { get; init; } = ""; [JsonPropertyName("subscribed_at")] public DateTimeOffset? SubscribedAt { get; init; } [JsonPropertyName("subscribed_for_days")] public int? SubscribedForDays { get; init; } [JsonPropertyName("subscribed_for_seconds")] public long? SubscribedForSeconds { get; init; } [JsonPropertyName("canceled")] public bool Canceled { get; init; } [JsonPropertyName("canceled_at")] public DateTimeOffset? CanceledAt { get; init; } /// customer, merchant, bank or schedule. [JsonPropertyName("canceled_by")] public string? CanceledBy { get; init; } [JsonPropertyName("current_period_start")] public DateTimeOffset? CurrentPeriodStart { get; init; } [JsonPropertyName("current_period_end")] public DateTimeOffset? CurrentPeriodEnd { get; init; } [JsonPropertyName("next_charge_at")] public DateTimeOffset? NextChargeAt { get; init; } [JsonPropertyName("ends_at")] public DateTimeOffset? EndsAt { get; init; } [JsonPropertyName("last_day")] public DateTimeOffset? LastDay { get; init; } [JsonPropertyName("charges")] public int Charges { get; init; } [JsonPropertyName("last_error")] public string? LastError { get; init; } [JsonPropertyName("customer")] public SubscriptionCustomer? Customer { get; init; } } /// The first payment of a subscription: hand to the pay button / hosted checkout. public sealed record SubscriptionCheckout( [property: JsonPropertyName("transaction_id")] string TransactionId, [property: JsonPropertyName("subscription")] Subscription Subscription); /// One first payment for several subscriptions: paying it starts all of (in your order). public sealed record SubscriptionsCheckout( [property: JsonPropertyName("transaction_id")] string TransactionId, [property: JsonPropertyName("subscriptions")] IReadOnlyList Subscriptions); /// One subscription in CreateSubscriptionsCheckoutAsync: one you already offered, or a new offer. public sealed record SubscriptionCheckoutItem { public string? SubscriptionId { get; private init; } public decimal Amount { get; private init; } public string Currency { get; private init; } = ""; public string Interval { get; private init; } = ""; public int IntervalCount { get; private init; } = 1; public string? Description { get; private init; } /// A subscription you already offered ("sub_…"). public static SubscriptionCheckoutItem Existing(string subscriptionId) => new() { SubscriptionId = subscriptionId }; /// A new offer, made with the checkout (same fields as CreateSubscriptionAsync). public static SubscriptionCheckoutItem New(decimal amount, string currency, string interval, int intervalCount = 1, string? description = null) => new() { Amount = amount, Currency = currency, Interval = interval, IntervalCount = intervalCount, Description = description }; public static implicit operator SubscriptionCheckoutItem(string subscriptionId) => Existing(subscriptionId); } /// Converts currency_from into currency_to. /// The other way. public sealed record Rate( [property: JsonPropertyName("to_rate")] decimal ToRate, [property: JsonPropertyName("from_rate")] decimal FromRate);