Created
January 17, 2017 15:54
-
-
Save fernandobandeira/0fff5123bdfe171d41b2d3d2d33867a3 to your computer and use it in GitHub Desktop.
Payment
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
/* Submit do form */ | |
handleSubmit(); | |
function handleSubmit() { | |
$('#formPayment').one('submit', function(e) { | |
$('#senderHash').val(PagSeguroDirectPayment.getSenderHash()); | |
if ($('.nav-tabs .active').prop('id') == 'presCredit_card') { | |
e.preventDefault(); | |
if ($('#installments').val() == 'Escolha a forma de parcelamento') { | |
displayError('Escolha a forma de parcelamento.'); | |
handleSubmit(); | |
} else { | |
getCreditCardToken(); | |
} | |
} else if ($('.nav-tabs .active').prop('id') == 'presOnline_debit') { | |
if ($('input[name=bankName]:checked').val() === undefined) { | |
e.preventDefault(); | |
displayError('Escolha um banco para prosseguir com a opção Débito Online.'); | |
handleSubmit(); | |
} | |
} | |
}); | |
} | |
function getCreditCardToken() { | |
var options = { | |
cardNumber: $('input[name=card_number]').val(), | |
cvv: $('input[name=cvv]').val(), | |
expirationMonth: $('input[name=expiration_month]').val(), | |
expirationYear: 20+$('input[name=expiration_year]').val(), | |
success: function(response) { | |
token = response['card']['token']; | |
$('#creditCardToken').val(token); | |
$('#formPayment').submit(); | |
}, | |
error: function(response) { | |
handleSubmit(); | |
displayError(response); | |
} | |
}; | |
if(brand !== undefined) { | |
options['brand'] = brand['name']; | |
} | |
PagSeguroDirectPayment.createCardToken(options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment