Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal Form API and BrainTree Exception Authentication
    primarykey
    data
    text
    <p>When I create a Drupal form with the API and construct the form as necessary, Braintree returns an authentication exception. When I take that same rendered HTML and output it on the page (skip the api), then it works. I can't figure out why!</p> <p>Below is the code that does not work.</p> <pre><code>function my_module_menu() { $items['user/payment/add'] = array( 'title' =&gt; t('Add Card'), 'type' =&gt; MENU_LOCAL_TASK, 'page callback' =&gt; 'drupal_get_form', 'page arguments' =&gt; array('my_module_add_form'), 'access arguments' =&gt; array('access content'), 'weight' =&gt; 2, ); } function my_module_add_form() { global $user; require_once 'sites/all/libraries/braintree/lib/Braintree.php'; Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('xxx'); Braintree_Configuration::publicKey('xxx'); Braintree_Configuration::privateKey('xxx'); $customer = Braintree_Customer::find($user-&gt;uid); $trData = Braintree_TransparentRedirect::updateCustomerData( array( 'redirectUrl' =&gt; 'http://www.xxx.com/user/payment', 'customerId' =&gt; $user-&gt;uid ) ); $form['#action'] = url(Braintree_TransparentRedirect::url(), array('external' =&gt; true)); $form['customer[first_name]'] = array( '#type' =&gt; 'textfield', '#title' =&gt; t('First Name'), ); $form['customer[last_name]'] = array( '#type' =&gt; 'textfield', '#title' =&gt; t('Last Name'), ); $form['tr_data'] = array( '#type' =&gt; 'hidden', '#value' =&gt; htmlentities($trData), ); $form['submit'] = array( '#type' =&gt; 'submit', '#value' =&gt; t('Save') ); return $form; } </code></pre> <p>if instead I take that exact HTML output and do this with a normal_menu_item and the same credentials as above...</p> <pre><code>function my_module_menu() { $items['user/payment/add'] = array( 'title' =&gt; t('Add Card'), 'type' =&gt; MENU_NORMAL_ITEM, 'page callback' =&gt; 'my_module_add_page', 'access arguments' =&gt; array('access content'), 'weight' =&gt; 2, ); } function my_module_add_page() { global $user; require_once 'sites/all/libraries/braintree/lib/Braintree.php'; Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('xxx'); Braintree_Configuration::publicKey('xxx'); Braintree_Configuration::privateKey('xxx'); $customer = Braintree_Customer::find($user-&gt;uid); $trData = Braintree_TransparentRedirect::updateCustomerData( array( 'redirectUrl' =&gt; 'http://www.xxx.com/user/payment', 'customerId' =&gt; $user-&gt;uid ) ); $output=" &lt;form accept-charset='UTF-8' id='tqcustom-billing' method='post' action='".Braintree_TransparentRedirect::url()."'&gt; &lt;div&gt; &lt;div class='form-item form-type-textfield form-item-customer-first-name'&gt; &lt;label for='edit-customer-first-name'&gt;First Name &lt;/label&gt; &lt;input type='text' class='form-text' maxlength='128' size='60' value='' name='customer[first_name]' id='edit-customer-first-name'&gt; &lt;/div&gt; &lt;div class='form-item form-type-textfield form-item-customer-last-name'&gt; &lt;label for='edit-customer-last-name'&gt;Last Name &lt;/label&gt; &lt;input type='text' class='form-text' maxlength='128' size='60' value='' name='customer[last_name]' id='edit-customer-last-name'&gt; &lt;/div&gt; &lt;input type='hidden' value='".$trData."' name='tr_data'&gt; &lt;input type='submit' class='form-submit' value='Save' name='op' id='edit-submit'&gt; &lt;/div&gt; &lt;/form&gt; "; return $output; } </code></pre> <p>it returns fine with a status code of 200. something about drupal_get_form or drupal_render kills the environment that braintree needs to authenticate the form post. What in the world could be causing this? The browser HTML output is 100% exactly the same both ways, but the first way won't authenticate.</p> <p>Please ask me for details and I'll supply them - desperate to figure this out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload