首页 > 解决方案 > 如何使用 stripe api 更新客户发票详细信息

问题描述

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

在此处输入图像描述

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

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都是上面提到的。如何更新图片中指定的其他字段?

标签: c#.netstripe-payments

解决方案


If you submit your changes on Stripe dashboard, you would see the following request body

{
  "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"
    ]
  }
}

So it maps to the request body shown in Stripe API doc.

The `CustomerUpdateOptions looks likes the following, refer to 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; }
    }
} 

So you would set the ShippingOptions to update the address.line1

Hope it helps


推荐阅读