alat/modules/statement.rs
1//! Account statements — retrieve a customer's transaction statement.
2//!
3//! The **Get Statement** product (`/get-statement-service`) generates a
4//! statement asynchronously in two steps:
5//!
6//! 1. **Initiate** — register the request for an account over a date range. The
7//! bank returns a `referenceId` once the statement is prepared.
8//! 2. **Retrieve** — exchange that `referenceId` for the actual transaction rows.
9//!
10//! The transaction rows reuse the shared [`Transaction`] type from the account
11//! module.
12
13use crate::client::Client;
14use crate::envelope::ApiResponse;
15use crate::error::Result;
16use crate::modules::account::Transaction;
17use serde::{Deserialize, Serialize};
18
19/// Request body to initiate a statement.
20///
21/// Server type: `InitiateGetCustomerStatementRequest`. The date fields are named
22/// `dateFrom`/`dateTo` and accept ISO-8601 date-times (e.g.
23/// `2022-09-07T09:27:13.133Z`).
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct InitiateStatementRequest {
27 /// The 10-digit NUBAN to produce a statement for.
28 pub account_number: String,
29 /// Inclusive start of the statement window (ISO-8601 date-time).
30 pub date_from: String,
31 /// Inclusive end of the statement window (ISO-8601 date-time).
32 pub date_to: String,
33}
34
35/// The `data` object returned by `InitiateGetCustomerStatement`: just the
36/// reference id used to retrieve the prepared statement.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39struct StatementReference {
40 reference_id: String,
41}
42
43/// Request body to retrieve a prepared statement.
44///
45/// Server type: `GetCustomerTransactionsRequest`.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct GetStatementRequest {
49 /// The `referenceId` returned by [`initiate_statement`](Client::initiate_statement).
50 pub reference_id: String,
51}
52
53impl Client {
54 /// **Step 1** — initiate statement generation; returns the `referenceId` to
55 /// pass to [`get_statement_transactions`](Client::get_statement_transactions).
56 ///
57 /// `POST /get-statement-service/api/AccountMaintenance/InitiateGetCustomerStatement`
58 pub async fn initiate_statement(&self, request: &InitiateStatementRequest) -> Result<String> {
59 let reference = self
60 .post_json::<_, ApiResponse<StatementReference>>(
61 "get-statement-service/api/AccountMaintenance/InitiateGetCustomerStatement",
62 request,
63 &[],
64 )
65 .await?
66 .into_result()?;
67 Ok(reference.reference_id)
68 }
69
70 /// **Step 2** — retrieve the prepared statement's transaction rows.
71 ///
72 /// `POST /get-statement-service/api/AccountMaintenance/GetCustomerTransactions`
73 pub async fn get_statement_transactions(
74 &self,
75 request: &GetStatementRequest,
76 ) -> Result<Vec<Transaction>> {
77 self.post_json::<_, ApiResponse<Vec<Transaction>>>(
78 "get-statement-service/api/AccountMaintenance/GetCustomerTransactions",
79 request,
80 &[],
81 )
82 .await?
83 .into_result()
84 }
85}