public function PaymentFactory::createPayment in Payment 8.2
Creates a payment for a field.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field_definition:
Return value
\Drupal\payment\Entity\PaymentInterface
Overrides PaymentFactoryInterface::createPayment
File
- modules/
payment_reference/ src/ PaymentFactory.php, line 44
Class
- PaymentFactory
- Provides a payment factory service.
Namespace
Drupal\payment_referenceCode
public function createPayment(FieldDefinitionInterface $field_definition) {
/** @var \Drupal\payment\Entity\PaymentInterface $payment */
$payment = $this->entityTypeManager
->getStorage('payment')
->create([
'bundle' => 'payment_reference',
]);
/** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
$payment_type = $payment
->getPaymentType();
$payment_type
->setEntityTypeId($field_definition
->getFieldStorageDefinition()
->getTargetEntityTypeId());
$payment_type
->setBundle($field_definition
->getTargetBundle());
$payment_type
->setFieldName($field_definition
->getName());
$payment
->setCurrencyCode($field_definition
->getSetting('currency_code'));
foreach ($field_definition
->getSetting('line_items_data') as $line_item_data) {
$line_item = $this->paymentLineItemManager
->createInstance($line_item_data['plugin_id'], $line_item_data['plugin_configuration']);
$payment
->setLineItem($line_item);
}
return $payment;
}