如何使用Stripe API更新客户发票明细

时间:2019-01-31 07:47:06

标签: c# .net stripe-payments

我要更新客户发票详细信息,详细信息如下图所示

enter image description here

我已经研究过,文档说使用此代码更新了象牙

StripeConfiguration.SetApiKey("sk_test_hi3LvqzVUrxrlBwqdFukAK4Q");

var options = new CustomerUpdateOptions {
  Description = "Customer for jenny.rosen@example.com"
};

var service = new CustomerService();
Customer customer = service.Update("cus_EQL4cC8XJAO4YJ", options);

此代码可以正常工作,但是当我尝试使用CustomerUpdateOptions进行更新时,例如Address Line 1 我在此类中找不到此属性

    [JsonProperty("account_balance")]
    public int? AccountBalance { get; set; }
    [JsonProperty("business_vat_id")]
    public string BusinessVatId { get; set; }
    [JsonProperty("source")]
    public string SourceToken { get; set; }
    [JsonProperty("source")]
    public SourceCard SourceCard { get; set; }
    [JsonProperty("coupon")]
    public string Coupon { get; set; }
    [JsonProperty("default_source")]
    public string DefaultSource { get; set; }
    [JsonProperty("description")]
    public string Description { get; set; }
    [JsonProperty("email")]
    public string Email { get; set; }
    [JsonProperty("metadata")]
    public Dictionary<string, string> Metadata { get; set; }

我在CustomerUpdateOptions中拥有的所有属性均如上所述。 如何更新图片中指定的其他字段?

1 个答案:

答案 0 :(得分:1)

如果您在Stripe仪表板上提交更改,则会看到以下请求正文

{
  "account_balance": "0",
  "description": "Customer for Testing",
  "invoice_prefix": "KarenPrefix",
  "shipping": {
    "phone": "+12016262852",
    "name": "",
    "address": {
      "line1": "",
      "line2": "",
      "city": "",
      "state": "",
      "postal_code": "",
      "country": ""
    }
  },
  "tax_info": {
    "tax_id": "",
    "type": "vat"
  },
  "invoicing": {
    "email_to": [
      "test@test.com"
    ],
    "email_cc": [
      "test2@test.com"
    ]
  }
}

因此它映射到条纹API doc中显示的请求正文。

`Cu​​stomerUpdateOptions如下所示,请参阅doc

namespace Stripe
{
    using System;
    using System.Collections.Generic;
    using Newtonsoft.Json;

    public class CustomerUpdateOptions : BaseOptions
    {
        [JsonProperty("account_balance")]
        public long? AccountBalance { get; set; }

        [JsonProperty("coupon")]
        public string Coupon { get; set; }

        [JsonProperty("default_source")]
        public string DefaultSource { get; set; }

        [JsonProperty("description")]
        public string Description { get; set; }

        [JsonProperty("email")]
        public string Email { get; set; }

        [JsonProperty("invoice_prefix")]
        public string InvoicePrefix { get; set; }

        [JsonProperty("metadata")]
        public Dictionary<string, string> Metadata { get; set; }

        [JsonProperty("shipping")]
        public ShippingOptions Shipping { get; set; }

        [JsonProperty("source")]
        public string SourceToken { get; set; }

        [JsonProperty("source")]
        public CardCreateNestedOptions SourceCard { get; set; }

        [JsonProperty("tax_info")]
        public CustomerTaxInfoOptions TaxInfo { get; set; }

        [JsonProperty("validate")]
        public bool? Validate { get; set; }
    }
} 

因此,您将设置ShippingOptions来更新address.line1

希望有帮助