简体   繁体   English

在 C# 中使用 ExtraParams 从 Stripe 的 API 中提取特定事件

[英]Using ExtraParams in C# to pull specific events from Stripe's API

So, I feel like I am overlooking something incredibly simple.所以,我觉得我忽略了一些非常简单的事情。 I am currently trying to pull all charge events for a single card given the card fingerprint from Stripe.鉴于来自 Stripe 的卡指纹,我目前正在尝试为单张卡提取所有收费事件。 However, I am pretty lost on how to do so without also supplying a customer ID, though I think I am close.但是,我对如何在不提供客户 ID 的情况下这样做感到非常困惑,尽管我认为我很接近。 I don't want to supply a customer ID since the purpose of this is to see who has been attempting to use the card.我不想提供客户 ID,因为这样做的目的是查看谁一直在尝试使用该卡。 Please point out the error of my ways because I can't find any documentation anywhere that suggests what I am doing wrong.请指出我的方式的错误,因为我在任何地方都找不到任何表明我做错了什么的文档。 It's a lot of payment processing examples, no filtering like I'm trying to do, and the API documentation doesn't explain how to filter "deeper".这是很多支付处理示例,没有像我试图做的过滤,而且 API 文档没有解释如何过滤“更深”。

Here's the function I am currently using:这是我目前使用的功能:

private StripeList<Charge> GetCardCharges(string card_id)
        {
            Dictionary<string, object> dict = new Dictionary<string, object> { { "source.fingerprint", card_id } };
            ChargeListOptions options = new ChargeListOptions { Limit = 100, ExtraParams = dict, };
            var service = new ChargeService();
            var charges = service.List(options);
            return charges;
        }

I have even tried我什至尝试过

Dictionary<string, object> dict = new Dictionary<string, object> { { "source", new Dictionary<string, object> { { "fingerprint", card_id } } } };

and have used an IDictionary instead and I still keep getting an unknown parameter message.并使用 IDictionary 代替,但我仍然不断收到未知参数消息。 Without the extra parameters it works fine in that it pulls 100 charge events, but that isn't very useful to me and writing a function that looks at every charge event ever seems inefficient.如果没有额外的参数,它可以正常工作,因为它可以提取 100 个充电事件,但这对我来说不是很有用,并且编写一个查看每个充电事件的函数似乎效率低下。 I am of course able to successfully filter from the "initial level" parameters in the JSON object, such as:我当然能够从 JSON 对象中的“初始级别”参数中成功过滤,例如:

Dictionary<string, object> dict = new Dictionary<string, object> { { "amount_refunded", 0 } };

I thank you in advanced for at least reading over this, and let me know if more information is needed!我提前感谢您至少阅读了这篇文章,如果需要更多信息,请告诉我! Here's a charge event from the test data for reference:以下是测试数据中的充电事件,供参考:

<Stripe.Charge@26602077 id=ch_1Hnzaj2eZvKYlo2CYBG4aWb4> JSON: {
  "id": "ch_1Hnzaj2eZvKYlo2CYBG4aWb4",
  "object": "charge",
  "amount": 100,
  "amount_captured": 0,
  "amount_refunded": 0,
  "application": null,
  "application_fee": null,
  "application_fee_amount": null,
  "authorization_code": null,
  "balance_transaction": null,
  "billing_details": {
    "address": {
      "city": null,
      "country": null,
      "line1": null,
      "line2": null,
      "postal_code": null,
      "state": null
    },
    "email": null,
    "name": null,
    "phone": null
  },
  "calculated_statement_descriptor": null,
  "captured": false,
  "created": 1605501925,
  "currency": "usd",
  "customer": null,
  "description": "My First Test Charge (created for API docs)",
  "destination": null,
  "dispute": null,
  "disputed": false,
  "failure_code": null,
  "failure_message": null,
  "fraud_details": {
    "stripe_report": null,
    "user_report": null
  },
  "invoice": null,
  "level3": null,
  "livemode": false,
  "metadata": {},
  "on_behalf_of": null,
  "order": null,
  "outcome": null,
  "paid": true,
  "payment_intent": null,
  "payment_method": "pm_1Hnzae2eZvKYlo2CZvrXwBjh",
  "payment_method_details": {
    "ach_credit_transfer": null,
    "ach_debit": null,
    "acss_debit": null,
    "alipay": null,
    "au_becs_debit": null,
    "bacs_debit": null,
    "bancontact": null,
    "card": {
      "brand": "visa",
      "checks": {
        "address_line1_check": null,
        "address_postal_code_check": null,
        "cvc_check": "pass"
      },
      "country": "US",
      "description": null,
      "exp_month": 8,
      "exp_year": 2021,
      "fingerprint": "Xt5EWLLDS7FJjR1c",
      "funding": "credit",
      "iin": null,
      "installments": null,
      "issuer": null,
      "last4": "4242",
      "moto": null,
      "network": "visa",
      "three_d_secure": null,
      "wallet": null
    },
    "card_present": null,
    "eps": null,
    "fpx": null,
    "giropay": null,
    "ideal": null,
    "interac_present": null,
    "klarna": null,
    "multibanco": null,
    "oxxo": null,
    "p24": null,
    "sepa_debit": null,
    "stripe_account": null,
    "type": "card",
    "wechat": null
  },
  "receipt_email": null,
  "receipt_number": null,
  "receipt_url": "https://pay.stripe.com/receipts/acct_1032D82eZvKYlo2C/ch_1Hnzaj2eZvKYlo2CYBG4aWb4/rcpt_IOnBY5JhICLngxEzCsH1wb609egY5bR",
  "refunded": false,
  "refunds": {
    "object": "list",
    "data": [],
    "has_more": false,
    "url": "/v1/charges/ch_1Hnzaj2eZvKYlo2CYBG4aWb4/refunds"
  },
  "review": null,
  "shipping": null,
  "source": {
    "id": "card_1Hnzae2eZvKYlo2CYAmFdjYF",
    "object": "card",
    "account": null,
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "available_payout_methods": null,
    "brand": "Visa",
    "country": "US",
    "currency": null,
    "customer": null,
    "cvc_check": "pass",
    "default_for_currency": null,
    "description": null,
    "dynamic_last4": null,
    "exp_month": 8,
    "exp_year": 2021,
    "fingerprint": "Xt5EWLLDS7FJjR1c",
    "funding": "credit",
    "iin": null,
    "issuer": null,
    "last4": "4242",
    "metadata": {},
    "name": null,
    "tokenization_method": null
  },
  "source_transfer": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "status": "succeeded",
  "transfer": null,
  "transfer_data": null,
  "transfer_group": null
}

ExtraParams is used to pass in parameters that aren't available natively in the SDK. ExtraParams用于传入 SDK 本身不可用的参数。 The main use case is for beta features that haven't made it into the SDK yet.主要用例是尚未加入 SDK 的测试版功能。

You can't use ExtraParams to filter on a specific parameter in a List endpoint, your only options are what's documented in the API ref: https://stripe.com/docs/api/charges/list您不能使用ExtraParams过滤 List 端点中的特定参数,您唯一的选择是 API ref 中记录的内容: https : //stripe.com/docs/api/charges/list

In your case you'd have to list all Charges and filter them yourself by looking at charge.payment_method_details.card.fingerprint在您的情况下,您必须列出所有费用并通过查看charge.payment_method_details.card.fingerprint

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM