Skip to content

Commit

Permalink
adiciona exemplo de criação de assinatura com cliente já existente
Browse files Browse the repository at this point in the history
  • Loading branch information
brenooliveira committed Aug 14, 2014
1 parent 447ec21 commit f43d8cc
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 8 deletions.
65 changes: 63 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="css/assinaturas-demo.css" rel="stylesheet">

<script type="text/javascript" src="https://sandbox.moip.com.br/moip-assinaturas.min.js"></script>
<script type="text/javascript" src="https://sandbox.moip.com.br/moip-assinaturas.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/assinaturas-demo.js"></script>
</head>
Expand Down Expand Up @@ -42,6 +42,7 @@ <h1>Moip Assinaturas</h1>
<div class="tabbable"> <!-- Only required for left/right tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Criar Assinatura</a></li>
<li><a href="#tab3" data-toggle="tab">Criar assinatura com Cliente já existente</a></li>
<li><a href="#tab2" data-toggle="tab">Atualizar cartão de crédito</a></li>
</ul>

Expand Down Expand Up @@ -213,7 +214,7 @@ <h1>Moip Assinaturas</h1>

<div class="tab-pane" id="tab2">
<legend>Atualizar cartão de cliente (<a href="#" id="carregar_dados_novo_cartao">Preencher dados de cartão</a>)</legend>

<div class="control-group">
<label class="control-label" for="customer_code">Código do cliente</label>
<div class="controls">
Expand Down Expand Up @@ -268,6 +269,66 @@ <h1>Moip Assinaturas</h1>
</div>
</form>
</div>

<!-- Criar assinatura com cliente já existente -->
<div class="tab-pane" id="tab3">
<legend>Criar assinatura com Cliente já existente (<a href="#" id="carregar_dados_novo_cartao">Preencher dados de cartão</a>)</legend>

<div class="control-group">
<label class="control-label" for="customer_code">Código do cliente</label>
<div class="controls">
<input id="existent_customer_code" maxlength="150" name="customer_code" placeholder="Código do seu cliente" type="text">
</div>
</div>
<legend>Novo cartão</legend>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" for="holder_name">Nome do Portador</label>
<div class="controls">
<input id="new_holder_name" maxlength="45" name="new_holder_name" placeholder="Nome escrito no cartão" type="text">
</div>
</div>

<div class="control-group">
<label class="control-label" for="credit_card">Número Cartão de Credito</label>
<div class="controls">
<input id="new_credit_card" maxlength="16" name="new_credit_card" placeholder="XXXXXXXXXXXX1234" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="credit_card">Data de Expiração</label>
<div class="controls">
<select name="new_expiration_month" id="new_expiration_month" class="input-mini">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12" selected="selected">12</option>
</select> / <select name="new_expiration_year" id="new_expiration_year" class="input-small">
<option value="14">2014</option>
<option value="15">2015</option>
<option value="16">2016</option>
<option value="17">2017</option>
<option value="18">2018</option>
<option value="19">2019</option>
<option value="20" selected="selected">2020</option>
</select>
</div>
</div>
<div class="form-actions">
<a href="#" class="btn btn-large btn-primary" id="subscribe_with_customer">Assinar</a>
</div>
</form>
</div>
<!-- Fim -->

</div>
</div>
</body>
Expand Down
44 changes: 38 additions & 6 deletions js/assinaturas-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $(document).ready(function(){
return;
}

var moip = new MoipAssinaturas(token);
var moip = new MoipAssinaturas(token);
var customer = build_customer();
var subscription_code = new Date().getTime(); // INFORME AQUI UM CÓDIGO PARA ESSA ASSINATURA

Expand Down Expand Up @@ -54,6 +54,38 @@ $(document).ready(function(){
});
});

$("#subscribe_with_customer").click(function(){
var token = $("#token").val(); // INFORME AQUI UM CÓDIGO DE UM PLANO SEU
var plan_code = $("#plan_code").val(); // INFORME AQUI UM CÓDIGO DE UM PLANO SEU
var moip = new MoipAssinaturas(token);

var customer = new Customer();
customer.code = $("#existent_customer_code").val();

moip.subscribe(
new Subscription()
.with_code(new Date().getTime())
.with_customer(customer)
.with_plan_code(plan_code)
).callback(function(response){
if (response.has_errors()) {
$("#erros").empty();
for (i = 0; i < response.errors.length; i++) {
var erro = response.errors[i].description;
$("#erros").append("<li>" + erro + "</li>");
$(".alert").fadeIn();
}
} else {
$("#to-show").removeClass("alert-error").addClass("alert-success").fadeIn();
$("#erros").empty().append("<li>Assinatura criado com sucesso</li>");
$("#erros").append("<li><strong>Próxima Cobrança:</strong> " + response.next_invoice_date.day + "/" + response.next_invoice_date.month + "/" + response.next_invoice_date.year + "</li>");
$("#erros").append("<li><strong>Status do pagamento:</strong> " + response.invoice.status.description + "</li>");
$("#erros").append("<li><strong>Status: </strong> " + response.status + "</li>")

}
});
});

$("#carregar_dados").click(function(){
fill_form();
});
Expand All @@ -80,10 +112,10 @@ var build_customer = function() {
}
return new Customer(customer_params);
};

var build_billing_info = function() {
var billing_info_params = {
fullname : $("#holder_name").val(),
fullname : $("#holder_name").val(),
expiration_month: $("#expiration_month").val(),
expiration_year: $("#expiration_year").val(),
credit_card_number: $("#credit_card").val()
Expand All @@ -93,14 +125,14 @@ var build_billing_info = function() {

var build_new_billing_info = function() {
var billing_info_params = {
fullname : $("#new_holder_name").val(),
fullname : $("#new_holder_name").val(),
expiration_month: $("#new_expiration_month").val(),
expiration_year: $("#new_expiration_year").val(),
credit_card_number: $("#new_credit_card").val()
};
return new BillingInfo(billing_info_params);
};

var build_address = function() {
var address_params = {
street: $("#rua").val(),
Expand Down Expand Up @@ -146,4 +178,4 @@ var fill_new_billing_info_form = function() {
$("#new_fullname").val("David Luis da Silva");
$("#new_holder_name").val("David L Silva");
$("#new_credit_card").val("4111111111111111");
};
};

0 comments on commit f43d8cc

Please sign in to comment.