PHP 产品列表页面发布到付款表单的总金额
我正在使用 SIM API 通过我的网站运行信用卡付款。具体来说,
我有一个产品,其中列出了数量字段和购买按钮。
如果客户更改数量,我需要更新发布的金额。
这是我的代码:
<?php
// This sample code requires the mhash library for PHP versions older than
// 5.1.2 - http://hmhash.sourceforge.net/
// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID = "0000000";
$transactionKey = "00000000000000";
$amount = "3.99";
$description = "This is a Sample Transaction";
$label = "Purchase"; // The is the label on the 'submit' button
$testMode = "false";
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$url = "https://test.authorize.net/gateway/transact.dll";
// If an amount or description were posted to this page, the defaults are overidden
if (array_key_exists("amount",$_REQUEST))
{ $amount = $_REQUEST["amount"]; }
if (array_key_exists("amount",$_REQUEST))
{ $description = $_REQUEST["description"]; }
// an invoice is generated using the date and time
$invoice = date(YmdHis);
// a sequence number is randomly generated
$sequence = rand(1, 1000);
// a timestamp is generated
$timeStamp = time();
// The following lines generate the SIM fingerprint. PHP versions 5.1.2 and
// newer have the necessary hmac function built in. For older versions, it
// will try to use the mhash library.
if( phpversion() >= '5.1.2' )
{ $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); }
else
{ $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); }
?>
<!-- Print the Amount and Description to the screen. -->
Amount: <?php echo $amount; ?> <br />
Description: <?php echo $description; ?> <br />
<!-- Create the HTML form containing necessary SIM post values -->
<FORM method='post' action='https://test.authorize.net/gateway/transact.dll' >
<!-- Additional fields can be added here as outlined in the SIM integration
guide at: http://developer.authorize.net -->
<input type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
<input type='hidden' name='x_amount' value='<?php echo $amount; ?>' />
<input type='hidden' name='x_description' value='<?php echo $description; ?>' />
<label>Quantity:</label><input type="text" name="quantity'" value="1" size="2" maxlength="3" />
<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' />
<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<input type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
<input type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' />
<input type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
<input type='hidden' name='x_show_form' value='PAYMENT_FORM' />
<input type="hidden" name="x_logo_URL" value="https://secure.authorize.net/mgraphics/logo_322583_1.jpg">
<input type='submit' value='<?php echo $label; ?>' />
</form>
我是 php 的初学者,因此任何帮助理解的内容将不胜感激。 S=我尝试过 amount= 3.99 * '数量' 但没有任何效果。
谢谢。 -安
i am using a SIM API to run credit card payments through my site. Specifically Authorize.net
I have a one product with a product listing a quantity field and a purchase button.
I need the amount that posts to be updated if the customer changes the quantity.
Here is my code:
<?php
// This sample code requires the mhash library for PHP versions older than
// 5.1.2 - http://hmhash.sourceforge.net/
// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID = "0000000";
$transactionKey = "00000000000000";
$amount = "3.99";
$description = "This is a Sample Transaction";
$label = "Purchase"; // The is the label on the 'submit' button
$testMode = "false";
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$url = "https://test.authorize.net/gateway/transact.dll";
// If an amount or description were posted to this page, the defaults are overidden
if (array_key_exists("amount",$_REQUEST))
{ $amount = $_REQUEST["amount"]; }
if (array_key_exists("amount",$_REQUEST))
{ $description = $_REQUEST["description"]; }
// an invoice is generated using the date and time
$invoice = date(YmdHis);
// a sequence number is randomly generated
$sequence = rand(1, 1000);
// a timestamp is generated
$timeStamp = time();
// The following lines generate the SIM fingerprint. PHP versions 5.1.2 and
// newer have the necessary hmac function built in. For older versions, it
// will try to use the mhash library.
if( phpversion() >= '5.1.2' )
{ $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); }
else
{ $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); }
?>
<!-- Print the Amount and Description to the screen. -->
Amount: <?php echo $amount; ?> <br />
Description: <?php echo $description; ?> <br />
<!-- Create the HTML form containing necessary SIM post values -->
<FORM method='post' action='https://test.authorize.net/gateway/transact.dll' >
<!-- Additional fields can be added here as outlined in the SIM integration
guide at: http://developer.authorize.net -->
<input type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
<input type='hidden' name='x_amount' value='<?php echo $amount; ?>' />
<input type='hidden' name='x_description' value='<?php echo $description; ?>' />
<label>Quantity:</label><input type="text" name="quantity'" value="1" size="2" maxlength="3" />
<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' />
<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<input type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
<input type='hidden' name='x_fp_hash' value='<?php echo $fingerprint; ?>' />
<input type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
<input type='hidden' name='x_show_form' value='PAYMENT_FORM' />
<input type="hidden" name="x_logo_URL" value="https://secure.authorize.net/mgraphics/logo_322583_1.jpg">
<input type='submit' value='<?php echo $label; ?>' />
</form>
I am a beginner at php so any help understanding the would be appreciated. S=I have tried amount= 3.99 * 'quantity' and that did nothing.
Thanks.
-Ann
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该给你的表单一个名称,并设置
Amount:
进入金额:?php echo $amount; ?>
然后将其添加到 html head:
并在输入表单上添加 onChange 参数。
希望这有助于为您指明正确的方向。
I think you should give your form a name, and make
Amount: <?php echo $amount; ?>
intoAmount: <span id='totalCost'>?php echo $amount; ?></span>
then add this in the html head:
and add an onChange param on your input form.
Hope that helps point you in the right direction.
除非我没明白您想要做什么,否则您最好在将表单发布到authorize.net 网站之前使用Javascript 将数量从1 更新为用户想要的数量。
这里的关键是记住当您发布表单或单击链接并发出 GET 请求时事件的顺序。
PHP 是服务器端技术,因此当您向服务器发送指令时它就会执行。例如,您将向 PHP 发送指令,例如查询我的数据库并获取内容,它将为您返回这些结果。
一旦您在浏览器中显示数据,PHP 就无法再次介入,除非您向服务器发送另一个请求。
相比之下,Javascript 及其库(如 JQuery)是浏览器工具,因此它们可以改变已知的内容。在您的情况下,您可以在 POST 事件发生之前,根据用户的选择,使用 Javascript 告诉数量字段进行更改。
了解这些 JS 函数:
onChange
onSubmit
document.write
document.getelementbyid
希望我不是在教你吃鸡蛋。
Unless I miss-understand what you want to do, you will be best off using Javascript to update the quantity from 1 to however many the user wants, before they POST the form to the authorize.net website.
The key here is to remember the order of events when you POST a form or click a link and make a GET request.
PHP is server-side tech, so it's executed when you send instructions to the server. For-instance, you'll send instructions to PHP like query my db and get stuff and it will return those results for you.
Once you display data in the browser PHP can't get involved again, unless you send another request to the server.
In contrast, Javascript and its libraries like JQuery are browser tools so they can change what is already known. In your case you can tell the quantity field to change using Javascript, based on the users choice, before the POST event takes place.
Read about these JS functions:
onChange
onSubmit
document.write
document.getelementbyid
Hope I'm not teaching you to suck eggs.