import Client from '../base'; import { TransactionState, Language, TransactionSource, State, PaymentProvider, CardBrand, CardBrandLabel, TransactionType, SearchResponse, ExternalTransactionState, ResourceType, ExternalPayoutState } from './../shared'; interface BillingAddress { line1: string; line2?: string; postcode: string; city: string; country: string; } interface RefundSummary { status: string; user_external_id?: string; amount_available: number; amount_submitted: number; amount_refunded: number; } interface SettlementSummary { capture_submit_time?: string; captured_date?: string; } interface CardDetails { cardholder_name: string; billing_address?: BillingAddress; card_brand: CardBrandLabel; last_digits_card_number: string; first_digits_card_number: string; } interface Transaction { transaction_id: string; reference: string; gateway_account_id: string; amount: number; created_date: string; state: State; transaction_type: TransactionType; parent_transaction_id?: string; } interface Payment extends Transaction { description: string; language: Language; source: TransactionSource; return_url: string; payment_provider: PaymentProvider; refund_summary: RefundSummary; settlement_summary: SettlementSummary; live: boolean; moto?: boolean; delayed_capture?: boolean; card_details?: CardDetails; email?: string; total_amount?: number; fee?: number; net_amount?: number; } interface Refund extends Transaction { /** External user ID of the user that requested the refund */ refunded_by?: string; refunded_by_user_email?: string; gateway_payout_id?: string; } interface PaymentCountByStateReport { timedout: number; submitted: number; declined: number; created: number; success: number; cancelled: number; started: number; error: number; undefined: number; capturable: number; } interface ReportCountEntry { count: number; gross_amount: number; } interface TransactionSummaryReport { payments: ReportCountEntry; moto_payments: ReportCountEntry; refunds: ReportCountEntry; net_income: number; } interface TransactionsByHourSegment { timestamp: string; all_payments: number; errored_payments: number; completed_payments: number; amount: number; net_amount: number; total_amount: number; fee: number; } declare type TransactionsByHourReport = TransactionsByHourSegment[]; interface PerformanceReport { total_volume: number; total_amount: number; average_amount: number; } interface GatewayPerformanceReportEntry { gateway_account_id: number; total_volume: number; average_amount: number; minimum_amount: number; maximum_amount: number; month: number; year: number; } interface Event { amount: number; state: State; resource_type: ResourceType; event_type: string; timestamp: string; data: { [key: string]: string; }; } interface EventTicker { resource_type: ResourceType; resource_external_id: string; event_date: string; event_type: string; transaction_type: TransactionType; payment_provider: PaymentProvider; gateway_account_id: string; amount: number; card_brand?: CardBrand; } interface Payout { amount: number; created_date: string; gateway_payout_id: string; gateway_account_id: string; state: State; paid_out_date?: string; } declare type GatewayPerformanceReport = GatewayPerformanceReportEntry[]; export default class Ledger extends Client { constructor(baseUrl: string); payments: { /** * @param id - GOV.UK Pay transaction external ID * @param params - optionally specify gateway account ID or override requirement */ retrieve(id: string, params: RetrieveTransactionForAccountRequest | RetrieveTransactionWithAccountOverrideRequest): Promise; list(filters: ListTransactionForAccountRequest | ListTransactionRequestWithAccountOverrideRequest): Promise | undefined>; /** * @param id - GOV.UK Pay transaction external ID * @param params - specify gateway account ID */ listRefunds(id: string, params: ListPaymentRefundsRequest): Promise; }; refunds: { /** * @param id - GOV.UK Pay transaction external ID * @param params - optionally specify gateway account ID or override requirement */ retrieve(id: string, params: RetrieveTransactionForAccountRequest | RetrieveTransactionWithAccountOverrideRequest): Promise; list(filters: ListTransactionForAccountRequest | ListTransactionRequestWithAccountOverrideRequest): Promise | undefined>; }; transactions: { /** * @param id - GOV.UK Pay transaction external ID * @param params - optionally specify gateway account ID or override requirement * @returns - List of events for this transaction and transaction with this * transaction set as their parent transaction */ listEvents(id: string, params: ListTransactionEventsRequest): Promise; }; events: { /** * List ticker entries for events on any live transaction * @param params */ listTicker(params: ListEventTickerRequest): Promise; }; reports: { retrievePaymentSummaryByState(params: PaymentsByStateWithAccountOverrideRequest | PaymentsByStateForAccountRequest): Promise; retrieveTransactionSummary(params: TransactionSummaryWithAccountOverrideRequest | TransactionSummaryForAccountRequest): Promise; /** * Fetch transaction statistics grouped by hour between two dates. Notes this * will only return transactions flagged as live. * @param params - TransactionsByHourRequest * @returns Live transaction statistics grouped by hour */ listTransactionSummaryByHour(params: TransactionsByHourRequest): Promise; retrievePerformanceSummary(params: PerformanceReportRequest): Promise; retrievePerformanceSummaryByGateway(params: GatewayPerformanceReportRequest): Promise; }; payouts: { list(params: ListPayoutForAccountRequest | ListPayoutWithAccountOverrideRequest): Promise | undefined>; }; } interface TransactionsByHourRequest { /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ to_date: string; } interface TransactionSummaryRequest { to_date?: string; /** moto_payments report entry will be returned with 0 values unless this is set to true. */ include_moto_statistics?: boolean; } interface TransactionSummaryWithAccountOverrideRequest extends TransactionSummaryRequest { override_account_id_restriction: boolean; override_from_date_validation: boolean; } interface TransactionSummaryForAccountRequest extends TransactionSummaryRequest { /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date: string; account_id: number; } interface PaymentsByStateRequest { /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date?: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ to_date?: string; } interface PaymentsByStateWithAccountOverrideRequest extends PaymentsByStateRequest { override_account_id_restriction: boolean; } interface PaymentsByStateForAccountRequest extends PaymentsByStateRequest { account_id: number; } interface PerformanceReportRequest { /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ to_date: string; state?: TransactionState; } interface GatewayPerformanceReportRequest { /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ to_date: string; } interface RetrieveTransactionForAccountRequest { account_id: number; } interface RetrieveTransactionWithAccountOverrideRequest { override_account_id_restriction: boolean; account_id?: number; } interface ListTransactionRequest { page?: number; display_size?: number; cardholder_name?: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date?: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ to_date?: string; email?: string; reference?: string; last_digits_card_number?: string; first_digits_card_number?: string; state?: ExternalTransactionState; payment_states?: ExternalTransactionState | ExternalTransactionState[]; refund_states?: ExternalTransactionState | ExternalTransactionState[]; card_brands?: CardBrand | CardBrand[]; gateway_payout_id?: string; gateway_transaction_id?: string; /** * If the reference filter should check for the value in the reference or should * require it to exactly equal the reference. */ exact_reference_match?: boolean; /** * If the transaction has a parent, should the search also match on the values * of the parent transaction. */ with_parent_transaction?: boolean; } interface ListTransactionForAccountRequest extends ListTransactionRequest { account_id: number | number[]; } interface ListTransactionRequestWithAccountOverrideRequest extends ListTransactionRequest { override_account_id_restriction: boolean; account_id?: number | number[]; } interface ListPaymentRefundsRequest { gateway_account_id: number; } interface ListPaymentRefundsResponse { parent_transaction_id: string; transactions: Refund[]; } interface ListTransactionEventsRequest { gateway_account_id: number; /** * Do not filter events. By default (false) events are filtered for the self * service view, only showing certain events for backward compatability. Including * all events will return everything that made up the transaction in Ledger. */ include_all_events: boolean; } interface ListTransactionEventsResponse { transaction_id: string; events: Event[]; } interface ListEventTickerRequest { /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ from_date: string; /** simplified extended ISO format (ISO 8601). YYYY-MM-DDTHH:mm:ss.sssZ. Dates will be registered as UTC. */ to_date: string; } interface ListPayoutRequest { page?: number; display_size?: number; state?: ExternalPayoutState; } interface ListPayoutForAccountRequest extends ListPayoutRequest { gateway_account_id: number | number[]; } interface ListPayoutWithAccountOverrideRequest extends ListPayoutRequest { override_account_id_restriction: boolean; gateway_account_id?: number | number[]; } export {};