Created
March 13, 2018 15:41
-
-
Save murilohns/8a5aa1608a6b4ac24ae60c0521244105 to your computer and use it in GitHub Desktop.
updateRecipient in Pagar.me with js
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
const pagarme = require('pagarme') | |
const api_key = 'SUA_CHAVE_DE_API'; | |
bank_account_1 = { | |
bank_code: '987', | |
agencia: '9876', | |
agencia_dv: '9', | |
conta: '98765', | |
conta_dv: '9', | |
legal_name: 'Primeira conta bancaria', | |
document_number: '26268738888' | |
}; | |
bank_account_2 = { | |
bank_code: '123', | |
agencia: '1234', | |
agencia_dv: '1', | |
conta: '12345', | |
conta_dv: '1', | |
legal_name: 'Nova conta bancaria', | |
document_number: '26268738888' | |
} | |
function createRecipient (callback) { | |
pagarme.client.connect({ api_key: api_key }) | |
.then(client => client.recipients.create({ | |
bank_account: bank_account_1, | |
transfer_interval: 'weekly', | |
transfer_day: 5, | |
transfer_enabled: true | |
})) | |
.then(recipient => { | |
console.log("Recebedor criado! ") | |
showRecipient(recipient) | |
callback(recipient) | |
}) | |
} | |
function updateRecipient (myRecipient) { | |
pagarme.client.connect({ api_key: api_key }) | |
.then(client => client.recipients.update({ | |
id: myRecipient.id, | |
bank_account: bank_account_2 | |
})) | |
.then(recipient => { | |
console.log("Recebedor atualizado! ") | |
showRecipient(recipient); | |
}) | |
.catch(err => | |
console.log(JSON.Stringify(err))); | |
} | |
function showRecipient(recipient) { | |
console.log(recipient); | |
} | |
console.log(createRecipient(updateRecipient)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment