Created
June 18, 2016 15:48
-
-
Save damianesteban/35d7e5468b6a1010ea036820754fe7f9 to your computer and use it in GitHub Desktop.
Braintree Release from Escrow after 48 hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new Date Object. | |
const today = new Date(); | |
// releases a transaction from escrow via the transaction id. | |
function releaseFromEscrow(transactionId) { | |
gateway.transaction.releaseFromEscrow(transactionId, (err, result) => { | |
if (err) { | |
console.log(`Error releasing transaction - ${err}`); | |
} | |
console.log(`Transaction released - ${result}`); | |
}); | |
} | |
console.log(`Searching gateway for transactions created at least two days ago - ${today.getDate() - 2}`); | |
// Performs a search for transactions that were created at least two days ago. | |
gateway.transaction.search((search) => { | |
search.createdAt().max(today.getDate() - 2); | |
}, (err, response) => { | |
response.each((error, transaction) => { | |
if (transaction.escrowStatus === 'held') { | |
releaseFromEscrow(transaction.id); | |
console.log(`Transaction released from escrow: ${transaction.id}`); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just noticed that
today.getDate() - 2
is an integer rather than a date. That might be a problem iftoday.getDate() == 1
, because subtracting two will give a negative number. Also,max
might not be properly comparing thecreatedAt
date with the integer.Maybe instead we should import moment.js, and do something like: