diff --git a/src/EventSubscriber/StripeWebformEventSubscriber.php b/src/EventSubscriber/StripeWebformEventSubscriber.php index 4f7aecf..1065810 100644 --- a/src/EventSubscriber/StripeWebformEventSubscriber.php +++ b/src/EventSubscriber/StripeWebformEventSubscriber.php @@ -14,6 +14,7 @@ use Psr\Log\LoggerInterface; use Stripe\Exception\ExceptionInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Drupal\Core\Serialization\Yaml; class StripeWebformEventSubscriber implements EventSubscriberInterface { @@ -140,6 +141,12 @@ class StripeWebformEventSubscriber implements EventSubscriberInterface { if (!empty($element['#stripe_billing_phone'])) { $event->setBillingPhone($element['#stripe_billing_phone']); } + if (!empty($element['#stripe_metadata'])) { + $metadata = Yaml::decode($element['#stripe_metadata']); + foreach ($metadata as $key => $item) { + $event->setMetadata($key, $item); + } + } } } diff --git a/src/Plugin/WebformElement/StripeWebformElementBase.php b/src/Plugin/WebformElement/StripeWebformElementBase.php index b55f11b..9a8d0fc 100644 --- a/src/Plugin/WebformElement/StripeWebformElementBase.php +++ b/src/Plugin/WebformElement/StripeWebformElementBase.php @@ -28,6 +28,7 @@ abstract class StripeWebformElementBase extends WebformElementBase { 'webform_stripe_subscriptions' => FALSE, 'webform_stripe_amount' => '', 'webform_stripe_amount_multiply' => TRUE, + 'stripe_metadata' => '', ]; /** @@ -253,6 +254,13 @@ abstract class StripeWebformElementBase extends WebformElementBase { '#title' => $this->t('Phone'), ]; + $form['stripe']['stripe_metadata'] = [ + '#type' => 'webform_codemirror', + '#mode' => 'yaml', + '#title' => $this->t('Metadata'), + '#description' => $this->t('Additional metadata in YAML format, each line a key: value element. You may use tokens - these should be enclosed in quote marks, e.g.
test: \'[webform_submission:values:test]\'', [':url' => 'https://stripe.com/docs/api#metadata']), + ]; + return $form; }