You are here

function stripe_admin_test in Stripe 7

Test/example implementation of the stripe form with the stripe_payment element.

1 string reference to 'stripe_admin_test'
stripe_menu in ./stripe.module
Implements hook_menu().

File

./stripe.test.inc, line 10
Stripe test form building callback and handlers.

Code

function stripe_admin_test($form, $form_state) {
  if (!stripe_get_key("secret") || !stripe_get_key("publishable")) {
    $form['error_markup'] = array(
      '#markup' => t("Please configure your Stripe API keys before attempting any test charges"),
    );
    return $form;
  }
  $form['stripe'] = array(
    '#type' => 'stripe_payment',
    '#address' => isset($form_state['values']['toggle_address']) ? (bool) $form_state['values']['toggle_address'] : FALSE,
    '#prefix' => '<div id="stripe-wrapper">',
    '#suffix' => '</div>',
    '#weight' => 10,
  );
  $form['toggle_address'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ask for address'),
    '#ajax' => array(
      'callback' => 'stripe_admin_test_ajax',
      'wrapper' => 'stripe-wrapper',
    ),
    '#default_value' => (bool) $form['stripe']['#address'],
  );
  $form['amount'] = array(
    '#type' => 'textfield',
    '#title' => t('Amount'),
    '#description' => '<em>cents</em>',
    '#default_value' => 99,
    '#size' => 6,
  );
  $form['card_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit Payment'),
    '#attributes' => array(
      'class' => array(
        'submit-button',
      ),
    ),
    '#weight' => 100,
  );
  return $form;
}