如何创建 HTML 表单以允许用户更改其 iTransact (itransact.com) 订阅设置?
例如:1) 选择不自动续订:
- 表单需要将 'recur_reps' 值更改为 0
例如:2)更改他们的订阅类型:
- 表单需要更改“recur_total”和“recur_desc”的值
(即:将表单发布到的 URL 是什么以及我需要向其发布哪些表单字段?)
如何创建 HTML 表单以允许用户更改其 iTransact (itransact.com) 订阅设置?
例如:1) 选择不自动续订:
例如:2)更改他们的订阅类型:
(即:将表单发布到的 URL 是什么以及我需要向其发布哪些表单字段?)
根据 iTransact 支持技术人员的说法,无法创建 HTML 表单来允许用户更改其 iTransact (itransact.com) 订阅设置。但是,有一个 XML API 允许这样做。
由于向 iTransact 的 XML API 发送 XML 请求的代码并不简单和直观,因此我决定将一个工作示例程序发布到 Stack Overflow,因为它可能有助于作为其他人的参考,特别是因为它们在iTransact.com 文档。
以下示例程序发送请求以获取现有事务的详细信息。
<?php
define('ITRANSACT_API_UPDATE_URL', 'https://secure.itransact.com/cgi-bin/rc/xmltrans2.cgi');
define('ITRANSACT_API_GATEWAY', '12345'); // vendor account number
define('ITRANSACT_API_USERNAME', 'fdfsdfksafdsafdsafdsafdsafdsa'); // vendor API username
define('ITRANSACT_API_KEY', 'fdsfdsafdsafdsfdsfdsfds'); // vendor API key
/**
* iTransact's XML API requires us to encrypt the XML command with a
* special key known only to us and iTransact. This is to ensure that the
* request cannot be modified after leaving our server.
*
* A keyed hash value is generated using the HMAC-SHA1 algorithm and then
* encoded with base-64 MIME.
*
* @param string $strXMLCmd: xml for the command operation
*
* @returns string: the base64-encrypted HASH_SHA1 payload Signature
* for the command
*/
function getITransactPayloadSignagureForCommand($strXMLCmd){
$key = ITRANSACT_API_KEY;
#Using built in PHP5 functions:
$digest = hash_hmac('sha1', $strXMLCmd, $key, true);
$strPayLoadSignature = base64_encode($digest);
#Using PEAR module:
#require_once 'Crypt/HMAC.php';
#$hmac = new Crypt_HMAC($key,"sha1");
#$digest = pack("H40", $hmac->hash(trim($payload)));
#$actual_signature = base64_encode($digest);
return $strPayLoadSignature;
}
/**
* Constructs the XML request in the iTransact format for the request
* including login credentials
*
* @param string $strXMLCmd: specific xml for the operation command
*/
function construct_itransact_xml($strXMLCmd){
$strPayLoadSignature = getITransactPayloadSignagureForCommand($strXMLCmd);
$strXML = '<?xml version="1.0"?>';
$strXML .= '<GatewayInterface>';
// Login credentials:
$strXML .= '<APICredentials>';
$strXML .= '<Username>'.ITRANSACT_API_USERNAME.'</Username>';
$strXML .= '<PayloadSignature>'.$strPayLoadSignature.'</PayloadSignature>';
$strXML .= '<TargetGateway>'.ITRANSACT_API_GATEWAY.'</TargetGateway>';
$strXML .= '</APICredentials>';
$strXML .= $strXMLCmd; // Unique part of every command
$strXML .= '</GatewayInterface>';
return $strXML;
}
/**
* Sends an XML request to iTransact.
*
* @param string $xml: the XML to send to iTransact
*
* @returns string: the XML responde from iTransact
*/
function post_xml_to_iTransact($xml) {
$url = ITRANSACT_API_UPDATE_URL;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return $result;
}
// *** MAIN ***
// construct XML command:
$strXID = '12345'; // transaction_id we wish to get details of
$strXMLCmd = '<RecurDetails><OperationXID>'.$strXID.'</OperationXID></RecurDetails>'; // command we wish to send
$strXML = construct_itransact_xml($strXMLCmd);
// send XML command:
$strReturnedXML = post_xml_to_iTransact($strXML); // send request and fetch result
echo 'Response XML from iTransact: '.var_export(htmlspecialchars($strReturnedXML), TRUE);
?>
注意:更新/取消现有定期订阅的请求将具有类似的格式,但将使用“recurUpdate”命令而不是“recurDetails”命令(有关所有可能命令的完整详细信息,请参阅:http ://www.itransact.com /downloads/PCDeveloperGuide.pdf )