我正在使用Stripe.Net来处理付款。当我开始测试"charge.refund“网页钩子时,我在代码后面得到了空发票属性,但是在Stripeweb钩子事件中存在发票值,并且我确认发票也是存在的仪表板。
注意到Stripe.Net中的版本和配置的webhook是不同的。
仪表板Web钩子API版本:2017-08-15
Stripe.Net版本: 16.12.0.0 (它支持2018-02-06)。
下面是Stripe webhook事件

这是破译代码(使用空引用的charge.Invoice.SubscriptionId中断)

以前有人遇到过这个问题吗?
谢谢
发布于 2018-07-21 18:19:36
// the ResponseJson on a list method is the entire list (as json) returned from stripe.
// the ObjectJson is so we can store only the json for a single object in the list on that entity for
// logging and/or debugging
public static T MapFromJson(string json, string parentToken = null, StripeResponse stripeResponse = null)
{
var jsonToParse = string.IsNullOrEmpty(parentToken) ? json : JObject.Parse(json).SelectToken(parentToken).ToString();
var result = JsonConvert.DeserializeObject<T>(jsonToParse);
// if necessary, we might need to apply the stripe response to nested properties for StripeList<T>
ApplyStripeResponse(json, stripeResponse, result);
return result;
}
public static T MapFromJson(StripeResponse stripeResponse, string parentToken = null)
{
return MapFromJson(stripeResponse.ResponseJson, parentToken, stripeResponse);
}
private static void ApplyStripeResponse(string json, StripeResponse stripeResponse, object obj)
{
if (stripeResponse == null)
{
return;
}
foreach (var property in obj.GetType().GetRuntimeProperties())
{
if (property.Name == nameof(StripeResponse))
{
property.SetValue(obj, stripeResponse);
}
}
stripeResponse.ObjectJson = json;
}它使用JSON.Net反序列化JSON,
事实是 attribute。
#region Expandable Invoice
/// <summary>
/// ID of the invoice this charge is for if one exists.
/// </summary>
public string InvoiceId { get; set; }
[JsonIgnore]
public StripeInvoice Invoice { get; set; }
[JsonProperty("invoice")]
internal object InternalInvoice
{
set
{
StringOrObject<StripeInvoice>.Map(value, s => this.InvoiceId = s, o => this.Invoice = o);
}
}
#endregion以及如何通过InternalInvoice映射StringOrObject<T>属性。
StringOrObject<StripeInvoice>.Map(value, s => this.InvoiceId = s, o => this.Invoice = o);您可以在类定义中看到
internal static class StringOrObject<T>
where T : StripeEntityWithId
{
public static void Map(object value, Action<string> updateId, Action<T> updateObject)
{
if (value is JObject)
{
T item = ((JToken)value).ToObject<T>();
updateId(item.Id);
updateObject(item);
}
else if (value is string)
{
updateId((string)value);
updateObject(null);
}
}
}如果传递的值是string,则将Invoice对象属性设置为null。
else if (value is string)
{
updateId((string)value);
updateObject(null);
}因此,您描述的行为是根据所显示的数据和代码设计的。
您可能需要提取InvoiceId并尝试检索它(发票)以使用其成员。
https://stackoverflow.com/questions/51458690
复制相似问题