class CommerceCardOnFile in Commerce Card on File 7.2
Entity class representing the commerce_cardonfile entity type.
Hierarchy
- class \Entity implements EntityInterface
- class \CommerceCardOnFile
Expanded class hierarchy of CommerceCardOnFile
1 string reference to 'CommerceCardOnFile'
- commerce_cardonfile_entity_info in ./
commerce_cardonfile.module - Implements of hook_entity_info().
File
- includes/
commerce_cardonfile.entity.inc, line 6
View source
class CommerceCardOnFile extends Entity {
/**
* The card id.
*
* @var integer
*/
public $card_id;
/**
* The uid of the card owner.
*
* @var integer
*/
public $uid;
/**
* The method_id of the payment method that stored the card.
*
* @var string
*/
public $payment_method;
/**
* The instance_id of the payment method that stored the card.
*
* @var string
*/
public $instance_id;
/**
* The id of the card at the payment gateway.
*
* @var string
*/
public $remote_id;
/**
* The card type.
*
* @var string
*/
public $card_type;
/**
* The name on the card.
*
* @var string
*/
public $card_name;
/**
* Truncated card number (last 4 digits).
*
* @var string
*/
public $card_number;
/**
* Expiration month.
*
* @var integer
*/
public $card_exp_month;
/**
* Expiration year.
*
* @var integer
*/
public $card_exp_year;
/**
* Whether this is the default card for this payment method instance..
*
* @var boolean
*/
public $instance_default = 1;
/**
* Card status: inactive (0), active (1), not deletable (2), declined (3).
*
* @var integer
*/
public $status = 1;
/**
* The Unix timestamp when the card was first stored.
*
* @var integer
*/
public $created;
/**
* The Unix timestamp when the card was last updated.
*
* @var integer
*/
public $changed;
public function __construct($values = array()) {
parent::__construct($values, 'commerce_cardonfile');
}
/**
* Overrides Entity::defaultLabel().
*/
protected function defaultLabel() {
$card_type = t('Card');
if (!empty($this->card_type)) {
$card_types = commerce_cardonfile_credit_card_types();
if (isset($card_types[$this->card_type])) {
$card_type = $card_types[$this->card_type];
}
}
$args = array(
'@card_type' => $card_type,
'@card_number' => $this->card_number,
);
return t('@card_type ending in @card_number', $args);
}
/**
* Overrides Entity::save().
*/
public function save() {
$this->changed = REQUEST_TIME;
// Set the created timestamp during initial save.
if (!$this->card_id) {
$this->created = REQUEST_TIME;
}
if ($this->card_id) {
$this->original = $original = entity_load_unchanged('commerce_cardonfile', $this->card_id);
// Reactivate a declined card after its expiration date has been modified.
if ($this->status == 3) {
$exp_month_changed = $this->original->card_exp_month != $this->card_exp_month;
$exp_year_changed = $this->original->card_exp_year != $this->card_exp_year;
if ($exp_month_changed || $exp_year_changed) {
$this->status = 1;
}
}
}
// Perform the save.
$save_result = parent::save();
if ($save_result !== FALSE) {
// We cannot consider operation as update when original card has uid 0.
// If we would, one user would end up with multiple default cards.
$is_update = isset($original) && $original->uid != 0;
$value_changed = $is_update && $this->instance_default != $original->instance_default;
// If the card is now instance_default, remove the flag from other cards.
if ($this->instance_default && (!$is_update || $value_changed)) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_cardonfile');
$query
->entityCondition('entity_id', $this->card_id, '<>');
$query
->propertyCondition('instance_id', $this->instance_id);
$query
->propertyCondition('uid', $this->uid);
$query
->propertyCondition('instance_default', TRUE);
$result = $query
->execute();
if (isset($result['commerce_cardonfile'])) {
$card_ids = array_keys($result['commerce_cardonfile']);
$other_cards = commerce_cardonfile_load_multiple($card_ids);
foreach ($other_cards as $other_card) {
$other_card->instance_default = 0;
commerce_cardonfile_save($other_card);
}
}
}
}
return $save_result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceCardOnFile:: |
public | property | Expiration month. | |
CommerceCardOnFile:: |
public | property | Expiration year. | |
CommerceCardOnFile:: |
public | property | The card id. | |
CommerceCardOnFile:: |
public | property | The name on the card. | |
CommerceCardOnFile:: |
public | property | Truncated card number (last 4 digits). | |
CommerceCardOnFile:: |
public | property | The card type. | |
CommerceCardOnFile:: |
public | property | The Unix timestamp when the card was last updated. | |
CommerceCardOnFile:: |
public | property | The Unix timestamp when the card was first stored. | |
CommerceCardOnFile:: |
public | property | Whether this is the default card for this payment method instance.. | |
CommerceCardOnFile:: |
public | property | The instance_id of the payment method that stored the card. | |
CommerceCardOnFile:: |
public | property | The method_id of the payment method that stored the card. | |
CommerceCardOnFile:: |
public | property | The id of the card at the payment gateway. | |
CommerceCardOnFile:: |
public | property | Card status: inactive (0), active (1), not deletable (2), declined (3). | |
CommerceCardOnFile:: |
public | property | The uid of the card owner. | |
CommerceCardOnFile:: |
protected | function |
Overrides Entity::defaultLabel(). Overrides Entity:: |
|
CommerceCardOnFile:: |
public | function |
Overrides Entity::save(). Overrides Entity:: |
|
CommerceCardOnFile:: |
public | function |
Overrides Entity:: |
|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Permanently deletes the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. |