php - 如何使用加密按钮将价格变量传递给 Paypal

标签 php paypal paypal-ipn paypal-sandbox

表单包含加密的 Paypal 按钮。我想将值(value)/价格变量传递给 paypal。我不知道该怎么做。

       <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
       <input type="hidden" name="cmd" value="_s-xclick">
      <input type="hidden" name="hosted_button_id" value="LMFWRYRBURU2J">

       <input  type="hidden"><h3>Amount of messages </h3> <br /> </div>
    <input class="paypal_input" type="" name="message" id="message" onkeyup="doMath()" maxlength="60"> <br /> 


      </p>
      <div  class="paypal_list2">   
          <p>
     <input type="hidden"><h3>Total amount</h3><br /> </div>
     <input id="total" class="paypal_input_1" type="text" value="" name="amount" readonly>

      <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
     <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
       </form>

我想通过加密按钮将这个可变金额传递给 Paypal

我试过这样

       <input type='hidden' name='amount' value='<?php echo $_POST['total'];?>'>

它没有收取金额。paypal 中的 item_price 空白。任何人都可以帮助我如何做到这一点。

最佳答案

  1. 唯一可以在网站之间传递的是字符串值。
  2. 其他网站必须为您提供他们将接受的值的名称。
  3. 但这会将值传递给 Paypal。
    1. 如下添加所需的每个隐藏变量
      <input type=hidden id=OrderID value=12345>
    2. 将值提交到外部站点的按钮
      < input type="button"onclick="javascript: submitToPayPal('http://www.paypal.com/cgi-bin/webscr');"value="提交到 PayPal">
    3. 向页面添加必要的 JavaScript
   
    

    function submitToPayPal(formAction){ 
        var formElementsArray = document.getElementsByTagName('FORM’);
        if ( formElementsArray != null )  {   
            var formElement = formElementsArray[0];
            document.getElementById('total_amount’).value = '';         
            document.getElementById('__VIEWSTATE’).name = 'NOVIEWSTATE';
            formElement.action = formAction;
            formElement.submit();
        }
    }
    

Use the below if you good in php script.

    /*The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.*/
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";

/*loop for posted values and append to querystring*/
foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$querystring .= "$key=$value&";
}

/* Append paypal return addresses*/
$querystring .= "return=".urlencode(stripslashes($return_url))."&";
$querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
$querystring .= "notify_url=".urlencode($notify_url);

/* Append querystring with custom field
//$querystring .= "&custom=".USERID; */

/* Redirect to paypal IPN*/
header("location:https://www.sandbox.paypal.com/cgi-bin/webscr".$querystring);
exit();

.

关于php - 如何使用加密按钮将价格变量传递给 Paypal ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12601182/

相关文章:

paypal-ipn - 来自 Paypal IPN 而不是 VERIFIED 或 INVALID 的错误响应

php - 给 PayPal 立即购买按钮特殊 ID?

php - Doctrine 未检测到一个实体管理器和多个数据库的架构更改

paypal - 我应该使用哪个 Paypal API 版本。 (经典与 REST)

c# - 如何处理paypal电子支票

php - PayPal REST API (PHP) 未完成交易

rest - 通过 OAuth 代表商家发出 PayPal REST API 请求

php - Mysql通过取错时间戳查询分组

php - htaccess 如何不重写某些 URL

php - StrToTime 在传递变量时不起作用