wyyerd / stripe-rs

Rust API bindings for the Stripe HTTP API.
Apache License 2.0
219 stars 88 forks source link

Support refund ids with a `pyr_` prefix #177

Closed khalsah closed 3 years ago

khalsah commented 3 years ago

Just like charge objects can have id's that start with either ch_ (if they are a credit card charge) or py_ (if they are made with some other payment method) refund object appear to have id's that start with either re_ or pyr_.

Additional context

The following is an example of a balance_transaction returned by stripe that the library currently fails to deserialize due to the pyr_ id in the source field.

{
  "id": "txn_1IjAOrLmhS4ct6Pcnemb89MP",
  "object": "balance_transaction",
  "amount": -5995,
  "available_on": 1619568000,
  "created": 1619128168,
  "currency": "usd",
  "description": "REFUND FOR FAILED PAYMENT",
  "exchange_rate": null,
  "fee": 352,
  "fee_details": [
    {
      "amount": 352,
      "application": null,
      "currency": "usd",
      "description": "Stripe processing fees",
      "type": "stripe_fee"
    }
  ],
  "net": -6347,
  "reporting_category": "charge_failure",
  "source": "pyr_1IjAOqLmhS4ct6Pc2ZhAd56E",
  "status": "available",
  "type": "payment_failure_refund"
}

Fetching that same balance_transaction with the source expanded you can see that stripe considers that source a "refund" object:

{
  "id": "txn_1IjAOrLmhS4ct6Pcnemb89MP",
  "object": "balance_transaction",
  "amount": -5995,
  "available_on": 1619568000,
  "created": 1619128168,
  "currency": "usd",
  "description": "REFUND FOR FAILED PAYMENT",
  "exchange_rate": null,
  "fee": 352,
  "fee_details": [
    {
      "amount": 352,
      "application": null,
      "currency": "usd",
      "description": "Stripe processing fees",
      "type": "stripe_fee"
    }
  ],
  "net": -6347,
  "reporting_category": "charge_failure",
  "source": {
    "id": "pyr_1IjAOqLmhS4ct6Pc2ZhAd56E",
    "object": "refund",
    "amount": 5995,
    "balance_transaction": "txn_1IjAOrLmhS4ct6Pcnemb89MP",
    "charge": "py_1IiJsHLmhS4ct6PcRVXjxSvz",
    "created": 1619128168,
    "currency": "usd",
    "description": "Payment failure refund",
    "metadata": {
    },
    "payment_intent": null,
    "reason": null,
    "receipt_number": null,
    "source_transfer_reversal": null,
    "status": "succeeded",
    "transfer_reversal": null
  },
  "status": "available",
  "type": "payment_failure_refund"
}