How do I make this text format from JWT Response in PHP Object into a nice print_r format in HTML.
I've tried
//Pretty format plain-text to HTML.
$message = preg_replace("\n\r?\n", "</p><p>", htmlspecialchars($message));
as it was suggested in another plain-text to HTML converstion topic here on stackoverflow. It completely doesn't return anything to $message and send's a empty body in the email.
Here is the current code:
<?php
require_once ('myprivatekeys.php');
//JWT class to encode/decode payload into JWT format. */
include_once "googlecheckout/JWT.php";
// From: http://stackoverflow.com/a/11225015/270712
$response = isset($HTTP_RAW_POST_DATA) ?
$HTTP_RAW_POST_DATA : file_get_contents("php://input");
$response = substr_replace($response, "", 0, 4); //remove "jwt=" from raw http data
$response = JWT::decode($response, $MerchantSecretKey);
print_r($response->response->orderId);
$subject = "Google Order Transaction waiting to be charged!";
$message = print_r($response, true);
$message .= "<br><B>Google Order waiting to be charged.</B>";
//Pretty format plain-text to HTML.
$message = preg_replace("\n\r?\n", "</p><p>", htmlspecialchars($message));
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
// More headers
$headers .= "From: <[email protected]>\r\n";
// send mail
mail($emailTo,$subject,$message,$headers);
?>
Here is how the email currently is on a successful order in Google Wallet.
stdClass Object ( [iss] => Google [request] => stdClass Object ( [description] => Private [name] => Buy 2123 [price] => 1592.25 [currencyCode] => USD ) [response] => stdClass Object ( [orderId] => GWDG_S.c2b69e16-30a0-4578-ab6c-b89acb1fc9bf ) [typ] => google/payments/inapp/item/v1/postback/buy [aud] => 04183051302638724136 [iat] => 1404407507 [exp] => 1404407527 )
Google Order waiting to be charged.
Okay you can't visualize it here in this question i'll post a screenshot.
P.S.> If there is nothing I can do in 1 line I'll end up doing like,
(I don't want to take this path since it's dangerous the variables could change at any time and I will lose orders due to merchant server errors !!!)
Is there a way to iterate the whole JWT response for all variables and loop them somehow?
$message .="currencyCode => ". $response->currencyCode . "<BR>";
$message .="Typ => ". $response->response->typ. "<BR>";
etc.. etc..