自定义paypal结账,包括php变量

时间:2013-05-13 18:35:16

标签: php html input paypal

我正在尝试向第三方结帐PayPal选项添加“自定义”值。我遇到的问题是PHP变量正在屏幕上显示。我将购物车价值传递给会话变量。

if(isset($_SESSION['checkout'])){
$orderData = '<table border="1"><th style="width:80px">Item</th>
             <th sytle="width:250px">Size</th>
             <th style="width:60px">Quantity</th>';
for ($i=0; $i<count($_SESSION['checkout']); $i++){
    $orderData .= '<tr><td style="text-align:center">'.$_SESSION['checkout'][$i][0].'</td><td style="text-align:center">'.$_SESSION['checkout'][$i][1].'</td><td style="text-align:center">'.$_SESSION['checkout'][$i][2].'</td></tr>';
}
}

我希望传递该表,并且基于PayPal documentation,我需要做的就是包含它。我正在回复PayPal表格:

echo '<form>
      //other hidden values
      <input type="hidden" name="custom" value="'.$orderData.'">
      //input submit button here
      </form>

就像我说的那样,输入应该是隐藏的,但它会在PayPal按钮之前显示。怎么样?

更新:这些代码完美地传递了数量:

<input type="hidden" name="amount" value="';?><?php if(isset($_SESSION['disc'])){print_r($_SESSION['disc']);}?><?php echo '">

它不会显示在页面上,但页面源中的变量是正确的。

UPDATE2:这是我的整个购物车脚本:

echo '<div style="position:absolute; left:770px; top:50px">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myemail@example.com">
<input type="hidden" name="item_name" value="Merchandise">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="custom" value="'.$orderData.'">
<input type="hidden" name="return" value="backtomywebsite.com">
<input type="hidden" name="cancel_return" value="backtomywebsite.com">
<input type="hidden" name="amount" value="';?><?php if(isset($_SESSION[$disc])){print_r($_SESSION[$disc]);}?><?php echo '">
<input type="image" src="http://www.mywebsite.com/images/BuyNow.png" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!" width="300" height="204">
    </form>
    </div>';

脚本工作时,而不是$ orderData我有一个带项目信息的print_r会话。该信息被发送到我的paypal帐户,但它是一个数组形式,看起来很难看。如果有办法将所有内容(成员信息,订单信息)放入php变量并将其传递到自定义字段中,那就太棒了。无论如何......这就是屏幕上的内容:

Image Showing PayPal Text

希望你仍然愿意帮助我。

1 个答案:

答案 0 :(得分:0)

在PayPal按钮之前显示它是什么意思?如果您正在查看页面的源代码,您将在页面中看到该值。

如果您说您正在通过金额,但没有看到它,您可能正在使用错误的变量。变量金额是一个有效的PayPal变量,但是根据您使用金额变量的具体按钮略有不同。我无法从您的代码中看出因为我没有看到您为“cmd”传递的内容,但如果您使用立即购买按钮或添加到购物车按钮,则变量“amount”将是正确的变量使用。如果您使用购物车上传方法,则需要使用变量“amount_x”。因此,如果我通过了两个项目,第一个是0.99而第二个是1.99,我会传递变量/值“amount_1 = 0.99”和“amount_2 = 1.99”。