Saltar al contenido

button payments step 1

<?php
//I get the total values of the order
//Subtotal 0 is the sum of the subtotals of the products that do not tax VAT
$subtotal_order_0 = number_format(0, 2, '.', '');
//Subtotal 0 is the sum of the subtotals of the products that do tax VAT + the value of the Shipping (if applicable)
$subtotal_order_12 = number_format(8.93, 2, '.', '');
//Tax is the value of the tax from the Subtotal
$tax_order = number_format($subtotal_order_12*0.12, 2, '.', '');
//Total is the sum of the Subtotal + Tax
$total_order = number_format($subtotal_order_0+$subtotal_order_12+$tax_order, 2, '.', '');

//I assemble the products of my order
//Store Product ID
$products[0]['id'] = 01;
//Product name
$products[0]['nombre'] = 'Nombre del Producto';
//Value without TAX of the product
$products[0]['subtotal'] = 8.93;
// Product tax
$products[0]['tax'] = 1.07;
//Total product value
$products[0]['total'] = 10.00;
//Product quantity
$products[0]['cantidad'] = 1;

//Store internal order id can be alphajumeric
$order = "001";

//I assemble the array to send
$datos = array(
        'products' => json_encode($products),
        'total' => $total_order,
        'tax' => $tax_order,
        'subtotal12' => $subtotal_order_12,
        'subtotal0' => $subtotal_order_0, //Subtotal of products that do not tax VAT
        'email' => "[email protected]",
        'first_name' => "Primer Nombre Cliente",
        'last_name' => "Apellidos Cliente",
        'document' => "1717272354", //customer identity document
        'phone' => "2238930",//Customer phone
        'address' => "Dirección del cliente",
        'ip_address' => get_client_ip(),//Function with client IP
        'order_id' => $order,
        'shipping' => 1.00, //Shipping value without taxes
        'shipping_tax' => 0.12,//Value of the shipping tax, if there is a shipping value, the tax is mandatory by the Banks
        'gateway' => 'botonpagos',
        'status' => 'pending',
        'date' => date('Y-m-d'),
        'url_response' => 'https://prueba.com/resultado.php?order='.$order //This field is optional in the case of Mobile APPS
    );

//Address to ButtonPagos with the order details
$url = 'https://portal.botonpagos.com/api/datafast/setOrder?'.http_build_query($datos);
//Consultation via CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'code: ID del comercio'//ID provided by ButtonPagos
));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responseData = curl_exec($ch);
//If there is a connection error
if(curl_error($ch)){
    echo curl_error($ch);
}

curl_close($ch);
//Step to array the data obtained in Json
$responseData = json_decode($responseData, true);

/**
 * Function that allows to obtain the ip of the client making the payment
 * 
 * */
function get_client_ip() 
{
    $ipaddress = "";
    if (getenv("HTTP_CLIENT_IP"))
        $ipaddress = getenv("HTTP_CLIENT_IP");
    else if(getenv("HTTP_X_FORWARDED_FOR"))
        $ipaddress = getenv("HTTP_X_FORWARDED_FOR");
    else if(getenv("HTTP_X_FORWARDED"))
        $ipaddress = getenv("HTTP_X_FORWARDED");
    else if(getenv("HTTP_FORWARDED_FOR"))
        $ipaddress = getenv("HTTP_FORWARDED_FOR");
    else if(getenv("HTTP_FORWARDED"))
       $ipaddress = getenv("HTTP_FORWARDED");
    else if(getenv("REMOTE_ADDR"))
        $ipaddress = getenv("REMOTE_ADDR");
    else
        $ipaddress = "UNKNOWN";
    return $ipaddress;
}


?>
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>PayAgile</title>
  </head>
  
  <body>
     
    <div class="container">
      <div class="row">
        <div class="col-md-8 order-md-1">
            <!-- I call the Payment Button on my page -->
            <iframe src="https://portal.botonpagos.com/api/datafast/botonV3/<?= $responseData['code'] ?>" width="100%" style="height: 766px; border: none;"></iframe>
        </div>
      </div>
    </div>
  </body>
</html>