Reputation: 825
I am trying to query transactions in Braintree Gateway using BraintreePayments API .NET SDK.
There is a note in the documentation which says:
https://developers.braintreepayments.com/reference/request/transaction/search/dotnet
"Time zones specified in the time value will be respected in the search; if you do not specify a time zone, the search will default to the time zone associated with your gateway account. Results will always be returned with time values in UTC"
How can this be specified in the search request API call?
var searchRequest = new TransactionSearchRequest().
CreatedAt.GreaterThanOrEqualTo(DateTime.Now.AddDays(-1));
ResourceCollection<Transaction> results = gateway.Transaction.Search(searchRequest);
Upvotes: 0
Views: 690
Reputation: 69
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
According to Microsoft .NET docs, you can use the ConvertTime(DateTime, TimeZoneInfo)
method to convert your DateTime object from your time zone to a different time zone.
You could proceed as follows:
// 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));
Upvotes: 5