/**
 * Test Http functions.
 */
function test_functions()
{
    http_cache_last_modified();
    http_chunked_decode();
    http_deflate();
    http_inflate();
    http_build_cookie();
    http_date();
    http_get_request_body_stream();
    http_get_request_body();
    http_get_request_headers();
    http_match_etag();
    http_match_modified();
    http_match_request_header();
    http_support();
    http_negotiate_charset();
    http_negotiate_content_type();
    http_negotiate_language();
    ob_deflatehandler();
    ob_etaghandler();
    ob_inflatehandler();
    http_parse_cookie();
    http_parse_headers();
    http_parse_message();
    http_parse_params();
    http_persistent_handles_clean();
    http_persistent_handles_count();
    http_persistent_handles_ident();
    http_get();
    http_head();
    http_post_data();
    http_post_fields();
    http_put_data();
    http_put_file();
    http_put_stream();
    http_request_body_encode();
    http_request_method_exists();
    http_request_method_name();
    http_request_method_register();
    http_request_method_unregister();
    http_request();
    http_redirect();
    http_send_content_disposition();
    http_send_content_type();
    http_send_data();
    http_send_file();
    http_send_last_modified();
    http_send_status();
    http_send_stream();
    http_throttle();
    http_build_str();
    http_build_url();
}
Example #2
0
	 and in XML as stem of the DOCYPE SYSTEM attribute or as stem of the xmlns:xsi root element
	 attribute.

 - CONTENT : Content of the document to process (in case of a POST request the content can be
	alternatevely specified as HTTP request body).
*/
try {
    $sslpath = "./SSL";
    $sslopt = array("local_cert" => "{$sslpath}/combinedcert.pem", "verify_peer" => false);
    $cmd = NULL;
    if (array_key_exists("CMD", $_REQUEST)) {
        $cmd = $_REQUEST['CMD'];
    }
    $body = $_REQUEST['CONTENT'];
    if ($body == NULL && $_SERVER['REQUEST_METHOD'] == 'POST') {
        $body = http_get_request_body();
    }
    $authopt = array("mech" => "NONE", "username" => "gunibert", "password" => "bork123");
    $conn = new Session("127.0.0.1", 7962, $sslopt, $authopt);
    if (($result = $conn->request($cmd, $body)) === FALSE) {
        echo "<html><head><title>FAILED</title></head><body>" . $conn->lasterror() . "</body></html>";
    } else {
        echo "<html><head><title>RESULT</title></head><body><p>" . $result . "</p></body></html>";
    }
    unset($conn);
} catch (\Exception $e) {
    echo "<html><head><title>ERROR</title></head><body>" . $e->getMessage() . "</body></html>";
}
?>

Example #3
0
 private static function initialize($server = true, $data = false)
 {
     if ($data) {
         if (!self::$xmlreq && !(self::$xmlreq = http_get_request_body())) {
             throw new Exception("Failed to fetch XMLRPC request body");
         }
     }
     if ($server) {
         if (!self::$xmlrpc && !(self::$xmlrpc = xmlrpc_server_create())) {
             throw new Exception("Failed to initialize XMLRPC server");
         }
         ++self::$refcnt;
     }
 }
 public function executePaste($id, $view = '', $ini = 'development')
 {
     $paste_dir = '/code';
     $jail_dir = '/opt/codepad';
     if (!$view) {
         $view = 'html_body';
     }
     $file = "{$paste_dir}/{$id}";
     if (file_exists("{$jail_dir}/{$file}")) {
         $gearman = new GearmanClient();
         $gearman->addServer();
         $paste = DataObject::get_one('Paste', 'Filename = \'' . Convert::raw2SQL($id) . '\'');
         if (!$paste) {
             echo 'Paste not found';
             die;
         }
         $func = $paste->PHPVersion()->FuncName;
         $options['path'] = $file;
         $options['headers'] = $this->emu_getallheaders();
         $query = $_GET;
         unset($query['url']);
         $query = http_build_query($query);
         $options['query_string'] = $query;
         $options['method'] = $_SERVER['REQUEST_METHOD'];
         // Attempt 1 of 3 - Fetch request body from STDIN via php://input
         $options['body'] = file_get_contents('php://input');
         if ($_SERVER['CONTENT_LENGTH'] > 0 && !$options['body']) {
             // Attempt 2 of 3 - Fetch request body via PECL_HTTP extension
             $options['body'] = http_get_request_body();
             // Attempt 3 of 3 - Reconstruct request body from $_POST and $_FILES
             if (!$options['body']) {
                 list($mime, $boundary) = explode('boundary=', $_SERVER['CONTENT_TYPE']) + array('', '');
                 if ($boundary) {
                     foreach ($_POST as $name => $value) {
                         $options['body'] .= "--{$boundary}\r\nContent-Disposition: form-data; name=\"{$name}\"\r\n\r\n{$value}\r\n";
                     }
                     foreach ($_FILES as $name => $file) {
                         $content = '||BASE64-BINARY||' . base64_encode(file_get_contents($file['tmp_name'])) . '||BASE64-BINARY||';
                         $type = $file['type'];
                         $length = $file['size'];
                         $origname = $file['name'];
                         $options['body'] .= "--{$boundary}\r\nContent-Disposition: form-data; name=\"{$name}\"; filename=\"{$origname}\"\r\nContent-Type: {$type}\r\nContent-Length: {$length}\r\nContent-Transfer-Encoding: binary\r\n\r\n{$content}\r\n";
                     }
                     $options['body'] .= "--{$boundary}";
                 }
             }
         }
         $options['ini'] = $ini;
         switch ($view) {
             case 'request_headers':
                 echo '<pre>';
                 foreach ($options['headers'] as $header => $value) {
                     echo "{$header}: {$value}\r\n";
                 }
                 echo '</pre>';
                 die;
             case 'request_body':
                 echo $options['body'];
                 die;
             case 'opcodes':
                 $func = 'VLD';
                 //						$options['version'] = $paste->PHPVersion()->Path;
                 break;
             case 'profile':
                 echo 'Not yet implemented';
                 die;
             case 'call_graph':
                 echo 'Not yet implemented';
                 die;
         }
         $res = $gearman->do($func, json_encode($options));
         $result = (array) json_decode($res);
         if (empty($result['headers'])) {
             // No headers, treat as error response
             if (!empty($result['errors'])) {
                 echo $result['errors'];
                 die;
             }
             if (strpos($result['body'], 'timelimit: sending warning signal 15') !== FALSE) {
                 var_dump($result);
                 echo "Time limit exceeded.";
             } elseif ($view != 'opcodes') {
                 echo "Invalid HTTP Response from server, received:<br/>\n<pre>";
                 var_dump($res);
                 echo "</pre>";
                 die;
             }
         }
         $headers = base64_decode($result['headers']);
         $body = base64_decode($result['body']);
         switch ($view) {
             case 'html_body':
                 foreach (explode("\r\n", $headers) as $header) {
                     header($header);
                 }
                 echo $body;
                 die;
             case 'response_body':
                 echo "<pre>{$body}</pre>";
                 die;
             case 'response_headers':
                 echo "<pre>{$headers}</pre>";
                 die;
             case 'opcodes':
                 echo "<pre>{$body}</pre>";
                 die;
             case 'profile':
                 echo 'Not yet implemented';
                 die;
             case 'call_graph':
                 echo 'Not yet implemented';
                 die;
             default:
                 echo 'Unknown view type';
                 die;
         }
     } else {
         return FALSE;
     }
 }
<?php

$request_headers = http_get_request_headers();
$dataType = isset($request_headers["X-File-Type"]) ? $request_headers["X-File-Type"] : "image/jpg";
echo "data:" . $dataType . ";base64," . base64_encode(http_get_request_body());
Example #6
0
 /**
  * Create from global environment
  *
  * @return static
  */
 public static function globals()
 {
     static $globals;
     if (!$globals) {
         $globals = new static(Uri::current());
         $globals->servers =& $_SERVER;
         $globals->envs =& $_ENV;
         $globals->values =& $_POST;
         $globals->cookies =& $_COOKIE;
         $globals->accept = Request\Accept::from($globals->server('HTTP_ACCEPT'), $globals->server('HTTP_ACCEPT_LANGUAGE'), $globals->server('HTTP_ACCEPT_ENCODING'), $globals->server('HTTP_ACCEPT_CHARSET'));
         $globals->method = $globals->server('REQUEST_METHOD');
         $globals->secure = $globals->server('HTTPS') == 'on';
         $globals->ajax = $globals->server('HTTP_X_REQUESTED_WITH') && strtolower($globals->server('HTTP_X_REQUESTED_WITH')) == 'xmlhttprequest';
         $globals->root = dirname($globals->server('SCRIPT_FILENAME'));
         $globals->root = rtrim($globals->root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         if (function_exists('http_response_code')) {
             $globals->code = http_response_code();
         }
         if (function_exists('http_get_request_body')) {
             $globals->body = http_get_request_body();
         }
         if (function_exists('apache_request_headers')) {
             $globals->headers = apache_request_headers();
         }
         foreach ($_FILES as $index => $file) {
             $globals->files[$index] = new Request\File($file);
         }
         $globals->cli = php_sapi_name() === 'cli';
         $globals->agent = $globals->server('HTTP_USER_AGENT');
         $globals->ip = $globals->server('REMOTE_ADDR');
         $globals->time = $globals->server('REQUEST_TIME');
     }
     return $globals;
 }
 public function actionQueryProgress()
 {
     $model = new QueryProgress();
     $request = http_get_request_body();
     //$request = json_encode(array("deviceID"=>"56:78:3D:E5:8F:N1","order"=>1));
     //var_dump($request);
     $model->decodeStatusRequest($request);
     $model->getStatusOrder();
     $response = $model->encodeMsg();
     //var_dump($response);
     HttpResponse::status(200);
     HttpResponse::setContentType('application/json');
     HttpResponse::setData($response);
     HttpResponse::send();
 }
 public function __construct($getBody = false)
 {
     // set some headers
     $this->headers['Content-Encoding'] = 'UTF8';
     //header('Content-type: text/plain');
     //header('Cache-Control: no-cache, must-revalidate');
     // get the rest path
     $full_path = me();
     if ($full_path) {
         $path = $full_path;
         $pos = strripos($full_path, '.php');
         if ($pos > 1) {
             $path = substr($full_path, $pos + 4);
             $path = trim($path, '/ ');
             // trim whitespace and slashes
         }
         if (stripos($path, '?')) {
             $qloc = stripos($path, '?');
             $this->query = trim(substr($path, $qloc), '?');
             $path = substr($path, 0, $qloc);
         }
         $this->path = $path;
     }
     // get the body
     if ($getBody) {
         if (function_exists('http_get_request_body')) {
             $this->body = http_get_request_body();
         } else {
             if (defined('STDIN')) {
                 $this->body = @stream_get_contents(STDIN);
             } else {
                 // Moodlerooms does not allow use of php://input
                 //  $this->body = @file_get_contents('php://input');
                 // cannot get the body
                 $this->setHeader('NO_BODY', 'Cannot retrieve request body content');
                 $this->body = null;
             }
         }
     }
     // allow for method overrides
     $current_method = $_SERVER['REQUEST_METHOD'];
     if (isset($_REQUEST[self::COMPENSATE_METHOD])) {
         $comp_method = $_REQUEST[self::COMPENSATE_METHOD];
         if (!empty($comp_method)) {
             // Allows override to GET or DELETE
             $comp_method = strtoupper(trim($comp_method));
             if ('GET' == $comp_method) {
                 $current_method = 'GET';
             } else {
                 if ('DELETE' == $comp_method) {
                     $current_method = 'DELETE';
                 } else {
                     if ('POST' == $comp_method) {
                         $current_method = 'POST';
                     }
                 }
             }
         }
     }
     $this->method = $current_method;
 }
<?php

require_once 'HTTP/Request2/Response.php';
//echo "Hello there you are now connected to the canteen web server <br />";
/*HttpResponse::status(200);
HttpResponse::setContentType('json');
//HttpResponse::setHeader('From', 'Lymber');
HttpResponse::setData($_POST);
HttpResponse::send();*/
$connection = Yii::app()->db;
$sql_select = 'SELECT *   FROM menu';
$command = $connection->createCommand($sql_select);
$menuData = $command->query();
$row = $menuData->readAll();
$json_string = json_encode(array("updated" => "false", 'menu:' => $row));
$headers = http_get_request_headers();
$result = http_get_request_body();
$decodeResult = json_decode($result);
HttpResponse::status(200);
HttpResponse::setContentType('application/json');
//HttpResponse::setHeader('From', 'Lymber');
HttpResponse::setData($json_string);
HttpResponse::send();
flush();
Example #10
0
 /**
  * Build the request using the (super) global variables.
  * 
  * @uses http_get_request_headers()
  * @uses http_get_request_body()
  * 
  * @return \Phpf\Request
  */
 public static function createFromGlobals()
 {
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
     $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
     // Set request path
     if (isset($_SERVER['PATH_INFO'])) {
         $uri = urldecode($_SERVER['PATH_INFO']);
     } else {
         $uri = urldecode($_SERVER['REQUEST_URI']);
         // Remove query string from path
         if (false !== ($qpos = strpos($uri, '?'))) {
             $uri = substr($uri, 0, $qpos);
         }
     }
     $headers = http_get_request_headers();
     // Set request body data as per RFC 3875 4.2, 4.3
     if ('HEAD' === $method || 'POST' === $method && empty($headers['content-length'])) {
         // HEAD requests have no body - ha!
         // POST requests must have content-length
         $data = array();
     } else {
         if ('POST' === $method && isset($headers['content-type']) && 'multipart/form-data' === $headers['content-type']) {
             // Use php://input except for POST with enctype="multipart/form-data"
             // @see {@link http://us3.php.net/manual/en/wrappers.php.php}
             $data = $_POST;
         } else {
             parse_str(http_get_request_body(), $data);
         }
     }
     return new static($method, $uri, $query, $headers, $data, $_COOKIE, $_FILES);
 }
Example #11
0
    function do_process()
    {
        $action = ym_request('action');
        if ($action == 'js') {
            header('Content-Type: text/javascript');
            ?>
jQuery(document).ready(function() {
	jQuery('.ym_stripe_button').click(function(event) {
		event.preventDefault();

		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="purchase_code"]').val(jQuery(this).parents('form').find('input[name="item_number"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="email"]').val(jQuery(this).parents('form').find('input[name="email"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="cost"]').val(jQuery(this).parents('form').find('input[name="cost"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="return_to"]').val(jQuery(this).parents('form').find('input[name="return_to"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="coupon"]').val(jQuery(this).parents('form').find('input[name="coupon"]').val());

		jQuery('.ym_form').slideUp();
		jQuery('#ym_stripe_cc_form').slideDown();
	});

	Stripe.setPublishableKey('<?php 
            echo $this->api_key;
            ?>
');
	jQuery('#<?php 
            echo $this->code;
            ?>
_cc_form').live('submit', function(event) {
		event.preventDefault();
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_button').attr('disabled', 'disabled');
		jQuery('#<?php 
            echo $this->code;
            ?>
_error_handler').slideUp();
		Stripe.createToken({
			number: jQuery('#credit_card_number').val(),
			cvc: jQuery('#credit_card_cvc').val(),
			exp_month: jQuery('#expire_number_month').val(),
			exp_year: jQuery('#expire_number_year').val()
		}, stripeResponseHandler);
	});
});
function stripeResponseHandler(status, response) {
	if (response.error) {
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_button').removeAttr('disabled');
		jQuery('#<?php 
            echo $this->code;
            ?>
_error_handler').html(response.error.message + '<br />').slideDown();
	} else {
		var token = response['id'];
		jQuery('.ym_wipeme').each(function() {
			jQuery(this).val('');
		});
		jQuery('#<?php 
            echo $this->code;
            ?>
_cc_form').slideUp();
		jQuery('#<?php 
            echo $this->code;
            ?>
_status').slideDown();
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_button').attr('disabled', 'disabled');
		jQuery('<input type="hidden" name="stripeToken" value="' + token + '" />').appendTo('#<?php 
            echo $this->code;
            ?>
_submit_form');
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').submit();
	}
}

jQuery(document).ready(function() {
	var stripebuynowtarget = '.<?php 
            echo $this->code;
            ?>
_post_purchase_button';
	var stripedoforms = false;
	if (!jQuery(stripebuynowtarget).size()) {
		stripebuynowtarget = '.<?php 
            echo $this->code;
            ?>
_bundle_purchase_button';
		stripedoforms = true;
	}
	jQuery(stripebuynowtarget).click(function(event) {
		event.preventDefault();

		if (stripedoforms) {
			jQuery('.ym_form').slideUp();
		}

		jQuery('<?php 
            echo $this->code;
            ?>
_cc_form').slideUp(function() {
			jQuery(this).remove();
		});

		var purchase_code = jQuery(this).parents('form').find('input[name="item_number"]').val();
		var email = jQuery(this).parents('form').find('input[name="email"]').val();
		var cost = jQuery(this).parents('form').find('input[name="cost"]').val();
		var return_to = jQuery(this).parents('form').find('input[name="return_to"]').val();

		jQuery(this).parents('.<?php 
            echo $this->code;
            ?>
_ppp_holder').slideUp(function() {
			jQuery(this).html(
				'<form action="" method="post" id="<?php 
            echo $this->code;
            ?>
_cc_form" class="like_form" autocomplete="off">'
				+ '<fieldset>'
				+ '<div id="<?php 
            echo $this->code;
            ?>
_error_handler" style="display: none;"></div>'
				+ '<label for="credit_card_number"><?php 
            _e('Credit Card Number', 'ym');
            ?>
<br /><input type="text" name="credit_card_number" id="credit_card_number" class="ym_wipeme" /></label><br />'
				+ '<label for="credit_card_cvc"><?php 
            _e('Credit Card CCV', 'ym');
            ?>
<br /><input type="text" name="credit_card_cvc" id="credit_card_cvc" class="ym_wipeme" /></label><br />'
				+ '<label for="expiration">Expiration (MM/YYYY)<br /><input type="text" size="2" maxlength="2" name="expire_number_month" id="expire_number_month" class="ym_wipeme" /> / <input type="text" size="4" maxlength="4" name="expire_number_year" id="expire_number_year" class="ym_wipeme" /></label><br />'
				+ '<br /><input type="submit" id="<?php 
            echo $this->code;
            ?>
_submit_button" value="<?php 
            _e('Pay', 'ym');
            ?>
" />'
				+ '</fieldset>'
				+ '</form>'
				+ '<form action="<?php 
            echo site_url('?ym_process=' . $this->code . '&action=start');
            ?>
" method="post" id="<?php 
            echo $this->code;
            ?>
_submit_form" style="display: none;">'
				+ '<input type="hidden" name="purchase_code" value="' + purchase_code + '" />'
				+ '<input type="hidden" name="email" value="' + email + '" />'
				+ '<input type="hidden" name="cost" value="' + cost + '" />'
				+ '<input type="hidden" name="return_to" value="' + return_to + '" />'
				+ '<div id="<?php 
            echo $this->code;
            ?>
_status" style="display: none;"><?php 
            _e('Loading', 'ym');
            ?>
</div>'
				).slideDown();
		});
	});
});
<?php 
            exit;
        } else {
            if ($action == 'start') {
                $charge = FALSE;
                $code = ym_post('purchase_code', FALSE);
                $token = ym_post('stripeToken', FALSE);
                $email = ym_post('email');
                if (!$token || !$code) {
                    echo '<p>An Error Occurred (a)</p>';
                    exit;
                } else {
                    list($buy, $what, $id, $user_id) = explode('_', $code);
                    // plan ID Not to contain user ID
                    $plan_id = $buy . '_' . $what . '_' . $id;
                    if ($what == 'subscription') {
                        $pack = ym_get_pack_by_id($id);
                        if ($pack['num_cycles'] != 1) {
                            // test plan exist
                            $r = $this->sync_packages($plan_id);
                            if (!$r) {
                                echo '<p>An Error Occurred in Sync</p>';
                                exit;
                            }
                            // got this far Go for Subscribe
                            $subscribe = array('card' => $token, 'plan' => $plan_id, 'email' => $email);
                            // trial check
                            if ($pack['trial_on'] == 1) {
                                // trial
                                $cost_check = $pack['trial_cost'] * 100;
                                if ($cost_check) {
                                    // paid for trial
                                    // issue charge
                                    $charge = array('amount' => $cost_check, 'currency' => 'usd', 'description' => 'Trial: ' . $plan_id);
                                }
                            }
                            // coupon?
                            if ($pack['cost'] != ym_post('cost')) {
                                // coupon in use
                                // nasty
                                $coupon = ym_post('coupon', FALSE);
                                if ($coupon) {
                                    $test = $this->sync_coupons(substr($coupon, 3));
                                    if ($test) {
                                        $subscribe['coupon'] = $coupon;
                                    } else {
                                        echo '<p>Coupon Sync Failed</p>';
                                        exit;
                                    }
                                } else {
                                    // or hacking attempt
                                    echo '<p>Unable to Match Coupon</p>';
                                    exit;
                                }
                            }
                            // check for customer exist
                            $create = TRUE;
                            $customer_id = get_user_meta($user_id, 'ym_stripe_customer_id', TRUE);
                            if ($customer_id) {
                                list($r_code, $response) = $this->stripe_api_request('customers/' . $customer_id);
                                if ($r_code == 200) {
                                    // check response
                                    if (isset($response->deleted) && $response->deleted == 1) {
                                        // deleted
                                    } else {
                                        // exists
                                        $create = FALSE;
                                    }
                                }
                            }
                            if ($create) {
                                list($r_code, $response) = $this->stripe_api_request('customers', 'POST', $subscribe);
                                // store ID
                                if ($r_code == 200) {
                                    update_user_meta($user_id, 'ym_stripe_customer_id', $response->id);
                                }
                            } else {
                                // update
                                $subscribe['prorate'] = $this->prorate;
                                unset($subscribe['email']);
                                //email not accepted for sub change
                                list($r_code, $response) = $this->stripe_api_request('customers/' . $customer_id . '/subscription', 'POST', $subscribe);
                            }
                            if ($r_code == 200) {
                                // leave to IPN for Prorate and/or start
                                if (ym_post('return_to', FALSE)) {
                                    header('Location: ' . ym_post('return_to'));
                                    exit;
                                }
                                $this->redirectlogic($pack, TRUE);
                                exit;
                            } else {
                                echo '<p>An Error Occurred (d: ' . $r_code . ': ' . $response->error->message . ')</p>';
                            }
                            exit;
                        } else {
                            // single occurrence subscription
                            $charge = array('amount' => ym_post('cost', 0) * 100, 'currency' => 'usd', 'description' => $plan_id);
                        }
                    } else {
                        //if ($what == 'post' || $what == 'bundle') {
                        // post
                        // TODO: temporary hack
                        $charge = array('amount' => ym_post('cost', 0) * 100, 'currency' => 'usd', 'description' => $plan_id);
                        //				} else {
                        // unknown purchase!!!!
                    }
                    // single charge
                    if ($charge) {
                        // customer exist?
                        $create = TRUE;
                        $customer_id = get_user_meta($user_id, 'ym_stripe_customer_id', TRUE);
                        if ($customer_id) {
                            list($r_code, $response) = $this->stripe_api_request('customers/' . $customer_id);
                            if ($r_code == 200) {
                                // check response
                                if (isset($response->deleted) && $response->deleted == 1) {
                                    // deleted
                                } else {
                                    // exists
                                    $create = FALSE;
                                }
                            }
                        }
                        if ($create) {
                            $customer = array('card' => $token, 'email' => $email);
                            list($r_code, $response) = $this->stripe_api_request('customers', 'POST', $customer);
                            // store ID
                            if ($r_code == 200) {
                                update_user_meta($user_id, 'ym_stripe_customer_id', $response->id);
                                $customer_id = $response->id;
                            }
                        }
                        if ($customer_id) {
                            // commence charge
                            $charge['customer'] = $customer_id;
                            list($r_code, $response) = $this->stripe_api_request('charges', 'POST', $charge);
                            if ($r_code == 200) {
                                if ($response->paid == 1) {
                                    $this->common_process($code, $charge['amount'], TRUE, FALSE);
                                    if ($what == 'post') {
                                        $pack = array('ppp' => 1, 'post_id' => $id);
                                    } else {
                                        if ($what == 'bundle') {
                                            $pack = array('ppp' => 1, 'ppp_pack_id' => $id);
                                        } else {
                                            $pack = $id;
                                        }
                                    }
                                    if (ym_post('return_to', FALSE)) {
                                        header('Location: ' . ym_post('return_to'));
                                        exit;
                                    }
                                    $this->redirectlogic($pack, TRUE);
                                } else {
                                    echo 'Failed';
                                }
                            } else {
                                echo '<p>An Error Occurred (f: ' . $r_code . ': ' . $response->error->message . ')</p>';
                            }
                        } else {
                            echo '<p>An Error Occurred (e: ' . $r_code . ': ' . $response->error->message . ')</p>';
                        }
                    }
                }
                exit;
            } else {
                if ($action == 'process') {
                    // process a web hook
                    if (function_exists('http_get_request_body')) {
                        $payload = http_get_request_body();
                    } else {
                        $payload = @file_get_contents('php://input');
                    }
                    $_REQUEST = json_decode($payload, TRUE);
                    // stash for YM_IPN Array
                    $payload = json_decode($payload);
                    if (!$payload) {
                        header('HTTP/1.1 400 Bad Request');
                        echo 'Error in IPN. No Data Recieved';
                    } else {
                        $this->packet = $payload;
                        list($type, $result) = explode('.', $payload->type, 2);
                        $escape_types = array('ping', 'plan');
                        $escape_results = array('created', 'customer.updated');
                        if (in_array($type, $escape_types) || in_array($result, $escape_results)) {
                            echo 'ohai';
                            exit;
                        }
                        $complete = FALSE;
                        $customer_id = isset($payload->data->object->customer) ? $payload->data->object->customer : '';
                        $email = isset($payload->data->object->email) ? $payload->data->object->email : '';
                        $code = isset($payload->data->object->lines->subscriptions[0]->plan->id) ? $payload->data->object->lines->subscriptions[0]->plan->id : '';
                        $cost = isset($payload->data->object->lines->subscriptions[0]->amount) ? $payload->data->object->lines->subscriptions[0]->amount : '';
                        global $wpdb;
                        $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = \'ym_stripe_customer_id\' AND meta_value = \'' . $customer_id . '\'');
                        if (!$user_id && $email) {
                            $user = get_user_by('email', $email);
                            $user_id = $user->ID;
                        }
                        if (!$user_id) {
                            // fail user match
                            echo 'OK';
                            exit;
                        }
                        if ($type == 'invoice') {
                            $cost = $payload->data->object->lines->subscriptions[0]->amount / 100;
                            //fron cents to dollars
                            $invoice_id = $payload->data->object->id;
                            if ($result == 'payment_succeeded') {
                                $complete = TRUE;
                            }
                            if ($complete) {
                                $code = $payload->data->object->lines->subscriptions[0]->plan->id;
                                list($buy, $what, $id) = explode('_', $code);
                                $last_invoice_id = get_user_meta($user_id, 'ym_last_stripe_id', TRUE);
                                if ($last_invoice_id == $invoice_id) {
                                    // double complete packet.....
                                    header('HTTP/1.1 200 OK');
                                    echo 'Double Packet';
                                    exit;
                                }
                                update_user_meta($user_id, 'ym_last_stripe_id', $invoice_id);
                                update_user_meta($user_id, 'ym_stripe_customer_id', $customer_id);
                            }
                            // append User ID to the code
                            $code .= '_' . $user_id;
                        } else {
                            if ($type == 'customer' && $result == 'deleted') {
                                // customer deleted
                                $cost = 0;
                                $complete = FALSE;
                                $code = $code ? $code . '_' . $user_id : 'buy_subscription_cancel_' . $user_id;
                                delete_user_meta($user_id, 'ym_stripe_customer_id');
                            }
                        }
                        // ignore anything else
                        if ($code && strlen($cost)) {
                            $this->common_process($code, $cost, $complete);
                        } else {
                            // skippy the bush kagaroo
                            header('HTTP/1.1 200 OK');
                            echo 'ok';
                            exit;
                        }
                    }
                } else {
                    echo '<p>
			An Error Has Occured
			<br />
			And the Payment Flow has exited abnormally
			</p><p>Debug Information</p>';
                    echo '<pre>' . print_r($_REQUEST) . '</pre>';
                    exit;
                }
            }
        }
    }
Example #12
0
 /**
 Handle a webhook
 */
 function catchWebHook()
 {
     if (function_exists('http_get_request_body')) {
         $data = http_get_request_body();
     } else {
         $data = @file_get_contents('php://input');
     }
     $data = json_decode($data);
     $gc_signature_string = $data->payload->signature;
     unset($data->payload->signature);
     $my_signature_string = $this->generateSignatureFromString($this->to_query($data->payload));
     if ($my_signature_string != $gc_signature_string) {
         return FALSE;
     }
     $resource_type = $data->payload->resource_type;
     $load = $resource_type . 's';
     return array('action' => $data->payload->action, 'resource' => $resource_type, 'resources' => $data->payload->{$load});
 }
Example #13
0
    if (substr($zipped, $offset, 1) == "") {
        # file_put_contents("tmp.gz", substr($zipped, $offset - 2));
        return gzinflate(substr($zipped, $offset + 8));
    }
    return "Unknown Format";
}
$text = '';
$uri = (string) $_GET['URI'];
$server = var_export($_SERVER, true);
$post = var_export($_POST, true);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $METHOD = 'POST';
    $POST_CONTENT = http_get_request_body();
    //  $POST_CONTENT = http_build_query($_POST);
    //$POST_CONTENT = urlencode(http_get_request_body());
    write_log("\n\nPOST RAW: " . var_export(http_get_request_body(), true) . "\n\n\n");
    $text = '!!!NOW POST!!!';
} else {
    $METHOD = 'GET';
}
// caching request for future processing
if ($_SERVER['SERVER_PORT'] == 443) {
    $text .= ' !!! HTTPS';
} else {
    $text .= " !!! PLAIN";
}
$get = var_export($_GET, true);
$text .= "\n\nuri:{$uri}\n\nserver:{$server}\n\n\nget:{$get}\n\n\npost:{$post}\n\npost_content:" . var_export($POST_CONTENT, true) . "\n\noriginal_headers:" . var_export($headers, true) . "\n\n";
//var_dump($headers);
$url = "http" . ($_SERVER['SERVER_PORT'] == 443 ? 's' : '') . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$urlInfo = @parse_url($url);
        $offset = 2;
    }
    if (substr($zipped, $offset, 1) == "") {
        # file_put_contents("tmp.gz", substr($zipped, $offset - 2));
        return gzinflate(substr($zipped, $offset + 8));
    }
    return "Unknown Format";
}
$text = '';
$uri = (string) $_GET['URI'];
$server = var_export($_SERVER, true);
$post = var_export($_POST, true);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $METHOD = 'POST';
    if (preg_match('/inAppBuy/', $_SERVER['REQUEST_URI']) || preg_match('/verifyReceipt/', $_SERVER['REQUEST_URI'])) {
        $POST_CONTENT = http_get_request_body();
    } else {
        $POST_CONTENT = http_build_query($_POST);
    }
    //$POST_CONTENT = urlencode(http_get_request_body());
    // //fwrite($file,"\n\nPOST RAW: ".var_export(http_get_request_body(),true)."\n\n\n");
    $text = '!!!NOW POST!!!';
} else {
    $METHOD = 'GET';
}
// caching request for future processing
if (!PROXY) {
    if (preg_match('/offerAvailabilityAndInfoDialog/', $_SERVER['REQUEST_URI'])) {
        $to_db_get = explode(',', 'restrictionLevel,id,versionId,guid,quantity,offerName,lang,bid,bvrs,icuLocale');
        foreach ($to_db_get as $gv) {
            if ($gv == 'id') {
 /**
  * Get the body of a POST or PUT.
  *
  * Used for fetching the post parameters and to calculate the body signature.
  *
  * @return string		null when no body present (or wrong content type for body)
  */
 public function getRequestBody()
 {
     if ($this->_rawBody === null) {
         $body = null;
         if ($this->getContentType() == 'multipart/form-data') {
             $body = \function_exists("http_get_request_body") ? http_get_request_body() : @$_POST[0];
         } else {
             if ($this->request->getMethod() == 'POST' || $this->request->getMethod() == 'PUT') {
                 $body = '';
                 $fh = @fopen('php://input', 'r');
                 if ($fh) {
                     while (!feof($fh)) {
                         $s = fread($fh, 1024);
                         if (is_string($s)) {
                             $body .= $s;
                         }
                     }
                     fclose($fh);
                 }
             }
         }
         $this->_rawBody = $body;
     }
     return $this->_rawBody;
 }