/
pagseguro_debito.tpl
120 lines (100 loc) · 3.71 KB
/
pagseguro_debito.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<style type="text/css">
a {cursor: pointer}
.overlay {height: 30px;width: 68px;background: #FFF;position: absolute;opacity: 0.7;}
.overlay:hover {opacity: 0;}
.vhide {display:none}
#button-confirm {margin-right: 40px}
</style>
<div class="content">
<div class="row-fluid">
<div class="alert alert-danger col-sm-12 vhide" id="warning" role="alert"></div>
<?php if (strlen($session_id) != 32) { ?>
<div class="alert alert-danger col-sm-12" id="warning" role="alert"><?php echo $session_id ?></div>
<?php exit(); } ?>
<div class="alert alert-info col-sm-12 vhide" id="info" role="alert">Aguarde...</div>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-4 control-label">Selecione seu banco</label>
<div id="bandeiras" class="col-sm-4"></div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">CPF:</label>
<div class="col-sm-4">
<input class="form-control" id="cpf" name="cpf" type="text" value="<?php echo $cpf ?>" />
<input id="bandeira" name="bandeira" type="hidden" />
</div>
</div>
<div class="form-group" id="button">
<div class="col-sm-4 col-sm-offset-4">
<a id="button-confirm" class="btn btn-primary" data-loading-text="Aguarde...">Confirmar</a>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
if (typeof(PagSeguroDirectPayment) == 'undefined') {
alert('Erro ao carregar javascript.\nAcesse http://www.valdeirsantana.com.br / Procure pelo módulo / Clique na aba FAQ para obter mais informações.');
}
PagSeguroDirectPayment.setSessionId('<?php echo $session_id ?>');
PagSeguroDirectPayment.getPaymentMethods({
success: function(bandeiras){
var cards = bandeiras.paymentMethods.ONLINE_DEBIT.options;
$.map(cards, function(e){
$('#bandeiras').append('<a class="pull-left" onClick="escolherBanco(\'' + e.name + '\')" id="' + e.name + '"><div class="overlay"></div><img src="https://stc.pagseguro.uol.com.br' + e.images.MEDIUM.path + '" /></a>');
});
$('#info').hide();
}
});
$('#button-confirm').click(function(){
var banco = $('input#bandeira').val();
var cpf = $('input#cpf').val();
if (cpf == '') {
$('#warning').html('Informe seu CPF').show();
} else if (banco == '') {
$('#warning').html('Informe a bandeira do seu banco').show();
} else {
$('#warning').empty().hide();
}
$.ajax({
url: 'index.php?route=extension/payment/pagseguro_debito/transition',
data: 'banco=' + banco.toLowerCase() + '&senderHash=' + PagSeguroDirectPayment.getSenderHash() + '&cpf=' + cpf,
type: 'POST',
dataType: 'JSON',
beforeSend: function() {
$('#info').show();
$('#button-confirm').button('loading');
},
success: function (json) {
if (json.error) {
$('#warning').html(json.error.message).show();
} else {
$('#button-confirm').hide().attr('disabled');
$('#button div').append('<a href="' + json.paymentLink + '" target="_blank" class="btn btn-success">Finalizar Pagametno</a>');
$.ajax({
url: 'index.php?route=extension/payment/pagseguro_debito/confirm',
data: 'status=' + json.status,
type: 'POST',
success: function (){
setTimeout(function(){
location.href = '<?php echo $continue ?>';
}, 5000);
}
})
}
},
complete: function(data) {
$('#info').hide();
}
})
})
function escolherBanco(banco) {
if (typeof(banco) == 'undefined') {
$('#warning').html('Selecione seu banco');
return;
}
$('input#bandeira').val(banco);
$('.overlay').css('opacity', '0.7');
$('#' + banco).find('.overlay').css('opacity', 0);
}
</script>