diff --git a/modules/payment_form/src/Entity/Payment/PaymentForm.php b/modules/payment_form/src/Entity/Payment/PaymentForm.php index b41d6dc..f7f9003 100644 --- a/modules/payment_form/src/Entity/Payment/PaymentForm.php +++ b/modules/payment_form/src/Entity/Payment/PaymentForm.php @@ -8,6 +8,7 @@ namespace Drupal\payment_form\Entity\Payment; use Drupal\Core\Entity\ContentEntityForm; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\TranslationInterface; @@ -118,4 +119,13 @@ class PaymentForm extends ContentEntityForm { return $actions; } + /** + * {@inheritdoc} + */ + protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) { + // Remove this override once https://drupal.org/node/2409143 has been fixed. + $this->getFormDisplay($form_state) + ->extractFormValues($entity, $form, $form_state); + } + } diff --git a/src/DatabaseQueue.php b/src/DatabaseQueue.php index 95477e1..190c9d2 100644 --- a/src/DatabaseQueue.php +++ b/src/DatabaseQueue.php @@ -156,7 +156,7 @@ class DatabaseQueue implements QueueInterface { */ public function claimPayment($payment_id) { $acquisition_code = $this->tryClaimPaymentOnce($payment_id); - // If a payment cannot be claimed at the first try, wait until the prevous + // If a payment cannot be claimed at the first try, wait until the previous // claim has expired and try to claim the payment one more time. if ($acquisition_code === FALSE) { sleep($this->getClaimExpirationPeriod()); @@ -235,10 +235,10 @@ class DatabaseQueue implements QueueInterface { } $query = $this->database->select('payment_queue', 'pq'); $query->addJoin('INNER', 'payment', 'p', 'p.id = pq.payment_id'); - $query->addJoin('INNER', 'payment_status', 'ps', 'p.last_payment_status_delta = ps.id'); + $query->addJoin('INNER', 'payment__payment_statuses', 'p_ps', 'p.id = p_ps.entity_id AND p.last_payment_status_delta = p_ps.delta'); $query->fields('pq', array('payment_id')) ->condition('pq.category_id', $category_id) - ->condition('ps.plugin_id', $allowed_payment_status_ids) + ->condition('p_ps.payment_statuses_plugin_id', $allowed_payment_status_ids) ->condition('p.owner', $owner_id) ->condition('pq.queue_id', $this->queueId); diff --git a/src/Element/PaymentStatusesDisplay.php b/src/Element/PaymentStatusesDisplay.php index f6fa198..d4fa413 100644 --- a/src/Element/PaymentStatusesDisplay.php +++ b/src/Element/PaymentStatusesDisplay.php @@ -78,6 +78,7 @@ class PaymentStatusesDisplay extends FormElement implements ContainerFactoryPlug if (!isset($element['#payment']) || !($element['#payment'] instanceof PaymentInterface)) { throw new \InvalidArgumentException('The payment does not implement \Drupal\payment\Entity\PaymentInterface.'); } + /** @var \Drupal\payment\Entity\PaymentInterface $payment */ $payment = $element['#payment']; $element['table'] = array( '#empty' => $this->t('There are no statuses.'), diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index 9c06970..cb55f6b 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -249,7 +249,7 @@ class Payment extends ContentEntityBase implements PaymentInterface { $payment_statuses[] = $field_item->getContainedPluginInstance(); } - return $payment_statuses; + return array_filter($payment_statuses); } /** diff --git a/src/Entity/Payment/PaymentListBuilder.php b/src/Entity/Payment/PaymentListBuilder.php index f631ec7..a5b9daa 100644 --- a/src/Entity/Payment/PaymentListBuilder.php +++ b/src/Entity/Payment/PaymentListBuilder.php @@ -89,7 +89,8 @@ class PaymentListBuilder extends EntityListBuilder { * {@inheritdoc} */ public function load() { - // @todo Add (table)sorting. + // @todo Add (table)sorting once https://drupal.org/node/2134761 has been + // fixed. $page = pager_find_page(); $start = static::PAYMENTS_PER_PAGE * ($page); $query = $this->storage->getQuery(); diff --git a/src/PaymentAwareInterface.php b/src/PaymentAwareInterface.php new file mode 100644 index 0000000..8cf0b9e --- /dev/null +++ b/src/PaymentAwareInterface.php @@ -0,0 +1,32 @@ +payment; + } + + /** + * {@inheritdoc} + */ + public function setPayment(PaymentInterface $payment) { + $this->payment = $payment; + + return $this; + } + +} diff --git a/src/Plugin/Field/FieldType/LineItemItem.php b/src/Plugin/Field/FieldType/LineItemItem.php index 7c6e701..de1643b 100644 --- a/src/Plugin/Field/FieldType/LineItemItem.php +++ b/src/Plugin/Field/FieldType/LineItemItem.php @@ -18,7 +18,7 @@ use Drupal\payment\Payment; * list_class = "\Drupal\payment\Plugin\Field\FieldType\PluginBagItemList" * ) */ -class LineItemItem extends PluginBagItemBase { +class LineItemItem extends PaymentAwarePluginBagItemBase { /** * {@inheritdoc} @@ -28,4 +28,15 @@ class LineItemItem extends PluginBagItemBase { return Payment::lineItemManager(); } + /** + * {@inheritdoc} + */ + public function onChange($property_name, $notify = TRUE) { + if ($this->getParent() instanceof PaymentInterface) { + /** @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface $plugin_instance */ + $plugin_instance = $this->getContainedPluginInstance(); + $plugin_instance->setPayment($this->getParent()); + } + } + } diff --git a/src/Plugin/Field/FieldType/PaymentAwarePluginBagItemBase.php b/src/Plugin/Field/FieldType/PaymentAwarePluginBagItemBase.php new file mode 100644 index 0000000..a057b18 --- /dev/null +++ b/src/Plugin/Field/FieldType/PaymentAwarePluginBagItemBase.php @@ -0,0 +1,34 @@ +getParent()) { + if ($data instanceof PaymentInterface) { + /** @var \Drupal\payment\PaymentAwareInterface $plugin_instance */ + $plugin_instance = $this->getContainedPluginInstance(); + $plugin_instance->setPayment($data); + break; + } + } + } + } + +} diff --git a/src/Plugin/Field/FieldType/PaymentMethodItem.php b/src/Plugin/Field/FieldType/PaymentMethodItem.php index e31447e..eeaa0d3 100644 --- a/src/Plugin/Field/FieldType/PaymentMethodItem.php +++ b/src/Plugin/Field/FieldType/PaymentMethodItem.php @@ -7,6 +7,7 @@ namespace Drupal\payment\Plugin\Field\FieldType; +use Drupal\payment\Entity\PaymentInterface; use Drupal\payment\Payment; /** @@ -18,7 +19,7 @@ use Drupal\payment\Payment; * list_class = "\Drupal\payment\Plugin\Field\FieldType\PluginBagItemList" * ) */ -class PaymentMethodItem extends PluginBagItemBase { +class PaymentMethodItem extends PaymentAwarePluginBagItemBase { /** * {@inheritdoc} diff --git a/src/Plugin/Field/FieldType/PaymentStatusItem.php b/src/Plugin/Field/FieldType/PaymentStatusItem.php index a92f1c1..f321c2e 100644 --- a/src/Plugin/Field/FieldType/PaymentStatusItem.php +++ b/src/Plugin/Field/FieldType/PaymentStatusItem.php @@ -18,7 +18,7 @@ use Drupal\payment\Payment; * list_class = "\Drupal\payment\Plugin\Field\FieldType\PluginBagItemList" * ) */ -class PaymentStatusItem extends PluginBagItemBase { +class PaymentStatusItem extends PaymentAwarePluginBagItemBase { /** * {@inheritdoc} diff --git a/src/Plugin/Field/FieldType/PaymentTypeItem.php b/src/Plugin/Field/FieldType/PaymentTypeItem.php index 32054b9..10069ea 100644 --- a/src/Plugin/Field/FieldType/PaymentTypeItem.php +++ b/src/Plugin/Field/FieldType/PaymentTypeItem.php @@ -18,7 +18,7 @@ use Drupal\payment\Payment; * list_class = "\Drupal\payment\Plugin\Field\FieldType\PluginBagItemList" * ) */ -class PaymentTypeItem extends PluginBagItemBase { +class PaymentTypeItem extends PaymentAwarePluginBagItemBase { /** * {@inheritdoc} diff --git a/src/Plugin/Field/FieldType/PluginBagItemBase.php b/src/Plugin/Field/FieldType/PluginBagItemBase.php index e3040e5..e3132fc 100644 --- a/src/Plugin/Field/FieldType/PluginBagItemBase.php +++ b/src/Plugin/Field/FieldType/PluginBagItemBase.php @@ -170,7 +170,7 @@ abstract class PluginBagItemBase extends FieldItemBase implements PluginBagItemI public function __clone() { $plugin_instance = $this->get('plugin_instance')->getValue(); if (is_object($plugin_instance)) { - $this->get('plugin_instance')->setValue(clone $plugin_instance); + $this->get('plugin_instance')->setValue(clone $plugin_instance, FALSE); } } diff --git a/src/Plugin/Payment/LineItem/PaymentLineItemBase.php b/src/Plugin/Payment/LineItem/PaymentLineItemBase.php index 452b0cd..9cedd2c 100644 --- a/src/Plugin/Payment/LineItem/PaymentLineItemBase.php +++ b/src/Plugin/Payment/LineItem/PaymentLineItemBase.php @@ -10,7 +10,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\currency\Math\MathInterface; -use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -21,6 +21,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ abstract class PaymentLineItemBase extends PluginBase implements PaymentLineItemInterface, ContainerFactoryPluginInterface { + use PaymentAwareTrait; + /** * The math service. * @@ -29,13 +31,6 @@ abstract class PaymentLineItemBase extends PluginBase implements PaymentLineItem protected $math; /** - * The payment this line item is for. - * - * @var \Drupal\payment\Entity\PaymentInterface - */ - protected $payment; - - /** * Constructs a new class instance. * * @param array $configuration @@ -94,22 +89,6 @@ abstract class PaymentLineItemBase extends PluginBase implements PaymentLineItem /** * {@inheritdoc} */ - public function getPayment() { - return $this->payment; - } - - /** - * {@inheritdoc} - */ - public function setPayment(PaymentInterface $payment) { - $this->payment = $payment; - - return $this; - } - - /** - * {@inheritdoc} - */ function getTotalAmount() { return $this->math->multiply($this->getAmount(), $this->getQuantity()); } diff --git a/src/Plugin/Payment/LineItem/PaymentLineItemInterface.php b/src/Plugin/Payment/LineItem/PaymentLineItemInterface.php index 6feebbf..af8f135 100644 --- a/src/Plugin/Payment/LineItem/PaymentLineItemInterface.php +++ b/src/Plugin/Payment/LineItem/PaymentLineItemInterface.php @@ -10,27 +10,12 @@ use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareInterface; /** * A payment line item. */ -interface PaymentLineItemInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface { - - /** - * Sets the payment the line item belongs to. - * - * @param \Drupal\payment\Entity\PaymentInterface $payment - * - * @return static - */ - public function setPayment(PaymentInterface $payment); - - /** - * Gets the payment this line item belongs to. - * - * @return \Drupal\payment\Entity\PaymentInterface - */ - public function getPayment(); +interface PaymentLineItemInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface, PaymentAwareInterface { /** * Gets the amount. diff --git a/src/Plugin/Payment/Method/PaymentMethodBase.php b/src/Plugin/Payment/Method/PaymentMethodBase.php index ae4c0f2..6663f41 100644 --- a/src/Plugin/Payment/Method/PaymentMethodBase.php +++ b/src/Plugin/Payment/Method/PaymentMethodBase.php @@ -12,12 +12,12 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Utility\Token; -use Drupal\payment\Entity\PaymentInterface; use Drupal\payment\Event\PaymentEvents; use Drupal\payment\Event\PaymentExecuteAccess; use Drupal\payment\Event\PaymentPreCapture; use Drupal\payment\Event\PaymentPreExecute; use Drupal\payment\Event\PaymentPreRefund; +use Drupal\payment\PaymentAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -32,6 +32,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; */ abstract class PaymentMethodBase extends PluginBase implements ContainerFactoryPluginInterface, PaymentMethodInterface, PaymentMethodCapturePaymentInterface, PaymentMethodRefundPaymentInterface { + use PaymentAwareTrait; + /** * The event dispatcher. * @@ -47,13 +49,6 @@ abstract class PaymentMethodBase extends PluginBase implements ContainerFactoryP protected $moduleHandler; /** - * The payment this payment method is for. - * - * @var \Drupal\payment\Entity\PaymentInterface - */ - protected $payment; - - /** * The token API. * * @var \Drupal\Core\Utility\Token @@ -140,22 +135,6 @@ abstract class PaymentMethodBase extends PluginBase implements ContainerFactoryP /** * {@inheritdoc} */ - public function getPayment() { - return $this->payment; - } - - /** - * {@inheritdoc} - */ - public function setPayment(PaymentInterface $payment) { - $this->payment = $payment; - - return $this; - } - - /** - * {@inheritdoc} - */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $message_text = $this->token->replace($this->getMessageText(), array( 'payment' => $this->getPayment(), diff --git a/src/Plugin/Payment/Method/PaymentMethodInterface.php b/src/Plugin/Payment/Method/PaymentMethodInterface.php index 3e45743..fe6395f 100644 --- a/src/Plugin/Payment/Method/PaymentMethodInterface.php +++ b/src/Plugin/Payment/Method/PaymentMethodInterface.php @@ -11,6 +11,7 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Session\AccountInterface; use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareInterface; /** * Defines a payment method. @@ -26,7 +27,7 @@ use Drupal\payment\Entity\PaymentInterface; * - \Drupal\payment\Plugin\Payment\Method\PaymentMethodCapturePaymentInterface: * This interface lets payment methods capture already authorized payments. */ -interface PaymentMethodInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface { +interface PaymentMethodInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface, PaymentAwareInterface { /** * Checks if the payment can be executed. @@ -60,22 +61,6 @@ interface PaymentMethodInterface extends PluginInspectionInterface, Configurable public function isPaymentExecutionInterruptive(); /** - * Gets the payment this payment method is for. - * - * @return \Drupal\payment\Entity\PaymentInterface - */ - public function getPayment(); - - /** - * Gets the payment this payment method is for. - * - * @param \Drupal\payment\Entity\PaymentInterface $payment - * - * @return $this - */ - public function setPayment(PaymentInterface $payment); - - /** * Gets the plugin label. * * @return string diff --git a/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorBase.php b/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorBase.php index 72c9a17..493a427 100644 --- a/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorBase.php +++ b/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Session\AccountInterface; use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareTrait; use Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface; use Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -23,6 +24,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ abstract class PaymentMethodSelectorBase extends PluginBase implements ContainerFactoryPluginInterface, PaymentMethodSelectorInterface { + use PaymentAwareTrait; + /** * The current user. * @@ -31,13 +34,6 @@ abstract class PaymentMethodSelectorBase extends PluginBase implements Container protected $currentUser; /** - * The payment a payment method is selected for. - * - * @var \Drupal\payment\Entity\PaymentInterface - */ - protected $payment; - - /** * The payment method manager. * * @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface @@ -172,13 +168,6 @@ abstract class PaymentMethodSelectorBase extends PluginBase implements Container /** * {@inheritdoc} */ - public function getPayment() { - return $this->payment; - } - - /** - * {@inheritdoc} - */ public function setPayment(PaymentInterface $payment) { $this->payment = $payment; if ($payment->getPaymentMethod()) { diff --git a/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorInterface.php b/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorInterface.php index 7025f61..a61b0fc 100644 --- a/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorInterface.php +++ b/src/Plugin/Payment/MethodSelector/PaymentMethodSelectorInterface.php @@ -9,13 +9,13 @@ namespace Drupal\payment\Plugin\Payment\MethodSelector; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\PluginFormInterface; -use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareInterface; use Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface; /** * Provides a plugin to select and configure a payment method for a payment. */ -interface PaymentMethodSelectorInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface { +interface PaymentMethodSelectorInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface, PaymentAwareInterface { /** * Sets whether a payment method must be selected. @@ -59,22 +59,6 @@ interface PaymentMethodSelectorInterface extends PluginInspectionInterface, Conf public function getAllowedPaymentMethods(); /** - * Gets the payment this payment method is for. - * - * @return \Drupal\payment\Entity\PaymentInterface - */ - public function getPayment(); - - /** - * Gets the payment this payment method is for. - * - * @param \Drupal\payment\Entity\PaymentInterface $payment - * - * @return $this - */ - public function setPayment(PaymentInterface $payment); - - /** * Gets the selected payment method. * * @return \Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface diff --git a/src/Plugin/Payment/Status/PaymentStatusBase.php b/src/Plugin/Payment/Status/PaymentStatusBase.php index 5578e98..17dd55c 100644 --- a/src/Plugin/Payment/Status/PaymentStatusBase.php +++ b/src/Plugin/Payment/Status/PaymentStatusBase.php @@ -9,6 +9,7 @@ namespace Drupal\payment\Plugin\Payment\Status; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -19,12 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ abstract class PaymentStatusBase extends PluginBase implements ContainerFactoryPluginInterface, PaymentStatusInterface { - /** - * The payment this payment status is for. - * - * @var \Drupal\payment\Entity\PaymentInterface - */ - protected $payment; + use PaymentAwareTrait; /** * The payment status plugin manager. @@ -107,22 +103,6 @@ abstract class PaymentStatusBase extends PluginBase implements ContainerFactoryP /** * {@inheritdoc} */ - public function getPayment() { - return $this->payment; - } - - /** - * {@inheritdoc} - */ - public function setPayment(PaymentInterface $payment) { - $this->payment = $payment; - - return $this; - } - - /** - * {@inheritdoc} - */ function getAncestors(){ return $this->paymentStatusManager->getAncestors($this->getPluginId()); } diff --git a/src/Plugin/Payment/Status/PaymentStatusInterface.php b/src/Plugin/Payment/Status/PaymentStatusInterface.php index 7c2f28e..fa214d8 100644 --- a/src/Plugin/Payment/Status/PaymentStatusInterface.php +++ b/src/Plugin/Payment/Status/PaymentStatusInterface.php @@ -8,12 +8,12 @@ namespace Drupal\payment\plugin\payment\status; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareInterface; /** * A payment status plugin. */ -interface PaymentStatusInterface extends PluginInspectionInterface, ConfigurablePluginInterface { +interface PaymentStatusInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PaymentAwareInterface { /** * Sets the created date and time. @@ -34,22 +34,6 @@ interface PaymentStatusInterface extends PluginInspectionInterface, Configurable public function getCreated(); /** - * Sets the payment the status belongs to. - * - * @param \Drupal\payment\Entity\PaymentInterface $payment - * - * @return static - */ - public function setPayment(PaymentInterface $payment); - - /** - * Gets the payment this status belongs to. - * - * @return \Drupal\payment\Entity\PaymentInterface - */ - public function getPayment(); - - /** * Gets this payment status's ancestors. * * @return array diff --git a/src/Plugin/Payment/Type/PaymentTypeBase.php b/src/Plugin/Payment/Type/PaymentTypeBase.php index 0846f8e..245691c 100644 --- a/src/Plugin/Payment/Type/PaymentTypeBase.php +++ b/src/Plugin/Payment/Type/PaymentTypeBase.php @@ -8,9 +8,9 @@ namespace Drupal\payment\Plugin\Payment\Type; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\payment\Entity\PaymentInterface; use Drupal\payment\Event\PaymentEvents; use Drupal\payment\Event\PaymentTypePreResumeContext; +use Drupal\payment\PaymentAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -19,6 +19,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; */ abstract class PaymentTypeBase extends PluginBase implements ContainerFactoryPluginInterface, PaymentTypeInterface { + use PaymentAwareTrait; + /** * The event dispatcher. * @@ -27,13 +29,6 @@ abstract class PaymentTypeBase extends PluginBase implements ContainerFactoryPlu protected $eventDispatcher; /** - * The payment this type is of. - * - * @var \Drupal\payment\Entity\PaymentInterface - */ - protected $payment; - - /** * Constructs a new class instance. * * @param array $configuration @@ -89,22 +84,6 @@ abstract class PaymentTypeBase extends PluginBase implements ContainerFactoryPlu /** * {@inheritdoc} */ - public function getPayment() { - return $this->payment; - } - - /** - * {@inheritdoc} - */ - public function setPayment(PaymentInterface $payment) { - $this->payment = $payment; - - return $this; - } - - /** - * {@inheritdoc} - */ function resumeContext() { $event = new PaymentTypePreResumeContext($this->getPayment()); $this->eventDispatcher->dispatch(PaymentEvents::PAYMENT_TYPE_PRE_RESUME_CONTEXT, $event); diff --git a/src/Plugin/Payment/Type/PaymentTypeInterface.php b/src/Plugin/Payment/Type/PaymentTypeInterface.php index 0aff7d7..5febcb0 100644 --- a/src/Plugin/Payment/Type/PaymentTypeInterface.php +++ b/src/Plugin/Payment/Type/PaymentTypeInterface.php @@ -9,28 +9,12 @@ namespace Drupal\payment\Plugin\Payment\Type; use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\payment\Entity\PaymentInterface; +use Drupal\payment\PaymentAwareInterface; /** * A payment type plugin. */ -interface PaymentTypeInterface extends PluginInspectionInterface, ConfigurablePluginInterface { - - /** - * Sets the ID of the payment this plugin is of. - * - * @param \Drupal\payment\Entity\PaymentInterface $payment - * - * @return static - */ - public function setPayment(PaymentInterface $payment); - - /** - * Gets the ID of the payment this plugin is of. - * - * @return \Drupal\payment\Entity\PaymentInterface - */ - public function getPayment(); +interface PaymentTypeInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PaymentAwareInterface { /** * Returns the description of the payment this plugin is of. diff --git a/src/QueueInterface.php b/src/QueueInterface.php index 8064a81..e1f6c50 100644 --- a/src/QueueInterface.php +++ b/src/QueueInterface.php @@ -49,7 +49,7 @@ interface QueueInterface { * * @param integer $payment_id * @param string $acquisition_code - * The code that was received from self::reserve(). + * The code that was received from self::claimPayment(). * * @return bool * Whether the acquisition was successful. diff --git a/src/Tests/Entity/Payment/PaymentStorageWebTest.php b/src/Tests/Entity/Payment/PaymentStorageWebTest.php index 3419e43..1165f09 100644 --- a/src/Tests/Entity/Payment/PaymentStorageWebTest.php +++ b/src/Tests/Entity/Payment/PaymentStorageWebTest.php @@ -9,6 +9,8 @@ namespace Drupal\payment\Tests\Entity\Payment; use Drupal\payment\Entity\PaymentInterface; use Drupal\payment\Payment; +use Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface; +use Drupal\payment\plugin\payment\status\PaymentStatusInterface; use Drupal\payment\Plugin\Payment\Type\PaymentTypeInterface; use Drupal\payment\Tests\Generate; use Drupal\simpletest\WebTestBase; @@ -69,7 +71,13 @@ class PaymentStorageWebTest extends WebTestBase { /** @var \Drupal\payment\Entity\PaymentInterface $payment_loaded */ $payment_loaded = entity_load_unchanged('payment', $payment->id()); $this->assertEqual(count($payment_loaded->getLineItems()), count($payment->getLineItems())); + foreach ($payment_loaded->getLineItems() as $line_item) { + $this->assertTrue($line_item instanceof PaymentLineItemInterface); + } $this->assertEqual(count($payment_loaded->getPaymentStatuses()), count($payment->getPaymentStatuses())); + foreach ($payment_loaded->getPaymentStatuses() as $status) { + $this->assertTrue($status instanceof PaymentStatusInterface); + } $this->assertEqual($payment_loaded->getPaymentMethod()->getConfiguration(), $payment->getPaymentMethod()->getConfiguration()); $this->assertEqual($payment_loaded->getPaymentType()->getConfiguration(), $payment->getPaymentType()->getConfiguration()); }