解码URL PayPal成功PHP

时间:2018-08-17 03:53:30

标签: php paypal

我正在尝试集成PayPal服务,几天前它可以与此代码一起使用

<?php 
$data=array(
'merchant_email'=>'sanjeev00733-facilitator@gmail.com',
'product_name'=>'Demo Product',
'amount'=>5.50,
'currency_code'=>'USD',
'thanks_page'=>"http://".$_SERVER['HTTP_HOST'].'/demo/paypal-payment-ipn/thank.php',
'notify_url'=>"http://".$_SERVER['HTTP_HOST'].'/demo/paypal-payment-ipn/ipn.php',
'cancel_url'=>"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
'paypal_mode'=>true
);  
if(isset($_POST['pay_now'])){
echo '<link rel="stylesheet" type="text/css" href="style.css" />';
echo '<div class="wait">PayPal is processing the payment, please wait...</div>';
echo '<div class="loader">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>';
echo infotutsPaypal($data);
}else{
?>
<html>
<title>Integrate PayPal Payment gateway in php - InfoTuts</title>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<div id="mhead"><h2>Integrate PayPal Payment gateway in PHP - <span class="red">Info</span>Tuts</h2></div>

<div id="product">
<form id='paypal-info' method='post' action='#'>
<label>Product Name : <?php echo $data['product_name']; ?></label></br>
<label>Product Price : <?php echo $data['amount'].''.$data['currency_code']; ?></label>

<input type='submit' name='pay_now' id='pay_now' value='Pay' />
</form>
</div>



</html>
<?php
}
    function infotutsPaypal( $data) {

            define( 'SSL_URL', 'https://www.paypal.com/cgi-bin/webscr' );
            define( 'SSL_SAND_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr' );

            $action = '';
            //Is this a test transaction? 
            $action = ($data['paypal_mode']) ? SSL_SAND_URL : SSL_URL;

            $form = '';

            $form .= '<form name="frm_payment_method" action="' . $action . '" method="post">';
            $form .= '<input type="hidden" name="business" value="' . $data['merchant_email'] . '" />';
            // Instant Payment Notification & Return Page Details /
            $form .= '<input type="hidden" name="notify_url" value="' . $data['notify_url'] . '" />';
            $form .= '<input type="hidden" name="cancel_return" value="' . $data['cancel_url'] . '" />';
            $form .= '<input type="hidden" name="return" value="' . $data['thanks_page'] . '" />';
            $form .= '<input type="hidden" name="rm" value="2" />';
            // Configures Basic Checkout Fields -->
            $form .= '<input type="hidden" name="lc" value="" />';
            $form .= '<input type="hidden" name="no_shipping" value="1" />';
            $form .= '<input type="hidden" name="no_note" value="1" />';
            // <input type="hidden" name="custom" value="localhost" />-->
            $form .= '<input type="hidden" name="currency_code" value="' . $data['currency_code'] . '" />';
            $form .= '<input type="hidden" name="page_style" value="paypal" />';
            $form .= '<input type="hidden" name="charset" value="utf-8" />';
            $form .= '<input type="hidden" name="item_name" value="' . $data['product_name'] . '" />';
            $form .= '<input type="hidden" value="_xclick" name="cmd"/>';
            $form .= '<input type="hidden" name="amount" value="' . $data['amount'] . '" />';

            $form .= '</form>';
            $form .= '<script>';
            $form .= 'setTimeout("document.frm_payment_method.submit()", 0);';
            $form .= '</script>';
            return $form;
        }

但是由于一个原因,它不再起作用了,所以我更改了所有代码,并以此做

<?php
//get logged in user ID from sesion
$loggedInUserID = $_SESSION["id"];

//PayPal variables
$paypalURL     = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$paypalID     = 'facilitator@hotmail.com';
$successURL = 'http://localhost/final/FrontEnd/success';
$cancelURL     = 'http://localhost/final/FrontEnd/inicio';
$notifyURL     = 'http://localhost/final/FrontEnd/ipn';

$itemName = 'Member Subscriptions';
$itemNumber = 'MS'.$loggedInUserID;

//subscription price for one month
$itemPrice = 25.00;
?>

<p>Choose Validity:
    <select name="validity" onchange="getSubsPrice(this);">
        <option value="1" selected="selected">1 Month</option>
        <option value="3">3 Month</option>
        <option value="6">6 Month</option>
        <option value="9">9 Month</option>
        <option value="12">12 Month</option>
    </select>
</p>
<p>Price: <span id="subPrice"><?php echo '$'.$itemPrice.' USD'; ?></span></p>
<form action="<?php echo $paypalURL; ?>" method="post">
    <!-- identify your business so that you can collect the payments -->
    <input type="hidden" name="business" value="<?php echo $paypalID; ?>">
    <!-- specify a subscriptions button. -->
    <input type="hidden" name="cmd" value="_xclick-subscriptions">
    <!-- specify details about the subscription that buyers will purchase -->
    <input type="hidden" name="item_name" value="<?php echo $itemName; ?>">
    <input type="hidden" name="item_number" value="<?php echo $itemNumber; ?>">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="a3" id="paypalAmt" value="<?php echo $itemPrice; ?>">
    <input type="hidden" name="p3" id="paypalValid" value="1">
    <input type="hidden" name="t3" value="M">
    <!-- custom variable user ID -->
    <input type="hidden" name="custom" value="<?php echo $loggedInUserID; ?>">
    <!-- specify urls -->
    <input type="hidden" name="cancel_return" value="<?php echo $cancelURL; ?>">
    <input type="hidden" name="return" value="<?php echo $successURL; ?>">
    <input type="hidden" name="notify_url" value="<?php echo $notifyURL; ?>">
    <!-- display the payment button -->
    <input class="paypal_button" type="submit" value="Buy Subscription">
</form>

<script>
function getSubsPrice(obj){
    var month = obj.value;
    var price = (month * <?php echo $itemPrice; ?>);
    document.getElementById('subPrice').innerHTML = '$'+price+' USD';
    document.getElementById('paypalValid').value = month;
    document.getElementById('paypalAmt').value = price;
}
</script>

它工作正常,但是当我将客户重定向到success.php时,这不会向我显示POST附带的值,而在URL中只是出现

  

http://localhost/final/FrontEnd/success?auth=AiW2kfKGq8nwLXjUoikLI0tN0rU-tsFg-FqXeeq.9EAJ.MP1cxmByESWxqNYLZ2zwEXWGaLChdVlqUYnbZ5FKPA&form_charset=UTF-8

我正在使用MVC,并且我有一个白名单,哪些页面可以输入用户,并且我这样声明

$rutas = array();
$ruta = null;
$infoUsuario = null;

if (isset($_GET["ruta"])) {
  $rutas = explode("/", $_GET["ruta"]);

//$item = "nickname";
$valor =  $rutas[0];

我的问题是如何获取URL附带的值?他们被刻印了吗?我尝试使用解码语句,但没有成功

0 个答案:

没有答案