【问题标题】:BraintreePayments API Query Transactions for a given dateBraintreePayments API 查询给定日期的交易
【发布时间】:2019-08-02 14:21:52
【问题描述】:

我正在尝试使用 BraintreePayments API .NET SDK 查询 Braintree Gateway 中的交易。

文档中有一条说明:

https://developers.braintreepayments.com/reference/request/transaction/search/dotnet

“在搜索中将遵循时间值中指定的时区;如果您未指定时区,则搜索将默认为与您的网关帐户关联的时区。结果将始终以世界标准时间"

如何在搜索请求 API 调用中指定?

var searchRequest = new TransactionSearchRequest().
    CreatedAt.GreaterThanOrEqualTo(DateTime.Now.AddDays(-1));

ResourceCollection<Transaction> results = gateway.Transaction.Search(searchRequest);

【问题讨论】:

    标签: c# braintree


    【解决方案1】:

    全面披露:我在 Braintree 工作。如果您还有其他问题,请随时联系 support.

    根据Microsoft .NET docs,您可以使用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));  
    

    【讨论】:

    • Braintree 似乎没有考虑时区。它似乎使用 UTC 作为搜索查询的默认值。使用 API 的给定日期的事务计数与仪表板中显示的计数不匹配。我不得不搜索 var searchRequest = new TransactionSearchRequest().CreatedAt.Between(start, end);并将事务从 UTC 转换回以达到仪表板事务中显示的相同计数。Where(t => TimeZoneInfo.ConvertTimeFromUtc(t.CreatedAt.Value, cstZone).Date == (targetTime.AddDays(-1))跨度>
    猜你喜欢
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2021-11-26
    • 2020-11-17
    相关资源
    最近更新 更多