You are here

function uc_stripe_renew in Ubercart Stripe 7.2

Same name and namespace in other branches
  1. 6.2 uc_stripe.module \uc_stripe_renew()
  2. 6 uc_stripe.module \uc_stripe_renew()
  3. 7.3 uc_stripe.module \uc_stripe_renew()
  4. 7 uc_stripe.module \uc_stripe_renew()

Handle renewing a recurring fee, called by uc_recurring

Runs when the subscription interval is hit. So once a month or whatever. This just charges the stripe customer whatever amount ubercart wants. It does not use the Stripe subscription feature.

Parameters

$order:

$fee:

Return value

bool

1 string reference to 'uc_stripe_renew'
uc_stripe_recurring_info in ./uc_stripe.module
Implements hook_recurring_info() to integrate with uc_recurring

File

./uc_stripe.module, line 624
A stripe.js PCI-compliant payment gateway Forked from Bitcookie's work (thanks!) which was posted at http://bitcookie.com/blog/pci-compliant-ubercart-and-stripe-js from discussion in the uc_stripe issue queue, https://www.drupal.org/node/1467886

Code

function uc_stripe_renew($order, &$fee) {
  try {

    //Load the API
    _uc_stripe_prepare_api();

    //Get the customer ID
    $stripe_customer_id = _uc_stripe_get_customer_id($order->uid);
    if (empty($stripe_customer_id)) {
      throw new Exception('No stripe customer ID found');
    }

    //Create the charge
    $amount = $fee->fee_amount;
    $amount = $amount * 100;
    $charge = \Stripe\Charge::create(array(
      "amount" => $amount,
      "currency" => strtolower($order->currency),
      "customer" => $stripe_customer_id,
    ));
    uc_payment_enter($order->order_id, $order->payment_method, $order->order_total, $fee->uid, $charge, "Success");
    $formatted_amount = number_format($fee->fee_amount, 2);
    $message = t('Card renewal payment of @amount processed successfully.', array(
      '@amount' => $formatted_amount,
    ));
    uc_order_comment_save($fee->order_id, $order->uid, $message, 'order', 'completed', FALSE);
    return TRUE;
  } catch (Exception $e) {
    $result = array(
      'success' => FALSE,
      'comment' => $e
        ->getCode(),
      'message' => t("Renewal Failed for order !order: !message", array(
        "!order" => $order->order_id,
        "!message" => $e
          ->getMessage(),
      )),
    );
    uc_order_comment_save($order->order_id, $order->uid, $result['message'], 'admin');
    watchdog('uc_stripe', 'Renewal failed for order @order_id, code=@code, message: @message', array(
      '@order_id' => $order->order_id,
      '@code' => $result['comment'],
      '@message' => $result['message'],
    ));
    return FALSE;
  }
}