PaymentReceipt.php in Ubercart 8.4
File
payment/uc_payment/src/Entity/PaymentReceipt.php
View source
<?php
namespace Drupal\uc_payment\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\uc_payment\PaymentReceiptInterface;
class PaymentReceipt extends ContentEntityBase implements PaymentReceiptInterface {
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['receipt_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Payment receipt ID'))
->setDescription(t('The payment receipt ID.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['order_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Order ID'))
->setDescription(t('The order ID.'))
->setSetting('target_type', 'uc_order');
$fields['method'] = BaseFieldDefinition::create('string')
->setLabel(t('Payment method'))
->setDescription('The payment method plugin ID.');
$fields['amount'] = BaseFieldDefinition::create('decimal')
->setLabel(t('Amount'))
->setDescription('The payment amount in the store default currency.')
->setSetting('default_value', 0.0)
->setSetting('precision', 16)
->setSetting('scale', 5);
$fields['currency'] = BaseFieldDefinition::create('string')
->setLabel(t('Currency'))
->setDescription(t('The ISO currency code for the payment.'))
->setPropertyConstraints('value', [
'Length' => [
'max' => 3,
],
])
->setSetting('default_value', '')
->setSetting('max_length', 3);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User ID'))
->setDescription('The user that collected the payment.')
->setSetting('target_type', 'user')
->setSetting('default_value', 0);
$fields['data'] = BaseFieldDefinition::create('map')
->setLabel(t('Data'))
->setDescription('A serialized array of extra data.');
$fields['comment'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Comment'))
->setDescription('A comment made on the payment.')
->setSetting('default_value', '');
$fields['received'] = BaseFieldDefinition::create('created')
->setLabel(t('Received'))
->setDescription(t('The time that the payment was received.'));
return $fields;
}
public function getOrder() {
return $this
->get('order_id')->entity;
}
public function getOrderId() {
return $this
->get('order_id')->target_id;
}
public function getMethod() {
return \Drupal::service('plugin.manager.uc_payment.method')
->createInstance($this
->get('method')->value);
}
public function getMethodId() {
return $this
->get('method')->value;
}
public function getAmount() {
return $this
->get('amount')->value;
}
public function getUser() {
return $this
->get('uid')->entity;
}
public function getUserId() {
return $this
->get('uid')->target_id;
}
public function getComment() {
return $this
->get('comment')->value;
}
public function getReceived() {
return $this
->get('received')->value;
}
}