/** * beforeSave * If self::$remote_sync is true, this accomplishes the following: * - Throws the data to save into a temporary variable * - Converts the braintree_customer_id key to customer_id * - Convers the braintree_credit_card_id key to payment_method_token * - Calls the parent (and sends the data to the API) * - Puts the temporary data back into the main data array, adding the 'id' (remote Transaction ID) and braintree_merchant_id keys * * @return bool */ public function beforeSave() { if ($this->remote_sync) { $temp_data = $this->data; if (!empty($this->data[$this->alias]['braintree_customer_id'])) { $this->data[$this->alias]['customer_id'] = $this->data[$this->alias]['braintree_customer_id']; unset($this->data[$this->alias]['braintree_customer_id']); } if (!empty($this->data[$this->alias]['braintree_credit_card_id'])) { $this->data[$this->alias]['payment_method_token'] = $this->data[$this->alias]['braintree_credit_card_id']; unset($this->data[$this->alias]['braintree_credit_card_id']); } } if (!parent::beforeSave()) { return false; } if ($this->remote_sync) { $this->data[$this->alias] = array_merge(array('id' => $this->id, 'braintree_merchant_id' => $this->data[$this->alias]['braintree_merchant_id']), $temp_data[$this->alias]); } if (!empty($this->id) && !empty($this->data[$this->alias]['braintree_customer_id'])) { $this->id = $this->data[$this->alias]['braintree_customer_id'] . '|' . $this->id; $this->data[$this->alias][$this->primaryKey] = $this->id; } return true; }
/** * beforeSave * If self::$remote_sync is true, this accomplishes the following: * - Throws the data to save into a temporary variable * - Converts the braintree_customer_id key to customer_id * - Calls the parent (and sends the data to the API) * - Puts the temporary data back into the main data array * - Unsets the CVV number * - Converts the credit card number to a masked number, and unsets the full number * * @return bool */ public function beforeSave() { if ($this->remote_sync) { $temp_data = $this->data; if (!empty($this->data[$this->alias]['braintree_customer_id'])) { $this->data[$this->alias]['customer_id'] = $this->data[$this->alias]['braintree_customer_id']; unset($this->data[$this->alias]['braintree_customer_id']); } } if (!parent::beforeSave()) { return false; } if ($this->remote_sync) { $this->data = $temp_data; } unset($this->data[$this->alias]['cvv']); if (!empty($this->data[$this->alias]['number'])) { $first_six = substr($this->data[$this->alias]['number'], 0, 6); $last_four = substr($this->data[$this->alias]['number'], -4); $strlen = strlen($this->data[$this->alias]['number']); $difference = $strlen - 10; $masked_number = $first_six; for ($count = 1; $count <= $difference; $count++) { $masked_number .= '*'; } $masked_number .= $last_four; $this->data[$this->alias]['masked_number'] = $masked_number; unset($this->data[$this->alias]['number']); } return true; }
/** * Construct * * @return void */ public function __construct() { return parent::__construct(); }