Reply
Contributor
Posts: 43
Registered: ‎06-17-2011
Accepted Solution

GetHostedProfilePage API call - How To Use It?

Hey,

 

I've searched this board and google to no avail. I don't see how I am able to get a token via:

 

GetHostedProfilePage API call

 

So I can use the hosted profile modification popups when using CIM. I know how to create a profile and delete one, but not modify one and I was hoping this pop up solution would come in handy. It says to:

 

"Put this hidden <form> anywhere on your page with the token from the GetHostedProfilePage API call.
"


But is there even any documentation to explain how to do this? I just want to use this method but I don't see the point of it if there is no explanation on how to use it. I just can't afford to lose more time trying to figure this out so I had to ask. I am sure others here would appreciate the answer as well.

 

Thank you for your time and for CIM, it is a remarkable service you offer and I do appreciate it even if it doesn't sound like it ;)


Accepted Solutions
Solution
Accepted by topic author jbh1977
‎08-21-2015 01:58 AM
Contributor
Posts: 43
Registered: ‎06-17-2011

Re: GetHostedProfilePage API call - How To Use It?

Got it. Thanks, guys. For the PHP users, here is what you do when you download the xml_php folder from the link provided by the CIM sdk:

 

1.) Edit index.php and add this at the bottom:

 

<form method=post action=get_token.php>
<b>Get Hosted Profile Page Id Token:</b><br>
customerProfileId <input type=text name=customerProfileId value='<?php echo $customerProfileId; ?>'><br>
<input type=submit name=submit value=submit>
</form>
<hr>

 2.) Create a new page called 'get_token.php'

 

3.) Add this php code to it:

 

<html>
<body>
<?php

/*
D I S C L A I M E R 
WARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IS AT YOUR OWN RISK.
Authorize.Net provphpides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Authorize.Net owns and retains all right, title and interest in and to the Automated Recurring Billing intellectual property.
*/

include_once ("vars.php");
include_once ("util.php");



//build xml to post
$content =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>
        <getHostedProfilePageRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">"
        .    MerchantAuthenticationBlock().
"<customerProfileId>" . $_POST["customerProfileId"] . "</customerProfileId>
    </getHostedProfilePageRequest>";

$response = send_xml_request($content);
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
            $token=$parsedresponse->token;
       
        echo "<P>The Token Is: $token";
       
       
}

echo "<br><a href=index.php?customerProfileId="
    . urlencode($_POST["customerProfileId"])
    . ">Continue</a><br>";
?>
</body>
</html>

 This code will print out your token. So just comment out the 'echo' parts if you use it live for the hosted pop up solution. Just reference the $token variable created on line 29.

 

I hope this helps.

View solution in original post


All Replies
Member
Posts: 9
Registered: ‎06-12-2011

Re: GetHostedProfilePage API call - How To Use It?

This is what I use to get the token using vb.net: 

 

Dim token As String

token = AuthNetClass.EditCustomerPaymentProfile(AuthNetProfileID)


Public Shared Function EditCustomerPaymentProfile(ByVal profile_id As Long) As String
 Dim hostedprofilesetting As New SettingType

 

 Dim hostedpage As GetHostedProfilePageResponseType =SoapAPIUtilities.Service.GetHostedProfilePage(SoapAPIUtilities.MerchantAuthentication, profile_id, Nothing)

        Dim page_token As String
        page_token = hostedpage.token

        Return page_token 
End Function


I also downloaded and copied into my project the supplied popup forms from the download section under CIM, CIM hosted popup for managing payment/shipping.


Once you get the token you will need to pass it to the page somehow. This is where I felt the documentation fell short. I'm using a 3rd party popup control and embedding the whole authnet profile edit form inside it.


What I did was create a dummypage called managecard.html and pass the token value as a querystring in the page url, so you would endup with a url like ManageCards.html?+tok (tok being the token variable)


Then in my managecards.html markup I had a javascript function that grabbed only the querystring token id and opened the authorize.net supplied popup form when the managecards page loaded:


      function getQuerystring() { 

 var urlen = window.location.search.length;

document.formAuthorizeNetPopup.Token.value = window.location.search.slice(1, urlen);          AuthorizeNetPopup.openManagePopup(); }

<body onload="getQuerystring()">

<form method="post" action="https://authorize.net/hosted/profile/manage" id="formAuthorizeNetPopup" name="formAuthorizeNetPopup" target="iframeAuthorizeNet" style="display:none;">  <input type="hidden" name="Token" value="" /></form>

Hopefully some of that information will help.
Nic

Contributor
Posts: 43
Registered: ‎06-17-2011

Re: GetHostedProfilePage API call - How To Use It?

What file do you have that hosts the function GetHostedProfilePage?

Thanks for the reply. Although I use PHP I am sure I can figure it out IF I can find the page WITH the function. My PHP SDK does NOT seem to have a file with it available. It's driving me nuts.

 

I can't understand why this is so hard to find an answer to. It's as if people in charge are avoiding the topic as nobody else seems to have had this resolved.

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: GetHostedProfilePage API call - How To Use It?

http://developer.authorize.net/downloads/samplecode/

Under the "Customer Information Manager (CIM)" section

Contributor
Posts: 43
Registered: ‎06-17-2011

Re: GetHostedProfilePage API call - How To Use It?

[ Edited ]

Thanks, but I must ask:

 

This standalone code will call the GetHostedProfilePage function?

Or is this to be in conjunction of the hosted pop up solution I downloaded earlier ? (That requies the token)

That's why I am baffled. What page is physically hosting this file to create that token so I can put it into the hidden field in the forms that come with the Hosted popup solution?

I only ask because I can't find it in this download that you suggested or any other. Knowing that page will help tremendously.

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: GetHostedProfilePage API call - How To Use It?

I don't think is support in the current SDKs yet.

Is a web service method at

https://api.authorize.net/soap/v1/Service.asmx

https://apitest.authorize.net/soap/v1/Service.asmx

 

There is sample/documentation in the CIM pdf file under "Section 3 Executing an API Call"

Contributor
Posts: 43
Registered: ‎06-17-2011

Re: GetHostedProfilePage API call - How To Use It?

Ok, I see what you are saying. I complete mis-understood that it was a webservice instead of a function. I was using the pattern of noticing all the existing functions in the SDK.

 

Thank you for the time. It is appreciated.

 

 - Joel

Solution
Accepted by topic author jbh1977
‎08-21-2015 01:58 AM
Contributor
Posts: 43
Registered: ‎06-17-2011

Re: GetHostedProfilePage API call - How To Use It?

Got it. Thanks, guys. For the PHP users, here is what you do when you download the xml_php folder from the link provided by the CIM sdk:

 

1.) Edit index.php and add this at the bottom:

 

<form method=post action=get_token.php>
<b>Get Hosted Profile Page Id Token:</b><br>
customerProfileId <input type=text name=customerProfileId value='<?php echo $customerProfileId; ?>'><br>
<input type=submit name=submit value=submit>
</form>
<hr>

 2.) Create a new page called 'get_token.php'

 

3.) Add this php code to it:

 

<html>
<body>
<?php

/*
D I S C L A I M E R 
WARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IS AT YOUR OWN RISK.
Authorize.Net provphpides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Authorize.Net owns and retains all right, title and interest in and to the Automated Recurring Billing intellectual property.
*/

include_once ("vars.php");
include_once ("util.php");



//build xml to post
$content =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>
        <getHostedProfilePageRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">"
        .    MerchantAuthenticationBlock().
"<customerProfileId>" . $_POST["customerProfileId"] . "</customerProfileId>
    </getHostedProfilePageRequest>";

$response = send_xml_request($content);
$parsedresponse = parse_api_response($response);
if ("Ok" == $parsedresponse->messages->resultCode) {
            $token=$parsedresponse->token;
       
        echo "<P>The Token Is: $token";
       
       
}

echo "<br><a href=index.php?customerProfileId="
    . urlencode($_POST["customerProfileId"])
    . ">Continue</a><br>";
?>
</body>
</html>

 This code will print out your token. So just comment out the 'echo' parts if you use it live for the hosted pop up solution. Just reference the $token variable created on line 29.

 

I hope this helps.

Member
Posts: 1
Registered: ‎05-16-2013

Re: GetHostedProfilePage API call - How To Use It?

This REALLY should be in the SDK itself. Instructions on how to do that yourself:

 

For users of the PHP SDK, add the following to AuthorizeNet.php:

 

require dirname(__FILE__) . '/lib/AuthorizeNetToken.php';

 

Then create a new file called '/lib/AuthorizeNetToken.php' and paste in the following contents:

 

<?php

// This is an added class by leiavoia

class AuthorizeNetToken extends AuthorizeNetRequest {

	const LIVE_URL = "https://api.authorize.net/xml/v1/request.api";
	const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api";

	private $_xml;
	public function GetTokenResponse( $customer_profile_id ) {
		$this->_constructXml("getHostedProfilePageRequest");
		$this->_xml->addChild("customerProfileId", $customer_profile_id);
		return $this->_sendRequest();
		}

	protected function _setPostString() {
		$this->_post_string = $this->_xml->asXML();
		}

	protected function _getPostUrl() {
		return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL);
		}

	protected function _handleResponse($response) {
		return new AuthorizeNetToken_Response($response);
		}

	private function _constructXml($request_type) {
		$string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>';
		$this->_xml = @new SimpleXMLElement($string);
		$merchant = $this->_xml->addChild('merchantAuthentication');
		$merchant->addChild('name',$this->_api_login);
		$merchant->addChild('transactionKey',$this->_transaction_key);
		}

	private function _addObject($destination, $object) {
		$array = (array)$object;
		foreach ($array as $key => $value) {
			if ($value && !is_object($value)) {
				if (is_array($value) && count($value)) {
					foreach ($value as $index => $item) {
						$items = $destination->addChild($key);
						$this->_addObject($items, $item);
						}
					} 
				else {
					$destination->addChild($key,$value);
					}
				} 
			elseif (is_object($value) && self::_notEmpty($value)) {
				$dest = $destination->addChild($key);
				$this->_addObject($dest, $value);
				}
			}
		}

	private static function _notEmpty($object) {
		$array = (array)$object;
		foreach ($array as $key => $value) {
			if ($value && !is_object($value)) {
				return true;
				} 
			elseif (is_object($value)) {
				if (self::_notEmpty($value)) {
					return true;
					}
				}
			}
		return false;
		}

	};

class AuthorizeNetToken_Response extends AuthorizeNetXMLResponse {
	public function GetToken() {
		return $this->_getElementContents("token");
		}
	};

 

You can use it like so:

 

define('AUTHORIZENET_API_LOGIN_ID', 'YOUR API LOGIN');
define('AUTHORIZENET_TRANSACTION_KEY','YOUR TRANSACTION KEY');
$API = new AuthorizeNetToken;
$response = $API->GetTokenResponse(18588389);
print "token = " . $response->GetToken();

 

 

 

Member
Posts: 2
Registered: ‎11-21-2014

Re: GetHostedProfilePage API call - How To Use It?

Are there any Classic ASP coders that can share code to retrieve the token? TIA