Hi. I've installed the module and have it set up and it is mostly working, except that Authorization and capture immediately does not seem to be.

When a purchase is made, the new customer is added on Stripe.com, along with their card details, and I can capture a payment manually.

However, I was expecting that the software would automatically capture the payment. Please can someone confirm that this is the case, and if so help me work out what I'm doing wrong?

CommentFileSizeAuthor
#5 capture.1.patch4.08 KBroblog
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

roblog created an issue. See original summary.

rfay’s picture

I haven't looked at it since posting the 8.x - It was certainly capturing (in test mode) at that time. Hopefully somebody who is using 8.x can comment.

roblog’s picture

I'd appreciate some input from anyone with more experience of the module. I'm trying to deduce if it is a configuration problem on my part, or the software is working as intended.

roblog’s picture

There is no call to \Stripe\Charge::create in 8.x-2.x.

The only reference to it is in uc_stripe.module, in relation to uc_recurring, but it has been commented out because it is not finished.

In fact there's a whole block of code missing from the D8 version that is in the D7 version:

//  Charge the stripe customer the amount in the order

  //--Handle transactions for $0

  // Stripe can't handle transactions < $0.50, but $0 is a common value
  // so we will just return a positive result when the amount is $0.
  if ($amount == 0) {
    $result = array(
      'success' => TRUE,
      'message' => t('Payment of $0 approved'),
      'uid' => $user->uid,
      'trans_id' => md5(uniqid(rand())),
    );
    uc_order_comment_save($order_id, $user->uid, $result['message'], 'admin');
    return $result;
  }


  // Charge the customer
  try {

    //Bail if there's no customer ID
    if (empty($stripe_customer_id)) {
      throw new Exception('No customer ID found');
    }

    // charge the Customer the amount in the order
    $charge = \Stripe\Charge::create(array(
        "amount" => $amount,
        "currency" => strtolower($order->currency),
        "customer" => $stripe_customer_id,
        "description" => t("Order #@order_id", array("@order_id" => $order_id)),
      )
    );

    $formatted_amount = $amount / 100;
    $formatted_amount = number_format($formatted_amount, 2);

    $result = array(
      'success' => TRUE,
      'message' => t('Payment of @amount processed successfully, Stripe transaction id @transaction_id.', array('@amount' => $formatted_amount, '@transaction_id' => $charge->id)),
      'comment' => t('Stripe transaction ID: @transaction_id', array('@transaction_id' => $charge->id)),
      'uid' => $user->uid,
    );

    uc_order_comment_save($order_id, $user->uid, $result['message'], 'admin');
    uc_order_comment_save($order_id, $user->uid, $result['message'], 'order', 'completed', FALSE);

    return $result;

  } catch (Exception $e) {
    $result = array(
      'success' => FALSE,
      'comment' => $e->getCode(),
      'message' => t("Stripe Charge Failed for order !order: !message", array(
        "!order" => $order_id,
        "!message" => $e->getMessage()
      )),
      'uid' => $user->uid,
      'order_id' => $order_id,
    );
    uc_order_comment_save($order_id, $user->uid, $result['message'], 'admin');
    watchdog('uc_stripe', 'Stripe charge failed for order @order, message: @message', array('@order' => $order_id, '@message' => $result['message']));

    return $result;
  }

  //  Default / Fallback procedure to fail if the above conditions aren't met

  $result = array(
    'success' => FALSE,
    'comment' => "Stripe Gateway Error",
    'message' => "Stripe Gateway Error",
    'uid' => $user->uid,
    'order_id' => $order_id,
  );

  uc_order_comment_save($order_id, $user->uid, $result['message'], 'admin');

  watchdog('uc_stripe', 'Stripe gateway error for order @order_id', array('order_id' => $order_id));

  return $result;
}
roblog’s picture

FileSize
4.08 KB

I've created a patch with the missing code, ported into D8

rfay’s picture

Category: Support request » Bug report
Status: Active » Needs review

  • rfay committed 6b93165 on 8.x-2.x authored by roblog
    Issue #2858522 by roblog: Authorize and capture not working
    
rfay’s picture

Status: Needs review » Fixed

Well nice work. I tested and you are in fact correct that without this patch it didn't charge and with it it did. Pretty impressive missing feature! Thanks for the good work on this, and I hope you can fix up other things. I don't have *any* site using this in 7.x or 8.x, and am not currently working with Drupal so pretty rusty. I had to move heaven and earth just to figure out how to install the stripe composer dependencies again.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.