We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

Handle JSON on the response of a <data> call?

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
emyhre
Posts: 6
Joined: Wed Nov 25, 2015 2:36 pm

Handle JSON on the response of a <data> call?

Post by emyhre »

In lieu of a client-side remote server call (see my other post), I'm looking for alternatives to post sensitive payment card data to our card processor, without having it enter our processing environment. If we can format the post correctly, our card processor can accept the payment card details and return the token which we can then use in our systems.

One potential approach might be to use the <data> element to perform a POST to a remote server. However, according to the documentation, the <data> tag expects XML to be returned. I believe that our card processor returns JSON after a successful post.

Is there any way to process the JSON instead of an XML response, to retrieve the token for subsequent use with the VXML on our own servers?

Thanks

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

Re: Handle JSON on the response of a <data> call?

Post by support »

Hi,

The <data> tag always requires an xml response. If you're hosting your vxml files from a regular web server, you can interact with your api through any programming language supported by the server. For example, you could dynamically generate your vxml files through php, in which case you would have all the capabilities of the high level language as well as serving up the vxml files. This is the general approach for interacting with web services, but otherwise the <data> tag is the only real native vxml way to interact with remote services, which is limited to xml returned from the service.

For utilizing web services from a web server that is hosting your vxml scripts, the process generally follows the pattern of: gather your input from the caller; submit that to another script (either via <submit> or <sudbialog>, via GET or POST, such that the high level language can access the values; call your api through your high level language, and then move on with your call. Here's a basic example that uses the <submit> tag to submit POST data to another script, which calls a function (let's pretend the function is actually defined somewhere and implements a web service) and then processes the result and branches on the result of the response:

start.vxml

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
	<form id="enter_account_number">
		<field name="account_number" type="digits?length=2">
			<prompt>
				Please enter your 2 digit account number.
			</prompt>
			<filled>
				<submit next="account.php" namelist="account_number" method="post"/>
			</filled>
		</field>
	</form>
</vxml>
account.php

Code: Select all

<?php
header('Content-type: text/xml');
// pretend there's an include here for the script with the get_account_info() method

// get the account number submitted via POST
if (isset($_POST['account_number'])) {
	$account_data = get_account_info($_POST['account_number']);
	if ($account_data != FALSE) {
		$first_name = $account_data['first_name'];
		$last_name = $account_data['last_name'];
	}
}

echo("<?xml version=\"1.0\"?>\n");
?>

<vxml version="2.0">
<?php if (isset($first_name, $last_name)) { ?>
	<form id="valid_account">
		<block>
			<prompt>
				Hello, <?= $first_name ?> <?= $last_name ?>.
			</prompt>
			<exit/>
		</block>
	</form>
<?php } else { ?>
	<form id="invalid_account">
		<block>
			<prompt>
				Sorry, your account was not found.
			</prompt>
			<exit/>
		</block>
	</form>
<? } ?>
</vxml>
Alternatively, you could use the <data> tag to submit your data to a wrapper function that would take the submitted params, make the request to your api, gather the json response from your api, then format the response to xml and return it, in which case you could parse it directly from the <data> tag, however this approach also requires an intermediary web server.

Hopefully that helps, but please let us know if you have any additional questions.

Regards,
Plum Support

Post Reply