我正在使用Stripe.Net来处理付款。当我开始测试“ charge.refund” webhook时,我在后面的代码中得到了NULL发票属性,但是Stripe webhook事件中存在发票值,并且我确认了发票也存在仪表板。
注意Stripe.Net中的版本和配置的webhook API不同。
仪表板Webhook API版本:2017-08-15
Stripe.Net版本:16.12.0.0(支持2018-02-06)。
这是Stripe Webhook事件
这是中断代码(charge.Invoice.SubscriptionId用空引用中断)
有人遇到过这个问题吗?
谢谢
参考方案
看着source code for the Stripe.Mapper<T>.MapFromJson
// 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,
StripeCharge.Invoice
property is marked with [JsonIgnore]
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
并尝试检索它(发票)以使用其成员。
可以是三进制么?二进制有什么好处?题解:为什么叫电子计算机?算盘应该没有二进制
LeetCode题解统计城市的所有灯泡这个是我刚毕业的时候,一个真实的面试题,这是一个开放题。题目描述:想办法,将一个城市的所有灯泡数量统计出来。题解:费米估算法1、如果某个城市常驻人口有1000万2、假设每5人居住在一套房里,每套房有灯泡5只,那么住宅灯泡共有1000万只3、假设公众场所每10人共享一只灯泡,那么共有100万只4、主要的这两者相加就得出了1100万只当然实际上这是估算的,具体应…
LeetCode题解黑白圆盘一个圆盘被涂上了黑白二色,两种颜色各占一个半圆。圆盘以一个未知的速度、按一个未知的方向旋转。你有一种特殊的相机可以让你即时观察到圆上的一个点的颜色。你需要多少个相机才能确定圆盘旋转的方向?题解:可以用一个相机即可
LeetCode题解圆上任取三点构成锐角三角形的概率来自字节跳动的一道几何题题解:1/4
LeetCode题解深度优先遍历和回溯的关系?深度优先遍历的范围更大还是回溯的范围更大?为什么?题解:我的理解是:dfs是回溯思想的一种体现- 回溯:是在整个搜索空间中搜索出可行解,在搜索过程中不断剪枝回退,这是回溯的思想,这个搜索空间并没有限制于特定的数据结构。- dfs:dfs是指特定的数据结构中如图,树(特殊的图)中搜索答案,范围限制在了特定的数据结构。个人拙见。