表单包含加密的 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 空白。任何人都可以帮助我如何做到这一点。
最佳答案
- 唯一可以在网站之间传递的是字符串值。
- 其他网站必须为您提供他们将接受的值的名称。
- 但这会将值传递给 Paypal。
- 如下添加所需的每个隐藏变量
<input type=hidden
id=OrderID
value=12345
> - 将值提交到外部站点的按钮
< input type="button"onclick="javascript: submitToPayPal('http://www.paypal.com/cgi-bin/webscr');"value="提交到 PayPal"> - 向页面添加必要的 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/