-1

SIM APIを使用して、自分のサイトでクレジットカードによる支払いを実行しています。具体的にはAuthorize.net

数量フィールドと購入ボタンがリストされた製品を含む1つの製品があります。

顧客が数量を変更した場合、投稿する金額を更新する必要があります。

これが私のコードです:

        <?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 *'quantity'を試しましたが、何もしませんでした。

ありがとう。-アン

4

2 に答える 2

0

私があなたが何をしたいのかを誤解しない限り、フォームをauthorize.net WebサイトにPOSTする前に、Javascriptを使用して数量を1からユーザーが望む数に更新するのが最善です。

ここで重要なのは、フォームをPOSTするか、リンクをクリックしてGETリクエストを行うときにイベントの順序を覚えておくことです。

PHPはサーバー側の技術であるため、サーバーに命令を送信するときに実行されます。たとえば、私のデータベースにクエリを実行してデータを取得するなどの指示をPHPに送信すると、それらの結果が返されます。

ブラウザにデータを表示すると、サーバーに別のリクエストを送信しない限り、PHPは再び関与できなくなります。

対照的に、JavascriptとJQueryのようなそのライブラリはブラウザツールであるため、既知のものを変更できます。あなたの場合、POSTイベントが発生する前に、ユーザーの選択に基づいて、Javascriptを使用して数量フィールドを変更するように指示できます。

これらのJS関数についてお読みください。

onChange

onSubmit

document.write

document.getelementbyid

私があなたに卵を吸うように教えていないことを願っています。

于 2011-06-29T19:27:40.600 に答える
0

フォームに名前を付けてAmount: <?php echo $amount; ?>Amount: <span id='totalCost'>?php echo $amount; ?></span>

次に、これをhtmlヘッドに追加します。

<script type='text/javascript>
function updateAmount(){
    var amount = document.formName.amount.value;
    var quantity = document.formName.quantity.value;
    var total = amount * quantity;
    document.getElementById("totalCost").value.write(total);
}
</script>

入力フォームにonChangeパラメータを追加します。

<label>Quantity:</label><input type="text" name="quantity'" value="1" size="2" maxlength="3" onChange="updateAmount()"/>

それがあなたを正しい方向に向けるのに役立つことを願っています。

于 2011-06-29T20:39:54.423 に答える