How can I tell whether or not a charge has been batched?
We can compare the captured_at property (charge.captured_at) with the most recent batch time. Here is an example using 11:59 EST:
const capturedAt = new Date(charge.captured_at);
const now = new Date();
// Note: we need this conditional to deal with charges that occur between 11:59PM
// and 12:00AM
const batchTime = now.getUTChours === 18 && now.getMinutes === 59 ? (
new Date()
.setUTCHours(18, 59, 0, 0); // 18:59:00 represents a 11:59 EST batch time
) : (
new Date()
.setDate(date.getDate() - 1);
.setUTCHours(18, 59, 0, 0);
);
const hasBatched = capturedAt > batchTime;
For more information about batch times, see here.