function uc_stripe_charge in Ubercart Stripe 6
Same name and namespace in other branches
- 6.2 uc_stripe.module \uc_stripe_charge()
- 7.3 uc_stripe.module \uc_stripe_charge()
- 7 uc_stripe.module \uc_stripe_charge()
- 7.2 uc_stripe.module \uc_stripe_charge()
uc_credit callback for creating an actual credit card charge
1 string reference to 'uc_stripe_charge'
- uc_stripe_payment_gateway in ./
uc_stripe.module - Implements hook_payment_gateway().
File
- ./
uc_stripe.module, line 310 - A module used for Stripe. Developed by Victor Quinn for Health for Hackers (http://www.healthforhackers.com)
Code
function uc_stripe_charge($order_id, $amount, $data) {
global $user;
$order = uc_order_load($order_id);
// Pad the expiration date with a 0 for single digit months.
if (drupal_strlen($order->payment_details['cc_exp_month']) == 1) {
$order->payment_details['cc_exp_month'] = '0' . $order->payment_details['cc_exp_month'];
}
$context = array(
'revision' => 'formatted-original',
'type' => 'amount',
);
$options = array(
'sign' => FALSE,
'thou' => FALSE,
'dec' => FALSE,
'prec' => 2,
);
// Set up minimum fields.
$data = array(
'amount' => uc_price($amount, $context, $options),
'currency' => 'usd',
'card' => array(
'number' => $order->payment_details['cc_number'],
'exp_month' => $order->payment_details['cc_exp_month'],
'exp_year' => $order->payment_details['cc_exp_year'],
'name' => $order->billing_first_name . ' ' . $order->billing_last_name,
'address_line1' => $order->billing_street1,
'address_zip' => $order->billing_postal_code,
'address_state' => uc_get_zone_code($order->billing_zone),
),
'description' => "{$order->primary_email}; OrderID: {$order_id}",
);
// Load the Stripe API and set the API key.
if (!_uc_stripe_load_api()) {
$result = array(
'success' => FALSE,
'comment' => t('Stripe API not found.'),
'message' => t('Stripe API not found. Contact the site administrator.'),
'uid' => $user->uid,
'order_id' => $order_id,
);
return $result;
}
// CVV Number (if enabled).
if (variable_get('uc_credit_cvv_enabled', TRUE)) {
$data['card']['cvc'] = $order->payment_details['cc_cvv'];
}
// 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('Credit card payment processed successfully via Stripe.'),
'uid' => $user->uid,
'trans_id' => md5(uniqid(rand())),
);
}
else {
$result = _uc_stripe_post_transaction($order_id, $data);
}
return $result;
}