Skip to content

Instantly share code, notes, and snippets.

@wallynm
Created October 31, 2018 04:46
Show Gist options
  • Save wallynm/410e1b022abc5f2bbde627a5c11192c4 to your computer and use it in GitHub Desktop.
Save wallynm/410e1b022abc5f2bbde627a5c11192c4 to your computer and use it in GitHub Desktop.
LoadPaymentMethod(function(Checkout, Methods) {
var method = this
var PagseguroDebit = new Methods.Transparent.DebitPayment({
name: 'Pagseguro',
scripts: 'https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js',
onSubmit: function(formData) {
console.info('Submitted Debit Pagseguro: ', formData)
},
onScriptLoad: function() {
console.info('onScriptLoad -> External script loaded with success')
}
})
var PagseguroCredit = new Methods.Transparent.CreditPayment({
name: 'Pagseguro',
scripts: 'https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js',
getBrand: function(cardnumber, callback) {
var self = this;
PagSeguroDirectPayment.getBrand({
cardBin: cardnumber,
success: function(response) {
callback('success', response)
},
error: function(response) {
callback('error', response)
}
});
},
onSubmit: function(formData) {
PagSeguroDirectPayment.onSenderHashReady(function(response){
if(response.status == 'error') {
console.log(response.message);
return false;
}
var hash = response.senderHash; //Hash estará disponível nesta variável.
});
}
})
var Modal = new Methods.ModalPayment({
name: 'Pagseguro',
scripts: 'https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.lightbox.js',
onSubmit: function(data) {
PagSeguroLightbox({
code: data.code
}, {
success: function(data){
Checkout.successHandler()
},
abort: function(data){
Checkout.successHandler()
}
})
},
onScriptLoad: function() {
console.info('onScriptLoad -> External script loaded with success')
}
})
Checkout.addMethod(PagseguroCredit)
Checkout.addMethod(PagseguroDebit)
Checkout.addMethod(Modal)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment