| 1 | /** |
| 2 | * Amounts are decimals in the currency's major unit (24.9 = 24.90 EUR). Pass a string ("24.90") for exact values; |
| 3 | * the SDK sends all amounts as strings, which the API accepts. |
| 4 | */ |
| 5 | export type Amount = number | string; |
| 6 | |
| 7 | export type PaymentStatus = "pending" | "completed" | "aborted"; |
| 8 | export type SubscriptionStatus = "offered" | "active" | "canceled"; |
| 9 | export type Interval = "day" | "week" | "month" | "year"; |
| 10 | |
| 11 | /** A payment (or a refund, `type: "refund"`), as `getPayment` returns it. */ |
| 12 | export interface Payment { |
| 13 | /** A random string like "tx_8fK2mQ7xRb4Tn9WcYz3LpH6v", not a number. */ |
| 14 | id: string; |
| 15 | type: "payment" | "refund" | (string & {}); |
| 16 | amount: number; |
| 17 | currency: string; |
| 18 | status: PaymentStatus | (string & {}); |
| 19 | description: string; |
| 20 | /** Set once the payment is completed. */ |
| 21 | reference: string | null; |
| 22 | /** Set once a QR code was issued. */ |
| 23 | payment_code: string | null; |
| 24 | refunded: number; |
| 25 | refundable: number; |
| 26 | refund_of: string | null; |
| 27 | subscription_id: string | null; |
| 28 | /** Every subscription this payment belongs to: the one it charged, or all those a checkout of several started. */ |
| 29 | subscription_ids: string[]; |
| 30 | } |
| 31 | |
| 32 | /** A QR code for a pending payment: put `url` in a QR code, or show the ready-made SVG at `qr_svg`. */ |
| 33 | export interface PaymentCode { |
| 34 | code: string; |
| 35 | url: string; |
| 36 | qr_svg: string; |
| 37 | } |
| 38 | |
| 39 | export interface Refund { |
| 40 | id: string; |
| 41 | amount: number; |
| 42 | currency: string; |
| 43 | reference: string; |
| 44 | reason: string | null; |
| 45 | } |
| 46 | |
| 47 | export interface RefundResult { |
| 48 | refund: Refund; |
| 49 | /** The refunded payment, with updated `refunded` / `refundable`. */ |
| 50 | transaction: Payment; |
| 51 | } |
| 52 | |
| 53 | /** Timestamps are ISO 8601 strings in UTC. */ |
| 54 | export interface Subscription { |
| 55 | /** A random string like "sub_8fK2mQ7xRb4Tn9WcYz3LpH6v", not a number. */ |
| 56 | id: string; |
| 57 | status: SubscriptionStatus | (string & {}); |
| 58 | /** Within a period that's been paid for: give access while this is true. */ |
| 59 | active_period: boolean; |
| 60 | amount: number; |
| 61 | currency: string; |
| 62 | interval: Interval | (string & {}); |
| 63 | interval_count: number; |
| 64 | description: string | null; |
| 65 | /** Send this to the customer. */ |
| 66 | url: string; |
| 67 | qr_svg: string; |
| 68 | subscribed_at: string | null; |
| 69 | subscribed_for_days: number | null; |
| 70 | subscribed_for_seconds: number | null; |
| 71 | canceled: boolean; |
| 72 | canceled_at: string | null; |
| 73 | canceled_by: "customer" | "merchant" | "bank" | "schedule" | (string & {}) | null; |
| 74 | current_period_start: string | null; |
| 75 | current_period_end: string | null; |
| 76 | next_charge_at: string | null; |
| 77 | ends_at: string | null; |
| 78 | last_day: string | null; |
| 79 | charges: number; |
| 80 | last_error: string | null; |
| 81 | customer: { name: string } | null; |
| 82 | } |
| 83 | |
| 84 | /** The first payment of a subscription: hand `transaction_id` to the pay button / hosted checkout. */ |
| 85 | export interface SubscriptionCheckout { |
| 86 | transaction_id: string; |
| 87 | subscription: Subscription; |
| 88 | } |
| 89 | |
| 90 | /** One first payment for several subscriptions: paying `transaction_id` starts all of `subscriptions` (in your order). */ |
| 91 | export interface SubscriptionsCheckout { |
| 92 | transaction_id: string; |
| 93 | subscriptions: Subscription[]; |
| 94 | } |
| 95 | |
| 96 | export interface Rate { |
| 97 | /** Converts `currency_from` into `currency_to`. */ |
| 98 | to_rate: number; |
| 99 | /** The other way. */ |
| 100 | from_rate: number; |
| 101 | } |
| 102 | |
| 103 | export interface CreatePaymentParams { |
| 104 | amount: Amount; |
| 105 | /** ISO code, e.g. "EUR". */ |
| 106 | currency: string; |
| 107 | /** Shown to the customer when they pay, and in their history. */ |
| 108 | description?: string; |
| 109 | /** Where HBank asks you to approve the payment. Required for the hosted checkout. */ |
| 110 | callback_url?: string; |
| 111 | } |
| 112 | |
| 113 | export interface RefundParams { |
| 114 | /** In the payment's currency. Left out: everything that's left. */ |
| 115 | amount?: Amount; |
| 116 | /** Up to 200 characters, shown to the customer. */ |
| 117 | reason?: string; |
| 118 | } |
| 119 | |
| 120 | export interface CreateSubscriptionParams { |
| 121 | amount: Amount; |
| 122 | currency: string; |
| 123 | interval: Interval; |
| 124 | /** Every how many intervals, 1 to 120. Default 1. */ |
| 125 | interval_count?: number; |
| 126 | /** Up to 200 characters, shown to the customer. */ |
| 127 | description?: string; |
| 128 | } |
| 129 | |
| 130 | export interface SubscriptionCheckoutParams extends CreateSubscriptionParams { |
| 131 | callback_url?: string; |
| 132 | } |
| 133 | |
| 134 | export interface SubscriptionsCheckoutParams { |
| 135 | /** Up to 20, in one currency: the id of a subscription you offered ("sub_…") or a new offer's fields. */ |
| 136 | subscriptions: (string | CreateSubscriptionParams)[]; |
| 137 | /** What the payment is for. Default: the subscriptions' descriptions. */ |
| 138 | description?: string; |
| 139 | callback_url?: string; |
| 140 | } |