You are here

function uc_recurring_fee_save in UC Recurring Payments and Subscriptions 6

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

Parameters

$type: String specifying whether the fee is being added to a product as a feature or attached to a user account; use 'product' or 'user'.

$data: An array of data for the fee depending on $type.

Return value

No return for 'product' $type; the rfid of the saved fee for 'user' $type.

2 calls to uc_recurring_fee_save()
uc_recurring_feature_form_submit in ./uc_recurring.module
uc_recurring_recurring_fee in ./uc_recurring.module
Implementation of hook_recurring_fee(); default recurring fee handler.

File

./uc_recurring.module, line 705
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} (uid, fee_handler, next_charge, fee_amount, regular_interval, remaining_intervals, charged_intervals, order_id, data, created) VALUES (%d, '%s', %d, %f, '%s', %d, %d, %d, '%s', %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'], time());
        $data['rfid'] = db_last_insert_id('uc_recurring_users', 'rfid');
      }
      return $data['rfid'];
  }
}