arlyon/async-stripe

error on parse webhook event

Closed this issue · 6 comments

Describe the bug

image

thread 'main' panicked at src/main.rs:133:47:
called Result::unwrap() on an Err value: Error("missing field refunds", line: 120, column: 3)
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

To Reproduce

use stripe::Event;
fn main() {
    let json = r#"
  {
"id": "evt_3OZrKABS6OLyeF2Q0Jd6Unwp",
  "object": "event",
  "api_version": "2023-10-16",
  "created": 1705567906,
  "data": {
    "object": {
      "id": "ch_3OZrKABS6OLyeF2Q0p5rkApJ",
      "object": "charge",
      "amount": 921,
      "amount_captured": 921,
      "amount_refunded": 0,
      "amount_updates": [
      ],
      "application": null,
      "application_fee": null,
      "application_fee_amount": null,
      "balance_transaction": "txn_3OZrKABS6OLyeF2Q0aYg7A1N",
      "billing_details": {
        "address": {
          "city": null,
          "country": "HK",
          "line1": null,
          "line2": null,
          "postal_code": null,
          "state": null
        },
        "email": null,
        "name": null,
        "phone": null
      },
      "calculated_statement_descriptor": "I18N.SITE",
      "captured": true,
      "created": 1705567906,
      "currency": "eur",
      "customer": "cus_POLP7kduwzrOZO",
      "description": null,
      "destination": null,
      "dispute": null,
      "disputed": false,
      "failure_balance_transaction": null,
      "failure_code": null,
      "failure_message": null,
      "fraud_details": {
      },
      "invoice": null,
      "livemode": false,
      "metadata": {
      },
      "on_behalf_of": null,
      "order": null,
      "outcome": {
        "network_status": "approved_by_network",
        "reason": null,
        "risk_level": "normal",
        "risk_score": 46,
        "seller_message": "Payment complete.",
        "type": "authorized"
      },
      "paid": true,
      "payment_intent": "pi_3OZrKABS6OLyeF2Q0R7Sy2br",
      "payment_method": "pm_1OZYiKBS6OLyeF2QypFO5uz4",
      "payment_method_details": {
        "card": {
          "amount_authorized": 921,
          "brand": "visa",
          "checks": {
            "address_line1_check": null,
            "address_postal_code_check": null,
            "cvc_check": null
          },
          "country": "US",
          "exp_month": 2,
          "exp_year": 2026,
          "extended_authorization": {
            "status": "disabled"
          },
          "fingerprint": "8ucVymgWvAPOS3CE",
          "funding": "credit",
          "incremental_authorization": {
            "status": "unavailable"
          },
          "installments": null,
          "last4": "4242",
          "mandate": null,
          "multicapture": {
            "status": "unavailable"
          },
          "network": "visa",
          "network_token": {
            "used": false
          },
          "overcapture": {
            "maximum_amount_capturable": 921,
            "status": "unavailable"
          },
          "three_d_secure": null,
          "wallet": null
        },
        "type": "card"
      },
      "radar_options": {
      },
      "receipt_email": null,
      "receipt_number": null,
      "receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xT09kZVpCUzZPTHllRjJRKKLNo60GMgYwDXSEzjM6LBZtxL67he86-l2kL_oWbNJg3F_WDxJvrbx831Cl2dspC6D38NyT_I6IEW89",
      "refunded": false,
      "review": null,
      "shipping": null,
      "source": null,
      "source_transfer": null,
      "statement_descriptor": null,
      "statement_descriptor_suffix": null,
      "status": "succeeded",
      "transfer_data": null,
      "transfer_group": null
    }
  },
  "livemode": false,
  "pending_webhooks": 2,
  "request": {
    "id": "req_vGZL0NgxwRyn2t",
    "idempotency_key": "137e565f-ee38-4e3a-bf49-bf3d460cfb7c"
  },
  "type": "charge.succeeded"
}
      "#;
    let t: Event = serde_json::from_str(json).unwrap();
    dbg!(t);
}

Expected behavior

parse

Code snippets

No response

OS

mac

Rust version

cargo 1.77.0-nightly (3e428a38a 2024-01-09)

Library version

v0.29.0

API version

latest

Additional context

No response

I am having the same error.

I've created #493 tho is a generated file. @i18n-now you could use my branch for now in case this is critical for you.

arlyon commented

The stripe openapi reports that this field is required, so if they are sending incorrect data then they need to resolve it on their end. I would suggest opening an issue with https://github.com/stripe/openapi and linking to this issue. When your request is addressed, this library will automatically pick up the changes (we update every week).

I am going to close PR #493 since merging it would just be overwritten the next week, but as mentioned by @DevSlashRichie please feel free to use that branch in the mean time 🙂

arlyon commented

Since there is no action in this repo, I am going to close this issue.

I'm seeing the same failure...

Screenshot 2024-04-24 at 1 58 43 AM

with the message

Failed to deserialize the JSON body into the target type: data.object: missing field `refunds` at line 121 column 3

I would suggest opening an issue with https://github.com/stripe/openapi and linking to this issue.

Created stripe/openapi#152.

stripe/openapi#152 has been resolved so we should be unblocked on this now.