我可以使用.php文件来处理其中的示例数据。但是,我已经尝试了几种方法来获取一个html表单将变量发布到php中。做这个的最好方式是什么?我将.php与其中适用于该站点的示例数据相关联。当我尝试使用.html文件并发布到此文件时,它停在BluPay.php文件中,没有任何反应,并且事务无法发送数据。这只是测试数据,因此信用卡信息内部没有任何内容。
<?php
/**
* BluePay PHP Sample Code
*
* This code sample runs a $3.00 Credit Card Sale transaction
* against a customer using test payment information.
* If using TEST mode, odd dollar amounts will return
* an approval and even dollar amounts will return a decline.
*
*/
include('BluePay.php');
$accountID = "XXXXXXXX";
$secretKey = "XXXXXXXXXXXXXX";
$mode = "TEST";
$payment = new BluePay(
$accountID,
$secretKey,
$mode
);
$payment->setCustomerInformation(array(
'firstName' => 'Bob',
'lastName' => 'Tester',
'addr1' => '1234 Test St.',
'addr2' => 'Apt #500',
'city' => 'Testville',
'state' => 'IL',
'zip' =>'54321',
'country' => 'USA',
'phone' => '1231231234',
'email' => 'test@bluepay.com'
));
$payment->setCCInformation(array(
'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
'cardExpire' => '1217', // Card Expire: 12/15
'cvv2' => '123' // Card CVV2: 123
));
$payment->sale('3.00'); // Sale Amount: $3.00
// Makes the API request with BluePAy
$payment->process();
// Reads the response from BluePay
if($payment->isSuccessfulResponse()){
echo
'Transaction Status: '. $payment->getStatus() . "\n" .
'Transaction Message: '. $payment->getMessage() . "\n" .
'Transaction ID: '. $payment->getTransID() . "\n" .
'AVS Response: ' . $payment->getAVSResponse() . "\n" .
'CVS Response: ' . $payment->getCVV2Response() . "\n" .
'Masked Account: ' . $payment->getMaskedAccount() . "\n" .
'Card Type: ' . $payment->getCardType() . "\n" .
'Authorization Code: ' . $payment->getAuthCode() . "\n";
} else{
echo $payment->getMessage() . "\n";
}
?>
这是我删除值后用于发布到php上面的html之一:
<form action="ccpost.php" method="post">
<input type="hidden" name="accountID" value="XXXXXXXXXX" />
<input type="hidden" name="secretKey" value="XXXXXXXXXXX" />
<input type="hidden" name="mode" value="TEST" />
First Name: <input type="text" name="firstName"><br>
Last Name: <input type="text" name="lastName"><br>
Address 1: <input type="text" name="addr1"><br>
Address 2: <input type="text" name="addr2"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
Zip Code: <input type="text" name="zip"><br>
Country: <input type="text" name="country"><br>
Phone: <input type="text" name="phone"><br>
E-mail: <input type="text" name="email"><br>
Card Number: <input type="text" name="cardNumber"><br>
Card Expire: <input type="text" name="cardExpire"><br>
Cvv: <input type="text" name="cvv2"><br>
Sale: <input type="text" name="sale"><br>
<input type="submit">
</form>
这是我想要发布的当前php。所以我拿了变量并使用$ _POST。但是我得到一个PHP Parse错误:语法错误,意外&#39 ;;&#39;在accountID行周围。
<?php
include('BluePay.php');
$payment = new BluePay(
$accountID = $_POST["accountID"];
$secretKey = $_POST["secretKey"];
$mode = $_POST["mode"];
);
$payment->setCustomerInformation(array(
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$addr1 = $_POST["addr1"];
$addr2 = $_POST["addr2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$country = $_POST["country"];
$phone = $_POST["phone"];
$email = $_POST["email"];
));
$payment->setCCInformation(array(
'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
'cardExpire' => '1217', // Card Expire: 12/15
'cvv2' => '123' // Card CVV2: 123
));
$payment->sale('3.00'); // Sale Amount: $3.00
// Makes the API request with BluePay
$payment->process();
// Reads the response from BluePay
if($payment->isSuccessfulResponse()){
echo
'Transaction Status: '. $payment->getStatus() . "\n" .
'Transaction Message: '. $payment->getMessage() . "\n" .
'Transaction ID: '. $payment->getTransID() . "\n" .
'AVS Response: ' . $payment->getAVSResponse() . "\n" .
'CVS Response: ' . $payment->getCVV2Response() . "\n" .
'Masked Account: ' . $payment->getMaskedAccount() . "\n" .
'Card Type: ' . $payment->getCardType() . "\n" .
'Authorization Code: ' . $payment->getAuthCode() . "\n";
} else{
echo $payment->getMessage() . "\n";
}
?>
答案 0 :(得分:1)
因为我看不到您的.html文件,所以提供具体答案并不容易。但我能做的最好的就是推荐你这个教程: https://www.w3schools.com/php/php_forms.asp 在那里你应该找到一切。
基本上你必须将你的.php脚本放到.html的'action标签',使用方法GET或POST,然后在.php中获取globals $ _GET或$ _POST中的数据。