针对给定日期的BraintreePayments API查询事务

问题描述 投票:0回答:1

我正在尝试使用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
1个回答
5
投票

完全披露:我在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));  
© www.soinside.com 2019 - 2024. All rights reserved.