Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refunds on Charge object is nullable #456

Closed
migueltol22 opened this issue Dec 7, 2023 · 3 comments · Fixed by #452 or #503
Closed

Refunds on Charge object is nullable #456

migueltol22 opened this issue Dec 7, 2023 · 3 comments · Fixed by #452 or #503
Labels
bug Something isn't working

Comments

@migueltol22
Copy link

migueltol22 commented Dec 7, 2023

Describe the bug

According to the stripe docs refunds on the charge object is nullable.

In situations when trying to deserialize the object to a Charge struct we get an error of

missing field `refunds`

To Reproduce

In my specific scenario, I am listening to the charge.succeeded webhook that is equivalent to the example as part of the repo

Listen to stripe webhooks locally using stripe cli

stripe listen --forward-connect-to localhost:8000/stripe_webhooks

charge.succeeded event will fail with the example setup.

Added additional logging for debugging

#[async_trait]
impl<S, B> FromRequest<S, B> for StripeEvent
where
    String: FromRequest<S, B>,
    B: Send + 'static,
    S: Send + Sync,
    AppState: FromRef<S>,
{
    type Rejection = Response;

    async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
        let ctx: AppState = AppState::from_ref(state);
        let signature = if let Some(sig) = req.headers().get("stripe-signature") {
            sig.to_owned()
        } else {
            return Err(StatusCode::BAD_REQUEST.into_response());
        };

        let payload = String::from_request(req, state)
            .await
            .map_err(IntoResponse::into_response)?;

        Ok(Self(
            stripe::Webhook::construct_event(
                &payload,
                signature.to_str().unwrap(),
                &ctx.config.stripe_webhook_secret,
            )
            .map_err(|e| {
                log::error!(
                    "failed to construct event of payload: {:?} with err: {:?}",
                    payload,
                    e
                );
                StatusCode::BAD_REQUEST.into_response()
            })?,
        ))
    }
}

Expected Error:

failed to construct event of payload: "<redacted_payload>" with err: BadParse(Error("missing field `refunds`", line: 120, column: 3))

Expected behavior

I'd expect refunds to be of type Option<List<Refund>> and be able to parse correctly if refunds is not provided in the payload.

Code snippets

No response

OS

macOs

Rust version

1.74.0

Library version

async-stripe 0.22.2

API version

2022-11-15

Additional context

No response

@migueltol22 migueltol22 added the bug Something isn't working label Dec 7, 2023
@extrawurst
Copy link

I am hitting the same problem in the webhook charge.refunded it wont deserialize properly
.. with err: BadParse(Error("missing field refunds", line: 124, column: 5))

@JBlashME
Copy link

JBlashME commented Feb 6, 2024

I am hitting the same problem in the webhook charge.refunded it wont deserialize properly .. with err: BadParse(Error("missing field refunds", line: 124, column: 5))

Im currently working with 0.31.0 and having the same issue.
I think its because refunds is not optional in the charge struct causing it to fail.
async-stripe-0.31.0/src/resources/generated/charge.rs

    /// A list of refunds that have been applied to the charge.
    pub refunds: List<Refund>,

It looks like in the PR above they have a fix
pub refunds: Option<stripe_types::List<stripe_shared::Refund>>,

The last comment on the PR was to release so hopefully it goes out soon.

@arlyon
Copy link
Owner

arlyon commented Feb 15, 2024

I have a PR for this here: #503

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants