function commerce_cardonfile_rules_action_order_charge_card in Commerce Card on File 7.2
Rules action callback for commerce_cardonfile_order_charge_card
1 string reference to 'commerce_cardonfile_rules_action_order_charge_card'
File
- ./
commerce_cardonfile.rules.inc, line 216 - Provides Rules integration
Code
function commerce_cardonfile_rules_action_order_charge_card($order, $charge = NULL, $select_card_response = NULL, $card = NULL, $forced_instance_id = NULL) {
// This action needs either the card data provided or a response returned by
// the `Select card on file to charge` action.
if (empty($select_card_response) && empty($card)) {
// Return an error wrapped in a response if none of them are provided.
$response = array(
'code' => COMMERCE_COF_PROCESS_CODE_INSUFFICIENT_DATA,
'message' => 'No chargeable card on file is provided for the order @order_id.',
);
rules_invoke_all('commerce_cardonfile_charge_failed', NULL, $order, $charge, $response);
return array(
'charge_card_response' => $response,
);
}
// If provided, card data will be used regardless the response returned by
// the `Select card on file to charge` action.
if (empty($card)) {
// Card data is not provided, so let's use the response by the
// aforementioned action. Make sure it found a chargeable card.
if ($select_card_response['code'] == COMMERCE_COF_PROCESS_CODE_CARD_OK) {
$card = $select_card_response['card_chosen'];
}
else {
rules_invoke_all('commerce_cardonfile_charge_failed', NULL, $order, $charge, $select_card_response);
return array(
'charge_card_response' => $select_card_response,
);
}
}
$response = commerce_cardonfile_order_charge_card($order, $charge, $card, $forced_instance_id);
return array(
'charge_card_response' => $response,
);
}