You are here

function uc_recurring_fee_save in Ubercart 5

Saves a recurring fee either for a product or for a user.

4 calls to uc_recurring_fee_save()
uc_authorizenet_arb_create in payment/uc_authorizenet/uc_authorizenet.module
Sends an ARB Create request via the XML API.
uc_authorizenet_silent_post in payment/uc_authorizenet/uc_authorizenet.module
uc_recurring_byref_save in payment/uc_recurring/uc_recurring.module
Saves a reference transaction fee to the database.
uc_recurring_feature_form_submit in payment/uc_recurring/uc_recurring.module

File

payment/uc_recurring/uc_recurring.module, line 899
Allows you to add a recurring fee to a product/SKU to handle subscription type services.

Code

function uc_recurring_fee_save($type, $data) {
  switch ($type) {
    case 'product':

      // First attempt to update an existing row.
      db_query("UPDATE {uc_recurring_products} SET model = '%s', fee_amount = %f, initial_charge = '%s', regular_interval = '%s', number_intervals = %d WHERE pfid = %d", $data['model'], $data['fee_amount'], $data['initial_charge'], $data['regular_interval'], $data['number_intervals'], $data['pfid']);

      // Otherwise insert this feature as a new row.
      if (db_affected_rows() == 0) {
        db_query("INSERT INTO {uc_recurring_products} (pfid, model, fee_amount, initial_charge, regular_interval, number_intervals) VALUES (%d, '%s', %f, '%s', '%s', %d)", $data['pfid'], $data['model'], $data['fee_amount'], $data['initial_charge'], $data['regular_interval'], $data['number_intervals']);
      }
      break;
    case 'user':

      // First attempt to update an existing row.
      db_query("UPDATE {uc_recurring_users} SET uid = %d, fee_handler = '%s', next_charge = %d, fee_amount = %f, regular_interval = '%s', remaining_intervals = %d, charged_intervals = %d, order_id = %d, data = '%s' WHERE rfid = %d", $data['uid'], $data['fee_handler'], $data['next_charge'], $data['fee_amount'], $data['regular_interval'], $data['remaining_intervals'], $data['charged_intervals'], $data['order_id'], $data['data'], $data['rfid']);

      // Otherwise insert this feature as a new row.
      if (db_affected_rows() == 0) {
        db_query("INSERT INTO {uc_recurring_users} (rfid, uid, fee_handler, next_charge, fee_amount, regular_interval, remaining_intervals, charged_intervals, order_id, data, created) VALUES (%d, %d, '%s', %d, %f, '%s', %d, %d, %d, '%s', %d)", $data['rfid'], $data['uid'], $data['fee_handler'], $data['next_charge'], $data['fee_amount'], $data['regular_interval'], $data['remaining_intervals'], $data['charged_intervals'], $data['order_id'], $data['data'], time());
      }
      break;
  }
}