arlyon / async-stripe

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

Error body serialization fails for `insufficient_capabilities_for_transfer` #636

Open dyc3 opened 2 weeks ago

dyc3 commented 2 weeks ago

Describe the bug

My integration made a request to POST /v1/transfers and get back this response:

{
  "error": {
    "code": "insufficient_capabilities_for_transfer",
    "message": "Your destination account needs to have at least one of the following capabilities enabled: transfers, crypto_transfers, legacy_payments",
    "request_log_url": "https://dashboard.stripe.com/test/logs/req_cyVXKUT1GV30oN?t=1731361723",
    "type": "invalid_request_error"
  }
}

This causes the async-stripe library to return a StripeError::JSONSerialization instead of StripeError::Stripe.

To Reproduce

  1. Create a connected account, but don't give it the transfers capability. I think not doing the onboarding for the connected account will also not give it any capabilities.
  2. Create a transfer to that connected account
  3. Receive error from Stripe
  4. Library fails to parse error.

Expected behavior

It should parse the error correctly and return the right type of error. Preferably, I think the ErrorCode enum should have an Unknown(String) variant so that cases like this can be worked around by users without an crate update.

Code snippets

No response

OS

linux, ubuntu 20.04

Rust version

1.82

Library version

async-stripe 0.39.1

API version

2023-10-16

Additional context

Directly related to: #384

I'm willing to contribute a fix for this.