Last active
February 8, 2018 17:13
-
-
Save murilohns/409ce9ac0d9a2cd1682ffcc719b70463 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Teste de Card Hash</title> | |
</head> | |
<body> | |
</body> | |
<script src="https://assets.pagar.me/pagarme-js/3.0/pagarme.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
var card = {} | |
card.card_holder_name = "Murilo Teste" | |
card.card_expiration_date = "1220" | |
card.card_number = "4242424242424242" | |
card.card_cvv = "123" | |
// pega os erros de validação nos campos do form e a bandeira do cartão | |
var cardValidations = pagarme.validate({card: card}) | |
//Então você pode verificar se algum campo não é válido | |
if(!cardValidations.card.card_number) | |
console.log('Oops, número de cartão incorreto') | |
console.log(cardValidations.card.brand); //Exibe a bandeira do cartão | |
//Mas caso esteja tudo certo, você pode seguir o fluxo | |
pagarme.client.connect({ encryption_key: 'ek_test_XrkRVobUGGTtvafcLGfoxPmNg5dnSD' }) | |
.then(client => | |
client.security.encrypt(card) | |
) | |
.then(card_hash => | |
console.log(card_hash) | |
) | |
// o próximo passo aqui é enviar o card_hash para seu servidor, e | |
// em seguida criar a transação/assinatura | |
return false | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment