我有两部分表格。第一部分请求电子邮件地址,物理地址。第二部分提交后,数据如下:
[name_first] => John
[name_last] => Doe
[email] => test@test.com
[invoice] => 12345
[price] => 35
[address_street address] => PO Box 123
[address_address line 2] =>
[address_city] => Anytown
[address_state] => NY
[address_zip] => 12345
[address_country] => USA
我希望将地址和发票号码预先填写到托管付款表格中,以便访问者不必填写两次。我使用Auth.net示例代码生成令牌,可以查看我在哪里传递付款金额,但如何通过数据中的另一个传递来生成表单?
<?php
require dirname(__FILE__).'/../vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
use net\authorize\api\constants as ANetEnvironment;
define("AUTHORIZENET_LOG_FILE", "phplog");
function getAnAcceptPaymentPage($values = array())
{
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName('5KP3u95bQpv');
$merchantAuthentication->setTransactionKey("xxxxxxxx");
//create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($values['price']);
echo '<P> :: ' . $transactionRequestType->getCustomer() . '</p>';
// Set Hosted Form options
$setting1 = new AnetAPI\SettingType();
$setting1->setSettingName("hostedPaymentButtonOptions");
$setting1->setSettingValue("{\"text\": \"Pay\"}");
$setting2 = new AnetAPI\SettingType();
$setting2->setSettingName("hostedPaymentOrderOptions");
$setting2->setSettingValue("{\"show\": true}");
$setting3 = new AnetAPI\SettingType();
$setting3->setSettingName("hostedPaymentReturnOptions");
$setting3->setSettingValue("{\"url\": \"$values[receipt_url]\", \"cancelUrl\": \"$values[cancel_url]\", \"showReceipt\": true}");
// Build transaction request
$request = new AnetAPI\GetHostedPaymentPageRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest($transactionRequestType);
$request->addToHostedPaymentSettings($setting1);
$request->addToHostedPaymentSettings($setting2);
$request->addToHostedPaymentSettings($setting3);
//execute request
$controller = new AnetController\GetHostedPaymentPageController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
return $response->getToken()."\n";
}
else
{
echo "ERROR : Failed to get hosted payment page token\n";
$errorMessages = $response->getMessages()->getMessage();
echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
?>
答案 0 :(得分:1)
当您请求令牌时,请在&#34; transactionRequest&#34;中包含您想要预先填充的任何内容。请求的元素。
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "25.00",
"customer": {
"email": "customer@email.com"
},
"billTo": {
"firstName": "John",
"lastName": "Jones",
"company": "Microsoft",
"address": "100 Sunrise Way",
"city": "Palm Springs",
"state": "CA",
"zip": "92234",
"country": "USA"
}
顺便说一下,我希望这不是你真正的交易密钥。如果是,你应该改变它。