arlyon / async-stripe

Async (and blocking!) Rust bindings for the Stripe API
https://payments.rs
Apache License 2.0
436 stars 127 forks source link

BalanceTransactionSourceId should include ReserveTransaction #572

Open pdoms opened 1 month ago

pdoms commented 1 month ago

Describe the bug

When listing BalanceTransactions deserialization fails at path to data.source if the source is a ReserveTransaction (with prefix rtx_).

To Reproduce

  1. Have a ReserveTransaction (Reserved Funds) in your stripe environment
  2. Call BalanceTransaction::list - no specific params or specify params.type_ = Some(BalanceTransactionType::ReserveTransaction.as_str());

Expected behavior

If the BalanceTransaction is of type ReserveTransaction Deserialization should work.

Code snippets

No response

OS

Ubuntu 22.04

Rust version

1.77.1 2024-03-27

Library version

async-stripe 0.37.1

API version

2022-08-01

Additional context

I assume it is a bug origination in the openAPI specs for stripe and thus incorrect code generation.

However, a manual/temporary fix could be the following.

src/ids.rs


def_id!(ReserveTransactionId, "rtx_"); //changed from "rtx" to "rtx_"
[...]
def_id!(
    #[optional]
    enum BalanceTransactionSourceId {
       [...]
        TransferReversal(TransferReversalId),
        ReserveTransaction(ReserveTransactionId),
    }
);

src/resources/balance_transactions_ext.rs

impl Object for BalanceTransactionSourceUnion {
    type Id = BalanceTransactionSourceId;
    fn id(&self) -> Self::Id {
        use BalanceTransactionSourceId as Id;
        use BalanceTransactionSourceUnion as Source;

        match self {
            [...]
            Source::ReserveTransaction(x) => Id::ReserveTransaction(x.id()), //from Id::None
            [...]
        }
    }
arlyon commented 1 month ago

I have opened a PR to change the ID to rtx_, that was an oversight thanks for reporting!

arlyon commented 1 month ago

Please let me know if that PR solves your issue

pdoms commented 1 month ago

Thanks @arlyon for the swift response to this. I have tried it with 0.37.2 but unfortunately the error still persists.