arlyon / async-stripe

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

Errors not returning complete response #486

Open DevSlashRichie opened 5 months ago

DevSlashRichie commented 5 months ago

Describe the bug

When an error occurs, for example creating a payment intent but it fails, it won't return the complete response.

To Reproduce

Create a payment intent that fails.

Expected behavior

It should return the complete response instead of just the first part of it.


{
  "error": {
    "charge": "ch_3ObmbRIo7omsGjqY31e2p2Nh",
    "code": "card_declined",
    "decline_code": "generic_decline",
    "doc_url": "https://stripe.com/docs/error-codes/card-declined",
    "message": "Your card was declined.",
    "payment_intent": {
      "id": "pi_3ObmbRIo7omsGjqY3y34dxUD",
      "object": "payment_intent",
      "amount": 53144,
      "amount_capturable": 0,
      "amount_details": {
        "tip": {
        }
      },
      "amount_received": 0,
      "application": "ca_P1a7jtwXanEd70AVRbHcXZUWYIDwvVwq",
      "application_fee_amount": 580,
      "automatic_payment_methods": {
        "allow_redirects": "never",
        "enabled": true
      },
      "canceled_at": null,
      "cancellation_reason": null,
      "capture_method": "automatic",
      "client_secret": "pi_3O**********************_******_*********************OVeY",
      "confirmation_method": "automatic",
      "created": 1706026413,
      "currency": "mxn",
      "customer": "cus_PLWDRkLb56p8fl",
      "description": "Renta de cancha, a las 2024-03-04 18:00:00 UTC por 60m",
      "invoice": null,
      "last_payment_error": {
        "charge": "ch_3ObmbRIo7omsGjqY31e2p2Nh",
        "code": "card_declined",
        "decline_code": "generic_decline",
        "doc_url": "https://stripe.com/docs/error-codes/card-declined",
        "message": "Your card was declined.",
        "payment_method": {
          "id": "pm_1ObmbQIo7omsGjqYUH0obYQn",
          "object": "payment_method",
          "billing_details": {
            "address": {
              "city": null,
              "country": null,
              "line1": null,
              "line2": null,
              "postal_code": null,
              "state": null
            },
            "email": null,
            "name": null,
            "phone": null
          },
          "card": {
            "brand": "visa",
            "checks": {
              "address_line1_check": null,
              "address_postal_code_check": null,
              "cvc_check": "pass"
            },
            "country": "US",
            "exp_month": 1,
            "exp_year": 2025,
            "fingerprint": "9SMlpA6uP9znzUD9",
            "funding": "credit",
            "generated_from": null,
            "last4": "0002",
            "networks": {
              "available": [
                "visa"
              ],
              "preferred": null
            },
            "three_d_secure_usage": {
              "supported": true
            },
            "wallet": null
          },
          "created": 1706026412,
          "customer": null,
          "livemode": false,
          "metadata": {
          },
          "type": "card"
        },
        "type": "card_error"
      },
      "latest_charge": "ch_3ObmbRIo7omsGjqY31e2p2Nh",
      "livemode": false,
      "metadata": {
        "recurring": "true",
        "internal_id": "pi_h1bvcaZKaXr4uxr9YrXr6"
      },
      "next_action": null,
      "on_behalf_of": null,
      "payment_method": null,
      "payment_method_configuration_details": {
        "id": "pmc_1OWp9tIo7omsGjqYiBO1LJGU",
        "parent": "pmc_1ODancEndTvLTZal0AIB1PtR"
      },
      "payment_method_options": {
        "card": {
          "installments": {
            "available_plans": [
            ],
            "enabled": false,
            "plan": null
          },
          "mandate_options": null,
          "network": null,
          "request_three_d_secure": "automatic"
        },
        "link": {
          "persistent_token": null
        },
        "oxxo": {
          "expires_after_days": 3
        }
      },
      "payment_method_types": [
        "card",
        "oxxo",
        "link"
      ],
      "processing": null,
      "receipt_email": "romr020606@gmail.com",
      "review": null,
      "setup_future_usage": null,
      "shipping": null,
      "source": null,
      "statement_descriptor": null,
      "statement_descriptor_suffix": null,
      "status": "requires_payment_method",
      "transfer_data": null,
      "transfer_group": null
    },
    "payment_method": {
      "id": "pm_1ObmbQIo7omsGjqYUH0obYQn",
      "object": "payment_method",
      "billing_details": {
        "address": {
          "city": null,
          "country": null,
          "line1": null,
          "line2": null,
          "postal_code": null,
          "state": null
        },
        "email": null,
        "name": null,
        "phone": null
      },
      "card": {
        "brand": "visa",
        "checks": {
          "address_line1_check": null,
          "address_postal_code_check": null,
          "cvc_check": "pass"
        },
        "country": "US",
        "exp_month": 1,
        "exp_year": 2025,
        "fingerprint": "9SMlpA6uP9znzUD9",
        "funding": "credit",
        "generated_from": null,
        "last4": "0002",
        "networks": {
          "available": [
            "visa"
          ],
          "preferred": null
        },
        "three_d_secure_usage": {
          "supported": true
        },
        "wallet": null
      },
      "created": 1706026412,
      "customer": null,
      "livemode": false,
      "metadata": {
      },
      "type": "card"
    },
    "request_log_url": "https://dashboard.stripe.com/acct_1OWp9qIo7omsGjqY/test/logs/req_YilXyfMdMGCrUU?t=1706026412",
    "type": "card_error"
  }
}```

### Code snippets

_No response_

### OS

macOS

### Rust version

1.26.0

### Library version

async-stripe 0.29.0

### API version

2023-10-16

### Additional context

_No response_