bkash-rs 0.2.1

Idiomatic async-first Rust client for the bKash Payment Gateway API.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
//! Authorization & Capture: request and response models.
//!
//! The Auth & Capture product implements a **delayed-capture reservation
//! model** (see plan §1.9). The verified flow is:
//!
//! 1. [`CreatePaymentRequest`] (`mode = "0011"`, `intent = "authorization"`)
//!    → [`CreatePaymentResponse`] returns a `paymentID` and `bkashURL`.
//! 2. Customer completes wallet approval at `bkashURL`.
//! 3. [`execute_payment`](super::super::auth_capture::AuthCaptureClient::execute_payment)
//!    → `paymentID` is **passed as a path param** to
//!    `/tokenized/checkout/execute/{paymentID}` (not as a body field, as
//!    in other products). Authorization is now complete.
//! 4. [`query_payment`](super::super::auth_capture::AuthCaptureClient::query_payment)
//!    → status should be `"Authorized"`. If still `"Initiated"`, retry
//!    from the create step.
//! 5. Either:
//!    - [`capture`](super::super::auth_capture::AuthCaptureClient::capture)
//!      (if the service was provided) → transaction completed.
//!    - [`void`](super::super::auth_capture::AuthCaptureClient::void)
//!      (if the service was not provided) → authorization cancelled.
//! 6. If no response is found from the capture/void API, **retry** the
//!    corresponding API unless the operation is successful (per §1.9).
//!
//! Note: the create-payment endpoint
//! (`/tokenized/checkout/payment/create`) is **distinct** from the
//! URL-based Checkout create endpoint
//! (`/tokenized/checkout/create`).
//!
//! ## Capture / Void response casing
//!
//! The Capture and Void response bodies use a lowercase `paymentId` field
//! (likely a documentation typo — other endpoints use `paymentID`). The
//! models in this module accept both casings via `#[serde(alias)]`.

use serde::{Deserialize, Serialize};

use crate::models::common::{Currency, Intent, Money, TransactionStatus};

/// `mode` discriminator value for `POST /tokenized/checkout/payment/create`
/// when creating an **Auth & Capture** payment (delayed-capture
/// reservation).
///
/// Note: the same `mode` value (`"0011"`) is used for URL-based Checkout
/// payments; the Auth & Capture flow is distinguished by the `intent`
/// field and the create-payment endpoint path.
pub const PAYMENT_MODE: &str = "0011";

// =====================================================================
// Create Payment (POST /tokenized/checkout/payment/create)
// =====================================================================

/// Request body for creating an Auth & Capture payment.
///
/// `mode` is automatically set to [`PAYMENT_MODE`] (`"0011"`) and `intent`
/// is forced to [`Intent::Authorization`].
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CreatePaymentRequest {
    /// Discriminator. Always [`PAYMENT_MODE`] (`"0011"`).
    #[serde(rename = "mode")]
    pub mode: String,

    /// Merchant's reference for the payer (e.g. internal customer ID).
    #[serde(rename = "payerReference")]
    pub payer_reference: String,

    /// URL bKash redirects to once the customer has completed the
    /// wallet-side flow.
    #[serde(rename = "callbackURL")]
    pub callback_url: String,

    /// Payment amount.
    pub amount: Money,

    /// Currency. bKash currently only supports BDT.
    pub currency: Currency,

    /// Intent. For Auth & Capture, this is always
    /// [`Intent::Authorization`].
    pub intent: Intent,

    /// Optional merchant invoice number.
    #[serde(
        rename = "merchantInvoiceNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub merchant_invoice_number: Option<String>,
}

impl CreatePaymentRequest {
    /// Construct a new create-payment request with sensible defaults.
    ///
    /// `mode` is automatically set to [`PAYMENT_MODE`] (`"0011"`) and
    /// `intent` is forced to [`Intent::Authorization`].
    #[must_use]
    pub fn new(
        payer_reference: impl Into<String>,
        callback_url: impl Into<String>,
        amount: Money,
        currency: Currency,
    ) -> Self {
        Self {
            mode: PAYMENT_MODE.to_string(),
            payer_reference: payer_reference.into(),
            callback_url: callback_url.into(),
            amount,
            currency,
            intent: Intent::Authorization,
            merchant_invoice_number: None,
        }
    }

    /// Override the merchant invoice number.
    #[must_use]
    pub fn with_merchant_invoice_number(mut self, n: impl Into<String>) -> Self {
        self.merchant_invoice_number = Some(n.into());
        self
    }
}

/// Response from creating an Auth & Capture payment. Contains the
/// `paymentID` that the client passes to
/// [`execute_payment`](super::super::auth_capture::AuthCaptureClient::execute_payment)
/// and the `bkashURL` the customer is redirected to.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CreatePaymentResponse {
    /// `paymentID` to be passed to the execute step.
    #[serde(rename = "paymentID")]
    pub payment_id: String,

    /// bKash-generated URL for the customer's wallet-side approval.
    #[serde(rename = "bkashURL", default)]
    pub bkash_url: String,

    /// Echoed callback URL.
    #[serde(rename = "callbackURL", default)]
    pub callback_url: String,

    /// Payment creation timestamp (ISO-8601).
    #[serde(rename = "paymentCreateTime", default)]
    pub payment_create_time: String,

    /// Echoed `payerReference`.
    #[serde(rename = "payerReference", default)]
    pub payer_reference: String,

    /// Echoed organization short code.
    #[serde(rename = "orgShortCode", default)]
    pub org_short_code: String,

    /// Echoed currency.
    #[serde(default)]
    pub currency: Currency,

    /// Echoed intent.
    #[serde(default)]
    pub intent: Intent,

    /// Echoed merchant invoice number.
    #[serde(rename = "merchantInvoiceNumber", default)]
    pub merchant_invoice_number: String,
}

// =====================================================================
// Execute Payment (POST /tokenized/checkout/execute/{paymentID})
// =====================================================================

/// Response from executing an Auth & Capture payment.
///
/// Note: unlike other products, the `paymentID` is **not** in the request
/// body. It is interpolated into the URL path
/// (`/tokenized/checkout/execute/{paymentID}`), so the execute endpoint
/// has **no** request body model.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ExecutePaymentResponse {
    /// `paymentID` that was executed.
    #[serde(rename = "paymentID")]
    pub payment_id: String,

    /// bKash transaction ID (`trxID`).
    #[serde(rename = "trxID", default)]
    pub trx_id: String,

    /// Customer MSISDN that completed the payment.
    #[serde(rename = "customerMsisdn", default)]
    pub customer_msisdn: String,

    /// Echoed `payerReference`.
    #[serde(rename = "payerReference", default)]
    pub payer_reference: String,

    /// Organization short code.
    #[serde(rename = "orgShortCode", default)]
    pub org_short_code: String,

    /// Echoed merchant invoice number.
    #[serde(rename = "merchantInvoiceNumber", default)]
    pub merchant_invoice_number: String,

    /// Echoed callback URL.
    #[serde(rename = "callbackURL", default)]
    pub callback_url: String,

    /// Payment execution timestamp (ISO-8601).
    #[serde(rename = "paymentExecuteTime", default)]
    pub payment_execute_time: String,

    /// Echoed currency.
    #[serde(default)]
    pub currency: Currency,

    /// Echoed intent.
    #[serde(default)]
    pub intent: Intent,

    /// Echoed amount.
    #[serde(default)]
    pub amount: Money,

    /// Authorization status (typically `"Authorized"` after a successful
    /// execute).
    #[serde(rename = "transactionStatus", default)]
    pub transaction_status: TransactionStatus,
}

// =====================================================================
// Query Payment (POST /tokenized/checkout/payment/status)
// =====================================================================

/// Request body for querying an Auth & Capture payment.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QueryPaymentRequest {
    /// `paymentID` to query.
    #[serde(rename = "paymentID")]
    pub payment_id: String,
}

impl QueryPaymentRequest {
    /// Construct a new query-payment request.
    #[must_use]
    pub fn new(payment_id: impl Into<String>) -> Self {
        Self {
            payment_id: payment_id.into(),
        }
    }
}

/// Response from querying an Auth & Capture payment.
///
/// The `transactionStatus` field is the key state machine indicator for
/// the reservation flow. The expected values are:
/// `"Initiated"`, `"Authorized"`, `"Completed"`. `"Initiated"` means the
/// customer has not yet completed the wallet flow; `"Authorized"` means
/// funds are reserved (ready for capture or void); `"Completed"` means
/// the funds have been captured.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QueryPaymentResponse {
    /// `paymentID` queried.
    #[serde(rename = "paymentID")]
    pub payment_id: String,

    /// bKash transaction ID.
    #[serde(rename = "trxID", default)]
    pub trx_id: String,

    /// Customer MSISDN.
    #[serde(rename = "customerMsisdn", default)]
    pub customer_msisdn: String,

    /// Echoed `payerReference`.
    #[serde(rename = "payerReference", default)]
    pub payer_reference: String,

    /// Echoed organization short code.
    #[serde(rename = "orgShortCode", default)]
    pub org_short_code: String,

    /// Echoed merchant invoice number.
    #[serde(rename = "merchantInvoiceNumber", default)]
    pub merchant_invoice_number: String,

    /// Echoed callback URL.
    #[serde(rename = "callbackURL", default)]
    pub callback_url: String,

    /// Echoed currency.
    #[serde(default)]
    pub currency: Currency,

    /// Echoed intent.
    #[serde(default)]
    pub intent: Intent,

    /// Echoed amount.
    #[serde(default)]
    pub amount: Money,

    /// Authorization / transaction status. Use the variant
    /// [`TransactionStatus::Authorized`] to confirm that a payment has
    /// been authorized and is ready for capture or void.
    #[serde(rename = "transactionStatus", default)]
    pub transaction_status: TransactionStatus,

    /// Timestamp the payment was executed (ISO-8601).
    #[serde(rename = "paymentExecuteTime", default)]
    pub payment_execute_time: String,
}

// =====================================================================
// Capture (POST /tokenized/checkout/payment/confirm/capture)
// =====================================================================

/// Request body for capturing a previously-authorized payment.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CaptureRequest {
    /// `paymentID` to capture.
    #[serde(rename = "paymentID")]
    pub payment_id: String,
}

impl CaptureRequest {
    /// Construct a new capture request.
    #[must_use]
    pub fn new(payment_id: impl Into<String>) -> Self {
        Self {
            payment_id: payment_id.into(),
        }
    }
}

/// Response from capturing a payment.
///
/// Note: the field is named `paymentId` (lowercase `i`) in the bKash
/// documentation samples (likely a doc typo), whereas the rest of the
/// bKash API uses `paymentID`. The model accepts both casings.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CaptureResponse {
    /// `paymentId` / `paymentID` that was captured.
    #[serde(rename = "paymentId", alias = "paymentID")]
    pub payment_id: String,

    /// Capture / creation timestamp (ISO-8601).
    #[serde(rename = "createTime", default)]
    pub create_time: String,

    /// Capture / update timestamp (ISO-8601).
    #[serde(rename = "updateTime", default)]
    pub update_time: String,

    /// bKash transaction ID.
    #[serde(rename = "trxID", default)]
    pub trx_id: String,

    /// Final transaction status (typically `"Completed"` after capture).
    #[serde(rename = "transactionStatus", default)]
    pub transaction_status: String,
}

// =====================================================================
// Void (POST /tokenized/checkout/payment/confirm/capture/void)
// =====================================================================

/// Request body for voiding a previously-authorized payment.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VoidRequest {
    /// `paymentID` to void.
    #[serde(rename = "paymentID")]
    pub payment_id: String,
}

impl VoidRequest {
    /// Construct a new void request.
    #[must_use]
    pub fn new(payment_id: impl Into<String>) -> Self {
        Self {
            payment_id: payment_id.into(),
        }
    }
}

/// Response from voiding a payment.
///
/// Note: the field is named `paymentId` (lowercase `i`) in the bKash
/// documentation samples (likely a doc typo), whereas the rest of the
/// bKash API uses `paymentID`. The model accepts both casings.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VoidResponse {
    /// `paymentId` / `paymentID` that was voided.
    #[serde(rename = "paymentId", alias = "paymentID")]
    pub payment_id: String,

    /// Void / creation timestamp (ISO-8601).
    #[serde(rename = "createTime", default)]
    pub create_time: String,

    /// Void / update timestamp (ISO-8601).
    #[serde(rename = "updateTime", default)]
    pub update_time: String,

    /// bKash transaction ID.
    #[serde(rename = "trxID", default)]
    pub trx_id: String,

    /// Final transaction status (typically `"Cancelled"` after void).
    #[serde(rename = "transactionStatus", default)]
    pub transaction_status: String,
}

// =====================================================================
// Search Transaction (GET /checkout/payment/search/{trxID})
// =====================================================================

/// Response from the search-transaction endpoint (Auth & Capture).
///
/// Note: this endpoint is **GET** (not POST) and takes `trxID` as a
/// **path param** (not a body field). It returns the full transaction
/// shape.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SearchTransactionResponse {
    /// bKash transaction ID.
    #[serde(rename = "trxID")]
    pub trx_id: String,

    /// Transaction status.
    #[serde(rename = "transactionStatus", default)]
    pub transaction_status: TransactionStatus,

    /// Transaction type (e.g. `"Payment"`, `"Refund"`).
    #[serde(rename = "transactionType", default)]
    pub transaction_type: String,

    /// Echoed amount.
    #[serde(default)]
    pub amount: Money,

    /// Echoed currency.
    #[serde(default)]
    pub currency: Currency,

    /// Customer MSISDN.
    #[serde(rename = "customerMsisdn", default)]
    pub customer_msisdn: String,

    /// Organization short code.
    #[serde(rename = "organizationShortCode", default)]
    pub organization_short_code: String,

    /// Initiation timestamp (ISO-8601).
    #[serde(rename = "initiationTime", default)]
    pub initiation_time: String,

    /// Completion timestamp (ISO-8601).
    #[serde(rename = "completedTime", default)]
    pub completed_time: String,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn create_payment_serialises_with_mode_0011_and_intent_authorization() {
        let req = CreatePaymentRequest::new(
            "cust-1",
            "https://example.test/cb",
            Money::bdt("50.00"),
            Currency::Bdt,
        );
        let json: serde_json::Value = serde_json::to_value(&req).unwrap();
        assert_eq!(json["mode"], "0011");
        assert_eq!(json["intent"], "authorization");
        assert_eq!(json["payerReference"], "cust-1");
        assert_eq!(json["callbackURL"], "https://example.test/cb");
        assert_eq!(json["amount"], "50.00");
        assert_eq!(json["currency"], "BDT");
        assert!(json.get("merchantInvoiceNumber").is_none());
    }

    #[test]
    fn create_payment_with_optional_fields_serialises() {
        let req = CreatePaymentRequest::new(
            "cust-1",
            "https://example.test/cb",
            Money::bdt("50.00"),
            Currency::Bdt,
        )
        .with_merchant_invoice_number("INV-AC-1");
        let json: serde_json::Value = serde_json::to_value(&req).unwrap();
        assert_eq!(json["merchantInvoiceNumber"], "INV-AC-1");
    }

    #[test]
    fn create_payment_response_parses_minimal() {
        let body = r#"{
            "paymentID": "TR0001",
            "bkashURL": "https://example.test/bkash",
            "callbackURL": "https://example.test/cb",
            "paymentCreateTime": "2026-06-22T10:00:00:000 GMT+06:00",
            "payerReference": "cust-1",
            "orgShortCode": "0123",
            "currency": "BDT",
            "intent": "authorization",
            "merchantInvoiceNumber": ""
        }"#;
        let resp: CreatePaymentResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
        assert_eq!(resp.intent, Intent::Authorization);
        assert_eq!(resp.bkash_url, "https://example.test/bkash");
    }

    #[test]
    fn execute_payment_response_parses_minimal() {
        let body = r#"{
            "paymentID": "TR0001",
            "trxID": "8A00ABCD",
            "transactionStatus": "Authorized",
            "amount": "50.00",
            "currency": "BDT",
            "intent": "authorization",
            "paymentExecuteTime": "2026-06-22T10:01:00:000 GMT+06:00"
        }"#;
        let resp: ExecutePaymentResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
        assert_eq!(resp.trx_id, "8A00ABCD");
        assert_eq!(resp.transaction_status, TransactionStatus::Authorized);
        assert_eq!(resp.amount.as_str(), "50.00");
    }

    #[test]
    fn query_payment_request_serialises() {
        let req = QueryPaymentRequest::new("TR0001");
        let json: serde_json::Value = serde_json::to_value(&req).unwrap();
        assert_eq!(json["paymentID"], "TR0001");
    }

    #[test]
    fn query_payment_response_parses_authorized() {
        let body = r#"{
            "paymentID": "TR0001",
            "trxID": "8A00ABCD",
            "transactionStatus": "Authorized",
            "amount": "50.00",
            "currency": "BDT",
            "intent": "authorization",
            "payerReference": "cust-1",
            "customerMsisdn": "01700000000",
            "orgShortCode": "0123",
            "callbackURL": "https://example.test/cb",
            "merchantInvoiceNumber": "",
            "paymentExecuteTime": "2026-06-22T10:01:00:000 GMT+06:00"
        }"#;
        let resp: QueryPaymentResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
        assert_eq!(resp.transaction_status, TransactionStatus::Authorized);
    }

    #[test]
    fn capture_request_serialises() {
        let req = CaptureRequest::new("TR0001");
        let json: serde_json::Value = serde_json::to_value(&req).unwrap();
        assert_eq!(json["paymentID"], "TR0001");
    }

    #[test]
    fn capture_response_accepts_lowercase_payment_id() {
        // The bKash sample uses lowercase `paymentId` for capture/void.
        let body = r#"{
            "paymentId": "TR0001",
            "createTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "updateTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "trxID": "8A00ABCD",
            "transactionStatus": "Completed"
        }"#;
        let resp: CaptureResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
        assert_eq!(resp.trx_id, "8A00ABCD");
        assert_eq!(resp.transaction_status, "Completed");
    }

    #[test]
    fn capture_response_accepts_uppercase_payment_id() {
        // The alias must accept the more typical `paymentID` form too.
        let body = r#"{
            "paymentID": "TR0001",
            "createTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "updateTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "trxID": "8A00ABCD",
            "transactionStatus": "Completed"
        }"#;
        let resp: CaptureResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
    }

    #[test]
    fn void_request_serialises() {
        let req = VoidRequest::new("TR0001");
        let json: serde_json::Value = serde_json::to_value(&req).unwrap();
        assert_eq!(json["paymentID"], "TR0001");
    }

    #[test]
    fn void_response_accepts_lowercase_payment_id() {
        let body = r#"{
            "paymentId": "TR0001",
            "createTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "updateTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "trxID": "8A00ABCD",
            "transactionStatus": "Cancelled"
        }"#;
        let resp: VoidResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
        assert_eq!(resp.transaction_status, "Cancelled");
    }

    #[test]
    fn void_response_accepts_uppercase_payment_id() {
        let body = r#"{
            "paymentID": "TR0001",
            "createTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "updateTime": "2026-06-22T10:02:00:000 GMT+06:00",
            "trxID": "8A00ABCD",
            "transactionStatus": "Cancelled"
        }"#;
        let resp: VoidResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.payment_id, "TR0001");
    }

    #[test]
    fn search_transaction_response_parses() {
        let body = r#"{
            "trxID": "8A00ABCD",
            "transactionStatus": "Authorized",
            "transactionType": "Payment",
            "amount": "100.00",
            "currency": "BDT",
            "customerMsisdn": "01700000000",
            "organizationShortCode": "0123",
            "initiationTime": "2026-06-22T09:00:00:000 GMT+06:00",
            "completedTime": ""
        }"#;
        let resp: SearchTransactionResponse = serde_json::from_str(body).unwrap();
        assert_eq!(resp.trx_id, "8A00ABCD");
        assert_eq!(resp.transaction_status, TransactionStatus::Authorized);
        assert_eq!(resp.amount.as_str(), "100.00");
    }

    // ---- proptest round-trips -----------------------------------------

    use proptest::prelude::*;

    proptest! {
        #[test]
        fn create_payment_request_roundtrip(
            payer_ref in ".*",
            callback in ".*",
            amount in ".*",
        ) {
            let req = CreatePaymentRequest::new(
                payer_ref,
                callback,
                Money::new(amount),
                Currency::Bdt,
            );
            // Auth & Capture's `intent` is forced to Authorization.
            let json = serde_json::to_string(&req).unwrap();
            let back: CreatePaymentRequest = serde_json::from_str(&json).unwrap();
            let json2 = serde_json::to_string(&back).unwrap();
            prop_assert_eq!(json, json2);
            prop_assert_eq!(back.intent, Intent::Authorization);
            prop_assert_eq!(back.mode, PAYMENT_MODE);
        }
    }
}