PHP mail variable

the mail() function

Moderators: egami, macek, gesf

Post Reply
ogautier
New php-forum User
New php-forum User
Posts: 1
Joined: Thu May 07, 2020 2:33 pm

Thu May 07, 2020 2:44 pm

Hello, I´m sending an email using this code, but I can´t send the values of the $buyOrder and $amount variables.

Dou you have any suggestions?

Regards!

<?php

require_once './vendor/autoload.php';

use Transbank\Webpay\Configuration;
use Transbank\Webpay\Webpay;
?>
<h1>Repo</h1>

<?php


$emailcliente = 'xyz@gmail.com';
$emailempresa = 'xyz@gmail.com';


/** Configuracion parametros de la clase Webpay */
$sample_baseurl = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

$configuration = Configuration::forTestingWebpayPlusNormal();
$configuration = new Configuration();
$configuration->setEnvironment("PRODUCCION");
$configuration->setCommerceCode(); //Si el código que posees es de 8 dígitos debes anteponer 5970.
$configuration->setPublicCert("-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----");
$configuration->setPrivateKey("-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----");


/** Creacion Objeto Webpay */
$webpay = new Webpay($configuration);

$action = isset($_GET["action"]) ? $_GET["action"] : 'init';

$post_array = false;

switch ($action) {

default:

$tx_step = "Init";

/** Monto de la transacción */
//$amount = 9990;
$amount = $_POST['amount'];
/** Orden de compra de la tienda */
//$buyOrder = rand();
$buyOrder = $_POST['buyOrder'];



/** Código comercio de la tienda entregado por Transbank */
$sessionId = uniqid(555555555555);


/** URL de retorno */

//$urlReturn = 'https://www.reposteriaangeles.cl/return.php';
$urlReturn = $sample_baseurl."?action=getResult";

/** URL Final */
//$urlFinal = 'https://www.reposteriaangeles.cl/final.php';
$urlFinal = $sample_baseurl."?action=end";


$request = array(
"amount" => $amount,
"buyOrder" => $buyOrder,
"sessionId" => $sessionId,
"urlReturn" => $urlReturn,
"urlFinal" => $urlFinal,
);

/** Iniciamos Transaccion */
$result = $webpay->getNormalTransaction()->initTransaction($amount, $buyOrder, $sessionId, $urlReturn, $urlFinal);

/** Verificamos respuesta de inicio en webpay */
if (!empty($result->token) && isset($result->token)) {
$message = "Sesion iniciada con exito en Webpay";
$token = $result->token;
$next_page = $result->url;
} else {
$message = "webpay no disponible";
}

$button_name = "Continuar &raquo;";

break;

case "getResult":

$tx_step = "Get Result";

if (!isset($_POST["token_ws"]))
break;

/** Token de la transacción */
$token = filter_input(INPUT_POST, 'token_ws');

$request = array(
"token" => filter_input(INPUT_POST, 'token_ws')
);

/** Rescatamos resultado y datos de la transaccion */
$result = $webpay->getNormalTransaction()->getTransactionResult($token);

/** Verificamos resultado de transacción */
if ($result->detailOutput->responseCode === 0) {

/** propiedad de HTML5 (web storage), que permite almacenar datos en nuestro navegador web */
echo '<script>window.localStorage.clear();</script>';
echo '<script>localStorage.setItem("authorizationCode", '.$result->detailOutput->authorizationCode.')</script>';
echo '<script>localStorage.setItem("amount", '.$result->detailOutput->amount.')</script>';
echo '<script>localStorage.setItem("buyOrder", '.$result->buyOrder.')</script>';



$titulo = 'Pago www.sss.com por xxx ';
$mensaje = 'Se ha recibido un nuevo pago mediante el sitio web xxxxx por un monto de xxx para la orden de compra codigo xxxx ' .$buyOrder;
$cabeceras = 'From: ' . $emailcliente . "\r\n" .
'Reply-To: ' . $emailcliente . "\r\n" .
'X-Mailer: PHP/' . phpversion();


mail($emailempresa, $titulo, $mensaje, $cabeceras);



$message = "Pago ACEPTADO por webpay (se deben guardar datos para mostrar voucher)";
$next_page = $result->urlRedirection;

} else {
$message = "Pago RECHAZADO por webpay - " . utf8_decode($result->detailOutput->responseDescription);
$next_page = '';
}

$button_name = "Continuar &raquo;";

break;

case "end":

$post_array = true;

$tx_step = "End";
$request = "";
$result = $_POST;

$message = "Transacion Finalizada";
$next_page = $sample_baseurl."?action=nullify";
$button_name = "Anular Transacci&oacute;n &raquo;";

break;


case "nullify":

$tx_step = "nullify";

$request = $_POST;

/** Codigo de Comercio */
$commercecode = null;

/** Código de autorización de la transacción que se requiere anular */
$authorizationCode = filter_input(INPUT_POST, 'authorizationCode');

/** Monto autorizado de la transacción que se requiere anular */
$amount = filter_input(INPUT_POST, 'amount');

/** Orden de compra de la transacción que se requiere anular */
$buyOrder = filter_input(INPUT_POST, 'buyOrder');

/** Monto que se desea anular de la transacción */
$nullifyAmount = 200;

$request = array(
"authorizationCode" => $authorizationCode, // Código de autorización
"authorizedAmount" => $amount, // Monto autorizado
"buyOrder" => $buyOrder, // Orden de compra
"nullifyAmount" => $nullifyAmount, // idsession local
"commercecode" => $configuration->getCommerceCode(), // idsession local
);

$result = $webpay->getNullifyTransaction()->nullify($authorizationCode, $amount, $buyOrder, $nullifyAmount, $commercecode);

/** Verificamos resultado de transacción */
if (!isset($result->authorizationCode)) {
$message = "webpay no disponible";
} else {
$message = "Transaci&oacute;n Finalizada";
}

$next_page = '';

break;
}

echo "<h2>Step: " . $tx_step . "</h2>";

if (!isset($request) || !isset($result) || !isset($message) || !isset($next_page)) {

$result = "Ocurri&oacute; un error al procesar su solicitud";
echo "<div style = 'background-color:lightgrey;'><h3>result</h3>$result;</div><br/><br/>";
echo "<a href='../..'>&laquo; volver a index</a>";
die;
}

/* Respuesta de Salida - Vista WEB */
?>

<div style="background-color:lightyellow;">
<h3>request</h3>
<?php var_dump($request); ?>
</div>
<div style="background-color:lightgrey;">
<h3>result</h3>
<?php var_dump($result); ?>
</div>
<p><samp><?php echo $message; ?></samp></p>

<?php if (strlen($next_page) && $post_array) { ?>

<form action="<?php echo $next_page; ?>" method="post">
<input type="hidden" name="authorizationCode" id="authorizationCode" value="">
<input type="hidden" name="amount" id="amount" value="">
<input type="hidden" name="buyOrder" id="buyOrder" value="">
<input type="submit" value="<?php echo $button_name; ?>">
</form>

<script>

var authorizationCode = localStorage.getItem('authorizationCode');
document.getElementById("authorizationCode").value = authorizationCode;

var amount = localStorage.getItem('amount');
document.getElementById("amount").value = amount;

var buyOrder = localStorage.getItem('buyOrder');
document.getElementById("buyOrder").value = buyOrder;

localStorage.clear();

</script>

<?php } elseif (strlen($next_page)) { ?>
<form action="<?php echo $next_page; ?>" method="post">

<input type="hidden" name="token_ws" value="<?php echo ($token); ?>">
<input type="submit" value="<?php echo $button_name; ?>">
</form>
<?php } ?>

<br>
<a href="../..">&laquo; volver a index</a>
Post Reply