normalize($form);
// Authenticate request with OAuth 1.0
$test_server = new TestOAuthServer(new MockOAuthDataStore());
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$test_server->add_signature_method($hmac_method);
try {
$req = OAuthRequest::from_request(Null, Null, $parameters=$norm_params);
list($consumer, $token) = $test_server->verify_request($req);
} catch (OAuthException $e) {
header("HTTP/1.1 401 Unauthorized");
fwrite($fh, $e->getMessage() . "\n
\n");
fwrite($fh, print_r($req, TRUE));
die();
}
// We've established the request is really originating from FormSmarts.
// We can now start to do something useful...
// Note: Do NOT insert your own code before this line!
fwrite($fh, $form->{'api_version'});
fwrite($fh, $form->{'form_name'});
fwrite($fh, $form->{'fs_ref_num'});
fwrite($fh, $form->{'api_date'});
$fields = $form->{'fields'};
// iterate over all fields
foreach($fields as $field) {
fwrite($fh, $field->{'field_name'});
fwrite($fh, $field->{'field_value'});
if($field->{'field_datatype'} == 'attachment') {
fwrite($fh, $field->{'attachment_url'});
fwrite($fh, $field->{'attachment_filename'});
}
}
// print value ID of first field
fwrite($fh, $fields[2]->{'field_datatype'});
// print payment information, if applicable
if(array_key_exists('payment', $form)) {
$payment = $form->{'payment'};
fwrite($fh, $payment->{'currency'});
fwrite($fh, $payment->{'amount'});
fwrite($fh, $payment->{'processor_name'});
fwrite($fh, $payment->{'processor_txn_id'});
}
// print context info, if available.
if(array_key_exists('form_context', $form)) {
fwrite($fh, $form->{'form_context'}->{'formsmarts_ctx_label'});
fwrite($fh, $form->{'form_context'}->{'formsmarts_ctx_value'});
}
fclose($fh);
?>