You are here

function stripe_admin_test_submit in Stripe 7

Submit callback for the stripe_admin_test form.

File

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

Code

function stripe_admin_test_submit($form, &$form_state) {
  if (stripe_load_library()) {
    try {
      $charge = \Stripe\Charge::create(array(
        // Amount in cents, again.
        "amount" => $form_state['values']['amount'],
        "currency" => "usd",
        "card" => $form_state['values']['stripe']['stripe_token'],
        "description" => t('Test Charge from :site', array(
          ':site' => variable_get('site_name', 'My Drupal Site'),
        )),
      ));
      drupal_set_message(t('Success! Card was successfully charged for the amount of :amount', array(
        ':amount' => $form_state['values']['amount'],
      )));
    } catch (Exception $e) {
      form_set_error('', $e
        ->getMessage());
      $form_state['rebuild'] = TRUE;
      return;
    }
  }
}