<?php
$init = 1;
$telefone = preg_replace('/\D/', '',$phone_number);
if(strlen($telefone)==13){
$telefone = substr($telefone,-10);
}elseif(strlen($telefone)==12){
$telefone = substr($telefone,-10);
}elseif(strlen($telefone)==11 || strlen($telefone)==10){
$telefone = $telefone;
}else{
$telefone = '(00)00000000';
}
?>
<form action="https://cieloecommerce.cielo.com.br/Transactional/Order/Index" method="post" id="cielo_form">
<!-- detalhes -->
<input type="hidden" name="merchant_id" value="<?php echo $merchant_id;?>" />
<input type="hidden" name="order_number" value="<?php echo $pedido;?>" />
<input type="hidden" name="shipping_type" value="<?php echo $shipping_tipo_frete;?>" />
<?php if($frete && $frete['value']>0){?>
<input type="hidden" name="Shipping_Zipcode" value="<?php echo $shipping_postcode;?>" />
<?php } ?>
<input type="hidden" name="soft_descriptor" value="<?php echo $soft;?>">
<input type="hidden" name="Antifraud_enabled" value="<?php echo $fraude;?>">


<!-- itens -->
<?php foreach($produtos AS $produto){?>
<input type="hidden" name="cart_<?php echo $init;?>_name" value="<?php echo $produto['name'];?>" />
<input type="hidden" name="cart_<?php echo $init;?>_unitprice" value="<?php echo number_format($produto['price'], 2, '', '');?>" />
<input type="hidden" name="cart_<?php echo $init;?>_quantity" value="<?php echo $produto['quantity'];?>" />
<input type="hidden" name="cart_<?php echo $init;?>_type" value="3" />
<?php $init++; } ?>

<?php if($taxas && $taxas>0){?>
<!-- taxas -->
<input type="hidden" name="cart_<?php echo $init;?>_name" value="Taxas e Impostos" />
<input type="hidden" name="cart_<?php echo $init;?>_unitprice" value="<?php echo number_format($taxas, 2, '', '');?>" />
<input type="hidden" name="cart_<?php echo $init;?>_quantity" value="1" />
<input type="hidden" name="cart_<?php echo $init;?>_type" value="3" />
<?php $init++; ?>
<?php } ?>

<!-- descontos -->
<?php if($desconto>0){?>
<input type="hidden" name="discount_type" value="1">
<input type="hidden" name="discount_value" value="<?php echo number_format($desconto, 2, '', '');?>">
<?php } ?>


<!-- endereco frete -->
<?php if($frete && $frete['value']>0){?>
<input type="hidden" name="shipping_1_name"  value="<?php echo $frete['title'];?>" />
<input type="hidden" name="shipping_1_price" value="<?php echo number_format($frete['value'], 2, '', '');?>" />

<input type="hidden" name="Shipping_Address_Name"         value="<?php echo $shipping_address_1;?>" />
<input type="hidden" name="Shipping_Address_Number"       value="<?php echo $shipping_numero;?>" />
<input type="hidden" name="Shipping_Address_Complement"   value="<?php echo $shipping_complemento;?>" />
<input type="hidden" name="Shipping_Address_District"     value="<?php echo $shipping_address_2;?>" />
<input type="hidden" name="Shipping_Address_City"         value="<?php echo $shipping_city;?>" />
<input type="hidden" name="Shipping_Address_State"        value="<?php echo $shipping_zone;?>" />
<?php } ?>

<!-- cliente -->
<input type="hidden" name="Customer_Name"       value="<?php echo $firstname;?> <?php echo $lastname;?>" />
<input type="hidden" name="Customer_Identity"   value="<?php echo (strlen($fiscal)==11 || strlen($fiscal)==14)?$fiscal:'';?>" />
<input type="hidden" name="Customer_Phone"      value="<?php echo preg_replace('/\D/', '',$telefone);?>" />
<input type="hidden" name="Customer_Email"      value="<?php echo $email;?>" />
<div class="buttons">	
<div class="right">

<?php if($exibir_btn){ ?>
	<input type="submit" id="button-confirm" value="Concluir Pagamento Online" class="button btn btn-primary" />
<?php } ?>

</div>
</div>
</form>