Skip to content

Commit

Permalink
code formatting and rename iCommunicator.html
Browse files Browse the repository at this point in the history
  • Loading branch information
adavidw committed Aug 19, 2017
1 parent 35ba642 commit 5ae8367
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 89 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions README-AcceptHosted.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ In this step we will demonstrate how to resize your container iframe based on re

To securely communicate between our Accept Hosted form and your web page, we need a communicator page which will be hosted on your site alongside your checkout/payment page. You can provide the URL of the communicator page in your token request, which will allow Authorize.Net to embed the communicator page in the payment form, and send JavaScript messaging through your communicator page to a listener script on your main page.

For example, in this sample application, see the sample communicator page, [iCommunicator.html](iCommunicator.html). You can use this same communicator page in your application.
For example, in this sample application, see the sample communicator page, [IFrameCommunicator.html](iCommunicator.html). You can use this same communicator page in your application.

Pass the URL of your communicator page when you request a token (Step 1 above). For example:

```xml
<setting>
<settingName>hostedPaymentIFrameCommunicatorUrl</settingName>
<settingValue>{"url":"https://www.mystore.com/checkout/iCommunicator.html"}</settingValue>
<settingValue>{"url":"https://www.mystore.com/checkout/IFrameCommunicator.html"}</settingValue>
</setting>
```

Expand Down
96 changes: 49 additions & 47 deletions getHostedPaymentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<phoneNumber>1231231234</phoneNumber>
</billTo>
<customerIP>192.168.1.1</customerIP>
<userFields>
<userFields>
<userField>
<name>sessionID</name>
<value>ABC123</value>
Expand Down Expand Up @@ -102,60 +102,62 @@
</hostedPaymentSettings>
</getHostedPaymentPageRequest>
XML;
$xml = simplexml_load_string($xmlStr,'SimpleXMLElement', LIBXML_NOWARNING);
$xml = simplexml_load_string($xmlStr, 'SimpleXMLElement', LIBXML_NOWARNING);
// $xml = new SimpleXMLElement($xmlStr);
$xml->merchantAuthentication->addChild('name',getenv('API_LOGIN_ID'));
$xml->merchantAuthentication->addChild('transactionKey',getenv('TRANSACTION_KEY'));
$xml->merchantAuthentication->addChild('name', getenv('API_LOGIN_ID'));
$xml->merchantAuthentication->addChild('transactionKey', getenv('TRANSACTION_KEY'));

$commUrl = json_encode(array('url' => thisPageURL()."iCommunicator.html" ),JSON_UNESCAPED_SLASHES);
$xml->hostedPaymentSettings->setting[0]->addChild('settingValue',$commUrl);
$commUrl = json_encode(array('url' => thisPageURL()."IFrameCommunicator.html" ), JSON_UNESCAPED_SLASHES);
$xml->hostedPaymentSettings->setting[0]->addChild('settingValue', $commUrl);

$retUrl = json_encode(array("showReceipt" => false ,'url' => thisPageURL()."return.html","urlText"=>"Continue to site", "cancelUrl" => thisPageURL()."return.html", "cancelUrlText" => "Cancel" ),JSON_UNESCAPED_SLASHES);
$xml->hostedPaymentSettings->setting[2]->addChild('settingValue',$retUrl);
$retUrl = json_encode(array("showReceipt" => false , 'url' => thisPageURL()."return.html", "urlText"=>"Continue to site", "cancelUrl" => thisPageURL()."return.html", "cancelUrlText" => "Cancel" ), JSON_UNESCAPED_SLASHES);
$xml->hostedPaymentSettings->setting[2]->addChild('settingValue', $retUrl);

$url = "https://apitest.authorize.net/xml/v1/request.api";

try{ //setting the curl parameters.
try { //setting the curl parameters.
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
// The following two curl SSL options are set to "false" for ease of development/debug purposes only.
// Any code used in production should either remove these lines or set them to the appropriate
// values to properly use secure connections for PCI-DSS compliance.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //for production, set value to true or 1
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //for production, set value to 2
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
//curl_setopt($ch, CURLOPT_PROXY, 'userproxy.visa.com:80');
$content = curl_exec($ch);
$content = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);

$hostedPaymentResponse = new SimpleXMLElement($content);
if (FALSE === $content)
throw new Exception(curl_error($ch), curl_errno($ch));
curl_close($ch);

}catch(Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}

function thisPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
if (false === $ch) {
throw new Exception('failed to initialize');
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
// The following two curl SSL options are set to "false" for ease of development/debug purposes only.
// Any code used in production should either remove these lines or set them to the appropriate
// values to properly use secure connections for PCI-DSS compliance.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //for production, set value to true or 1
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //for production, set value to 2
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
//curl_setopt($ch, CURLOPT_PROXY, 'userproxy.visa.com:80');
$content = curl_exec($ch);
$content = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);

$pageLocation = str_replace('index.php', '', $pageURL);
$hostedPaymentResponse = new SimpleXMLElement($content);
if (false === $content) {
throw new Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
} catch (Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}

return $pageLocation;
function thisPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}

?>
$pageLocation = str_replace('index.php', '', $pageURL);

return $pageLocation;
}
82 changes: 42 additions & 40 deletions getToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,60 @@
$loginId = getenv("API_LOGIN_ID");
$transactionKey = getenv("TRANSACTION_KEY");

$xml->merchantAuthentication->addChild('name',$loginId);
$xml->merchantAuthentication->addChild('transactionKey',$transactionKey);
$xml->merchantAuthentication->addChild('name', $loginId);
$xml->merchantAuthentication->addChild('transactionKey', $transactionKey);
if (isset($_COOKIE['cpid'])) {
$cpid = $_COOKIE['cpid'];
}
else if(isset($_COOKIE['temp_cpid'])){
} else if (isset($_COOKIE['temp_cpid'])) {
$cpid = $_COOKIE['temp_cpid'];
}

$xml->customerProfileId = $cpid;
$xml->hostedProfileSettings->setting[0]->addChild('settingValue',curPageURL()."return.html");
$xml->hostedProfileSettings->setting[1]->addChild('settingValue',curPageURL()."iCommunicator.html");
$xml->hostedProfileSettings->setting[0]->addChild('settingValue', curPageURL()."return.html");
$xml->hostedProfileSettings->setting[1]->addChild('settingValue', curPageURL()."IFrameCommunicator.html");

$url = "https://apitest.authorize.net/xml/v1/request.api";

try{ //setting the curl parameters.
try { //setting the curl parameters.
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
// The following two curl SSL options are set to "false" for ease of development/debug purposes only.
// Any code used in production should either remove these lines or set them to the appropriate
// values to properly use secure connections for PCI-DSS compliance.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //for production, set value to true or 1
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //for production, set value to 2
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
$content = curl_exec($ch);
$response = new SimpleXMLElement($content);
if (FALSE === $content)
throw new Exception(curl_error($ch), curl_errno($ch));
curl_close($ch);

}catch(Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}
if (false === $ch) {
throw new Exception('failed to initialize');
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
// The following two curl SSL options are set to "false" for ease of development/debug purposes only.
// Any code used in production should either remove these lines or set them to the appropriate
// values to properly use secure connections for PCI-DSS compliance.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //for production, set value to true or 1
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //for production, set value to 2
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
$content = curl_exec($ch);
$response = new SimpleXMLElement($content);
if (false === $content) {
throw new Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
} catch (Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
function curPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}

$pageLocation = str_replace('index.php', '', $pageURL);

return $pageLocation;
}
?>
}

0 comments on commit 5ae8367

Please sign in to comment.