You are here

function commerce_payleap_cof_cardonfile_update_delete in Commerce Payleap 7

Callback for card on file update or delete.

See also

MerchantServices.svc/ManageCreditCardInfo (SCM API Guide)

1 string reference to 'commerce_payleap_cof_cardonfile_update_delete'
commerce_payleap_commerce_payment_method_info in ./commerce_payleap.module
Implements hook_commerce_payment_method_info().

File

./commerce_payleap.module, line 864
Implements PayLeap payment services for use in Drupal Commerce.

Code

function commerce_payleap_cof_cardonfile_update_delete($form, &$form_state, $payment_method, $card_data) {
  $info = array();
  $ids = explode('|', $card_data['remote_id']);

  // Update method expect the the full credit card number.
  // Delete can be triggered without it.
  $card_number = '';
  if ($form['#id'] == 'commerce-cardonfile-update-form') {
    $action = 'Update';
    if ($form_state['values']['credit_card']['number'] != $form['credit_card']['number']['#default_value']) {
      $card_number = $form_state['values']['credit_card']['number'];
    }
    else {
      form_set_error('credit_card][number', t('The credit card number you entered is invalid.'));
      return FALSE;
    }
  }
  else {
    $action = 'Delete';
  }
  $info += array(
    'CustomerKey' => $ids[0],
    'CardInfoKey' => $ids[1],
    'NameOnCard' => $card_data['card_name'],
    'CardNum' => $card_number,
    'ExpDate' => $card_data['card_exp_month'] . substr($card_data['card_exp_year'], 2, 2),
    'Street' => '',
    'Zip' => '',
  );

  // Fetch the response from the API server and let Card on File know if the
  // update was successful.
  $result = commerce_payleap_card_profile_request($payment_method, $info, $action);
  return (bool) $result['status'];
}