c# - BraintreePayments API 查询给定日期的交易
问题描述
我正在尝试使用 BraintreePayments API .NET SDK 查询 Braintree Gateway 中的交易。
文档中有一条注释说:
https://developers.braintreepayments.com/reference/request/transaction/search/dotnet
“时间值中指定的时区将在搜索中得到尊重;如果您未指定时区,则搜索将默认为与您的网关帐户关联的时区。结果将始终以 UTC 时间值返回”
如何在搜索请求 API 调用中指定它?
var searchRequest = new TransactionSearchRequest().
CreatedAt.GreaterThanOrEqualTo(DateTime.Now.AddDays(-1));
ResourceCollection<Transaction> results = gateway.Transaction.Search(searchRequest);
解决方案
全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系 支持人员。
根据Microsoft .NET 文档,您可以使用该ConvertTime(DateTime, TimeZoneInfo)
方法将 DateTime 对象从您的时区转换为不同的时区。
您可以进行如下操作:
// Retrieve the time zone for Eastern Standard Time (U.S. and Canada).
TimeZoneInfo est;
try {
est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
}
catch (TimeZoneNotFoundException) {
Console.WriteLine("Unable to retrieve the Eastern Standard time zone.");
return;
}
catch (InvalidTimeZoneException) {
Console.WriteLine("Unable to retrieve the Eastern Standard time zone.");
return;
}
//Create a converted time zone DateTime object
DateTime targetTime = TimeZoneInfo.ConvertTime(timeToConvert, est);
//Run search request
var searchRequest = new TransactionSearchRequest().
CreatedAt.GreaterThanOrEqualTo(targetTime.AddDays(-1));
推荐阅读
- python - PyTorch:损失保持不变
- progressive-web-apps - 移动设备上的 Phaser PWA 扩展问题
- azure - 在 Azure Databricks 中反序列化事件中心消息
- git - git 中提交的 sed/grep 标记
- c - gcc 编译器报告警告,但 a.out 工作顺利,否则
- hadoop - Cucumber-Hadoop:如何从 HDFS 位置读取黄瓜特征文件?
- c# - 使用 MIMEKIT 使用数字证书对纯文本文件进行签名和加密
- java - 在 Visual Studio Code 中启动 Java 语言服务器卡在 37%
- javascript - HTML5画布:角度> 2 PI的逆时针弧
- c++ - 基于返回类型的转换和过载扣除