You are here

function commerce_cardonfile_can_charge in Commerce Card on File 7.2

Returns TRUE if the card can be charged

1 call to commerce_cardonfile_can_charge()
commerce_cardonfile_order_can_charge_card in ./commerce_cardonfile.module
Returns TRUE if the card can be charged for the given order

File

./commerce_cardonfile.module, line 1063
Supports card on file functionality for credit card payment methods by associating card data reference IDs from payment gateways with user accounts.

Code

function commerce_cardonfile_can_charge($card) {

  // DENY if card is disabled
  if (empty($card->status)) {
    return FALSE;
  }

  // DENY if there is no payment method instance
  if (empty($card->instance_id)) {
    return FALSE;
  }

  // DENY if card is expired
  if (!commerce_cardonfile_validate_card_expiration($card)) {
    return FALSE;
  }

  // load payment method related to the card
  $payment_method = commerce_payment_method_instance_load($card->instance_id);

  // DENY if not a valid payment method
  if (empty($payment_method)) {
    return FALSE;
  }

  // ALLOW/DENY based on payment method capabilities
  $callback = commerce_cardonfile_payment_method_callback($payment_method, 'charge callback');
  return $callback ? TRUE : FALSE;
}