首页 > 解决方案 > 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);

标签: c#braintree

解决方案


全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系 支持人员

根据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));  

推荐阅读