';
}
self::$printResultCounter++;
echo '
';
if ($objectId) {
echo "
" . ($objectName ? $objectName : "Object") . " with ID: $objectId
";
}
echo '
Request Object
';
self::printObject($request);
echo 'Response Object
';
self::printObject($response, $errorMessage);
echo '';
echo '
Request Object
';
self::printObject($request) ;
echo 'Response Object
';
self::printObject($response, $errorMessage);
echo '
';
}
flush();
}
/**
* Prints success response HTML Output to web page.
*
* @param string $title
* @param string $objectName
* @param string $objectId
* @param mixed $request
* @param mixed $response
*/
public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null)
{
self::printOutput($title, $objectName, $objectId, $request, $response, false);
}
/**
* Prints Error
*
* @param $title
* @param $objectName
* @param null $objectId
* @param null $request
* @param \Exception $exception
*/
public static function printError($title, $objectName, $objectId = null, $request = null, $exception = null)
{
$data = null;
if ($exception instanceof \PayPal\Exception\PayPalConnectionException) {
$data = $exception->getData();
}
self::printOutput($title, $objectName, $objectId, $request, $data, $exception->getMessage());
}
protected static function printConsoleObject($object, $error = null)
{
if ($error) {
echo 'ERROR:'. $error;
}
if ($object) {
if (is_a($object, 'PayPal\Common\PayPalModel')) {
/** @var $object \PayPal\Common\PayPalModel */
echo $object->toJSON(128);
} elseif (is_string($object) && \PayPal\Validation\JsonValidator::validate($object, true)) {
echo str_replace('\\/', '/', json_encode(json_decode($object), 128));
} elseif (is_string($object)) {
echo $object;
} else {
print_r($object);
}
} else {
echo "No Data";
}
}
protected static function printObject($object, $error = null)
{
if ($error) {
echo '
'.
$error.
'
';
}
if ($object) {
if (is_a($object, 'PayPal\Common\PayPalModel')) {
/** @var $object \PayPal\Common\PayPalModel */
echo '
' . $object->toJSON(128) . "
";
} elseif (is_string($object) && \PayPal\Validation\JsonValidator::validate($object, true)) {
echo '
'. str_replace('\\/', '/', json_encode(json_decode($object), 128)) . "
";
} elseif (is_string($object)) {
echo '
' . $object . '
';
} else {
echo "
";
print_r($object);
echo "
";
}
} else {
echo "
No Data";
}
}
}
/**
* ### getBaseUrl function
* // utility function that returns base url for
* // determining return/cancel urls
*
* @return string
*/
function getBaseUrl()
{
if (PHP_SAPI == 'cli') {
$trace=debug_backtrace();
$relativePath = substr(dirname($trace[0]['file']), strlen(dirname(dirname(__FILE__))));
echo "Warning: This sample may require a server to handle return URL. Cannot execute in command line. Defaulting URL to http://localhost$relativePath \n";
return "http://localhost" . $relativePath;
}
$protocol = 'http';
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) {
$protocol .= 's';
}
$host = $_SERVER['HTTP_HOST'];
$request = $_SERVER['PHP_SELF'];
return dirname($protocol . '://' . $host . $request);
}