Created
December 7, 2018 18:40
-
-
Save mihaiserban/0673065002f305d1d83e97fa312f1206 to your computer and use it in GitHub Desktop.
braintree payments stream search transactions
This file contains hidden or 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
router.get('/payments', verifyJWT_MW, function(req, res) { | |
try { | |
let transactions = []; | |
const stream = Braintree.gateway.transaction.search(function(search) { | |
search.customerId().is(req.user.account.braintreeCustomerId); | |
}); | |
stream.on('ready', function() { | |
console.log(stream.searchResponse.length()); | |
}); | |
stream.on('data', function(transaction) { | |
transactions.push({ | |
title: 'Topup Credit', | |
id: transaction.id, | |
status: transaction.status, | |
amount: transaction.amount, | |
currency: transaction.currencyIsoCode, | |
createdAt: transaction.createdAt, | |
card: { | |
type: transaction.creditCard.cardType, | |
last4: transaction.creditCard.last4 | |
} | |
}); | |
}); | |
stream.on('error', function(e) { | |
throw e; | |
}); | |
stream.on('end', function() { | |
res.status(200).json({ | |
success: true, | |
message: 'Successfully retrieved transactions for account.', | |
data: transactions | |
}); | |
}); | |
} catch (error) { | |
res.status(500).json({ | |
success: false, | |
message: error.message | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment